Archived

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

2d game

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

If you intended to correct an error in the post then please contact us.

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


Link to post
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).
Explain better so we can help you :-/

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites