Archived

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

knealeaj

2d game

Recommended Posts

knealeaj    122
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 this post


Link to post
Share on other sites
Koshmaar    989
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).
Explain better so we can help you :-/

Share this post


Link to post
Share on other sites
oliii    2196
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]

Share this post


Link to post
Share on other sites