Asteroids ship rotation
I''m making an Asteroids game in C++ class. (you know how it is for us smart C++ guys who finish our required stuff quickly so we can make games) We''re working with Turbo C++. That means using the pitiful Turbo C++ graphics commands. Now, I''ve decided the ship will just be a triangle until I decide on somehting else. What I need is some way to have this traingle rotate when the player pushes the left and right keys. Thanx for the help
C:DOSC:DOSRUNRUN DOSRUN
I just made an asteroids clone in DX, i did. Its tight! I might just e-mail it to ya.
to rotate any point around the origin the equation is (if you have taken trig it''s a sinch).
newx = x*cos(angle) - y*sin(angle)
newy = y*cos(angle) + x*sin(angle)
if you want to rotate around any point you must first translate the point, rotate, and then translate back.
also remember to use sine and cosine lookup tables so that you don''t waste precious time calculating things more than once.
I have always been lost!
newx = x*cos(angle) - y*sin(angle)
newy = y*cos(angle) + x*sin(angle)
if you want to rotate around any point you must first translate the point, rotate, and then translate back.
also remember to use sine and cosine lookup tables so that you don''t waste precious time calculating things more than once.
I have always been lost!
Sentence you never want to here: Is it ok to eat the fuzzy stuff in your belly button?
Of course, if you wanted to go the full physics route, you could cause a turn-button press to add a rotational force to the ship. Then divide the force with the mass to find the acceleration. And so on... until you have your delta theta.
If I wasn''t so lazy I''d do the above. The ''standard'' asteroids way of doing it is to have a left/right button press increment the angle (that corresponds to the current facing). I think. At least that''s what I''m currently doing.
Dark Lord Pi
If I wasn''t so lazy I''d do the above. The ''standard'' asteroids way of doing it is to have a left/right button press increment the angle (that corresponds to the current facing). I think. At least that''s what I''m currently doing.
Dark Lord Pi
Dark Lord Pi
Thanx alot. Even though I don''t understand the equation above for rotation (I''ve only used sines and cosines to calculate angles and measures of a right triangle), I think I can make some sort of use for it. Thanx again.
C:DOSC:DOSRUNRUN DOSRUN
On the subject of asteroid clones:
movement is easy and all, it seems
while up arrow is pressed:
x-velocity += cos(direction)*speed;
y-velocity += sin(direction)*speed;
but how the hell do you implement a max-speed? I don''t think friction in space will be very realistic, but I tried tons of stuff. I have something that works somewhat, but it''s not mathmatically correct or anything. Just put it together with trial and error
DarkAgito
movement is easy and all, it seems
while up arrow is pressed:
x-velocity += cos(direction)*speed;
y-velocity += sin(direction)*speed;
but how the hell do you implement a max-speed? I don''t think friction in space will be very realistic, but I tried tons of stuff. I have something that works somewhat, but it''s not mathmatically correct or anything. Just put it together with trial and error
DarkAgito
The max speed is c. Don''t worry about exceeding it in your program, because you can''t.
If you really want to worry about it, do this:
If you really want to worry about it, do this:
// do frictionif (--speed<0) speed=0;// do thrustif (UpArrow is pressed) { speed += 2; if (speed>maxSpeed) speed=maxSpeed;}
May 03, 2000 02:02 PM
I''ve got an almost complete vector graphics engine written in QuickBASIC (I know I know). Anyway, it does have all the formulas you''d need for rotation, velocity and even particle effects. It is slow (runs at 20 fps on my 550MHz) but that''s not the point. It has the formulas, so if you want it just let me know and I''ll email it to you.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement