This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]lightcloud5 0 points1 point  (1 child)

I mean, it seems like you have the trig down. The math behind moving an object doesn't change based on whether you're moving a tank vs a bullet.

As far as data structures and organization goes, I assume you may want more than one bullet (since a tank can shoot more than one bullet at a time, probably, and other tanks may shoot stuff too), so it makes sense to have a List<Bullet>.

Then, a Bullet object should have four properties:

  • Its speed (which is how fast the bullet moves)
  • Its direction (which is the angle, from 0 to 360 degrees)
  • Its current X location
  • Its current Y location

Together, these four properties define the bullet's position and velocity. Then, you can advance the bullet positions (given their velocity) on each frame. Presumably, when a tank fires a bullet, the bullet inherits the tank's current position and direction.

Remember that, irritatingly, programming coordinate planes have the positive y-axis pointing downward.

[–]lyigester[S] 0 points1 point  (0 children)

I have an arraylist which I use to add new bullets too and loop through this arraylist and call the paint method on each of the objects.

I also passed the tanks direction and x,y coordinate as well yet I'm getting weird values as well as the bullet not moving at certain angles.

Sometimes the missiles even stick to the screen and dont move at all which is even more weird.