Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
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 918 times)
0 Members and 1 Guest are viewing this topic.
Offline elamre

JGO Coder


Medals: 15
Projects: 1


hitar!


« Posted 2012-07-07 00: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: 264
Projects: 2


I'm the King!


« Reply #1 - Posted 2012-07-07 11: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

JGO Coder


Medals: 15
Projects: 1


hitar!


« Reply #2 - Posted 2012-07-07 11: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!
Try the Free Demo of Titan Attacks
Offline Phased
« Reply #3 - Posted 2012-07-07 12: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 12:56:57 »

Except you have a custom class named Math too.

Offline Ultroman

JGO Knight


Medals: 23
Projects: 1


Snappin' at snizzes since '83


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

zing!

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

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (34 views)
2013-05-17 21:29:12

alaslipknot (42 views)
2013-05-16 21:24:48

gouessej (72 views)
2013-05-16 00:53:38

gouessej (71 views)
2013-05-16 00:17:58

theagentd (79 views)
2013-05-15 15:01:13

theagentd (74 views)
2013-05-15 15:00:54

StreetDoggy (116 views)
2013-05-14 15:56:26

kutucuk (139 views)
2013-05-12 17:10:36

kutucuk (140 views)
2013-05-12 15:36:09

UnluckyDevil (148 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.114 seconds with 21 queries.