Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Shoot bullets out of the loop  (Read 1587 times)
0 Members and 1 Guest are viewing this topic.
Offline elamre
« Posted 2012-07-06 22:57:50 »

Hello all, im finishing up some shooter game. But i have got a slight problem with my shooting mechanism. the first 5 degrees go perfectly fine, but after that it goes off.
This is the method im using to shoot bullets:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
   public void shootBullets() {
      float lengDir = 1;
      switch (Ships.currentship) {
      case Ships.NORMALSHIP:
         lengDir = 15;
         break;
      }
      float tempX = Player.getPlayer().getShip().getImageOriginX();
      float tempY = -Player.getPlayer().getShip().getImageOriginY();
      tempX += (Math.sin(java.lang.Math.toRadians(this.dir)) * lengDir);
      tempY += (Math.cos(java.lang.Math.toRadians(this.dir)) * lengDir);
      System.out.println(tempX + " , " + tempY);
      Player.getPlayer().getBullets().add(new NormalBullet(x + tempX, y + tempY, dir));
   }


lengdir is the length to the loop from the origin of the image. Im using 15 in this code.
Im using slick, so the point (0,0) is at the left top of an image.
getImageOriginX:
1  
2  
3  
   public float getImageOriginX() {
      return image.getWidth() / 2;
   }


The weapon is an object which is attached to the player. meaning that the x of the weapon is the x of the player (its basically a suit), same goes for the direction and the y position

output, starting facing north, and turning 90 degrees before shooting:
1  
2  
3  
4  
15.0 , -1.0
29.984562 , -16.680374
14.424611 , -30.98896
0.007386695 , -15.529313

My projects:
Tower Defence!]http://www.java-gaming.org/topics/iconified/25690/view.html]Tower Defence! [lll.......] 30%!
Lightsnakerider! [llllll....] 60%!
Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2012-07-07 09:12:46 »

Your code barely makes any sense but first thing I noticed is that you have to use cosine for X and sine for Y Grin

Also, please drop the "java.lang." part, it's hurting my eyes Grin

Offline elamre
« Reply #2 - Posted 2012-07-07 09:13:52 »

At least my code made more sense then you not making sense.
But i shall thank you for this stupid mistake i made. cant believe i did that! :|

My projects:
Tower Defence!]http://www.java-gaming.org/topics/iconified/25690/view.html]Tower Defence! [lll.......] 30%!
Lightsnakerider! [llllll....] 60%!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Phased
« Reply #3 - Posted 2012-07-07 10:37:59 »

At least my code made more sense then you not making sense.

if your referring to the java.lang part, his trying to say, import it so you can just do Math.cosin();

his post made a lot of sense.
Offline ReBirth
« Reply #4 - Posted 2012-07-07 10:56:57 »

Except you have a custom class named Math too.

Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #5 - Posted 2012-07-12 05:34:37 »

zing!

- Jonas
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (38 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!