Skip to main content
gamedev.net
🔒 Locked

2d game

Started by knealeaj 1 reply 850+ views
Original Post
knealeaj
knealeaj
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!!
oliii
oliii
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]
Everything is better with Metal.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.