#### Archived

This topic is now archived and is closed to further replies.

# 2d game

This topic is 5310 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am writing a 2d shooter. I want one of the bad guys to move in a circle. Has anyone got a function to track the x and y coordinates. Thanks Also the faster the code the better!!

##### Share on other sites
Could you give us more information? What do you mean by "function to track the x and y coordinates"? What is this 2d shooter like, is it sth like Raptor (view from above) or Defender (right side scrolling).

##### Share on other sites
well, given an angular velocity (how fast they follow the circle)...

angle += angular_velocity * dt;
x = circle_centre_x + circle_radius_x * cos(angle);
y = circle_centre_y + circle_radius_y * sin(angle);

dt being the time elapsed since last position update, or a fixed time, like (1.0f / 60.0f), 60 being equivalent to 60 fps.

you can move the circle_centre, and change the circle_radius, to make the enemy ships circle move and change shape. having a different radius along x and y will make them follow an ellipsoid. You can make the circle pulse that way, and make the circle bounce or follow an ellipsoid.

angle will also be a parameter for every ship, like x and y.

[edited by - oliii on January 4, 2004 9:03:47 AM]

1. 1
Rutin
24
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 9
• 46
• 41
• 23
• 13
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002033
×