# Thread: 2d shooter

1. ## 2d shooter

I am trying to make a 2d shooter. The idea is that it will be a sqaire map with ships that can fly about in any direction. What I can't work out is how to make them go in lots of different directons.

Code:
```//up
ship.y-1
//up left
ship.y-1 ship.x-1
//left
ship.x-1
...etc```
doing this I can see how it would be possible to make ships go in 8 directions and I can see how it would be possible to make ships go in 16 directions but what would be a good way of making ships able to travel in all 360 degrees?

2. Use a control that moves the ship forwards/backwards by pressing UP/DOWN, and change the angle it is looking at by pressing LEFT/RIGHT.
Use trigonometric functions (cos/sin) for the math part.

3. ## I think this is what you need... =)

You can try this:

// Where angle is the ship's rotation angle (0° - 360°)
ship.x += sin(angle) * ship.speed;
ship.y += cos(angle) * ship.speed;

I think that is what you want. Try that and let me know if it worked =).

4. Remember to use floating-points instead of integers as coordinates for your objects. Temporarily convert the coordinates to integers when you draw them.

5. thanx for replies

This is exacly the info I needed and seams to do the trick thanx

Popular pages Recent additions