# 2d shooter

• 04-22-2003
Enf
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?
• 04-22-2003
Magos
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.
• 04-22-2003
SyntaxBubble
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 =).
• 04-22-2003
Sang-drax
Remember to use floating-points instead of integers as coordinates for your objects. Temporarily convert the coordinates to integers when you draw them.
• 04-23-2003
Enf
thanx for replies

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