Archived

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

Mkk

Breakout clone, ball´s moving

Recommended Posts

I´m working out with Breakout clone (C++/OpenGL) and now I need some help with figuring out how to move ball correctly. Ball has a variable angle (direction). Question is: How can I increase/decrease ball x and y variables correctly based on this angle variable? Thanks.

Share this post


Link to post
Share on other sites
I don't know openGL, but if you know the angle you want the ball to travel in, and the total velocity, then x_increment = velocity*cos(angle); and y_increment = velocity*sin(angle);

that will give how much x and how much y to move it by every time to move in that angle. The angle will probably have to be in radians. If you're not familiar with radians, the formula for degrees to radians is r=(pi/180)*d .

You'll have to find a way to save precision among the types you're using.

[edited by - masque01 on March 21, 2004 1:39:14 PM]

Share this post


Link to post
Share on other sites