Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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 1433 times)
0 Members and 1 Guest are viewing this topic.
Offline elamre

JGO Coder


Medals: 17
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: 340
Projects: 2
Exp: 5 years


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: 17
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!
Legends of Yore - The Casual Retro Roguelike
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: 24
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.

 

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

The first screenshot will be displayed as a thumbnail.

Riven (20 views)
2014-07-30 07:09:19

Riven (13 views)
2014-07-30 07:08:52

Dwinin (12 views)
2014-07-29 23:59:34

E.R. Fleming (31 views)
2014-07-29 16:07:13

E.R. Fleming (12 views)
2014-07-29 16:06:25

pw (42 views)
2014-07-24 14:59:36

Riven (42 views)
2014-07-24 10:16:32

Riven (28 views)
2014-07-24 10:07:15

Riven (29 views)
2014-07-24 09:56:16

ctomni231 (60 views)
2014-07-18 19:55:21
HotSpot Options
by dleskov
2014-07-08 16:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 13:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 13:47:22

How do I start Java Game Development?
by ra4king
2014-05-18 00:13:37

HotSpot Options
by Roquen
2014-05-15 22:59:54

HotSpot Options
by Roquen
2014-05-07 04:03:10

Escape Analysis
by Roquen
2014-04-30 11:16:43

Experimental Toys
by Roquen
2014-04-29 02:24:22
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!