by d-soldier » Sat Jul 14, 2007 3:22 pm
Nova, I think an Asteroids game would be a great place to start, and you will learn a lot from making it. As far as the player movements go, heres how I did it in mine (which might be merely a modified version of how Makslane did it in the demo which can be downloaded from the demo section).
1) My player actor had one animation set, which is him rotating (from facing right, counter-clockwise in a full 360 degree rotation. My set was 120 frames for smooth movement, but 72 would be fine too.
2) The player's create actor script had the animation movement "stopped", and on the keydown event for "left" all I did was change the animation direction to "backwards" with "repeat" enabled, and a follow up Key-up event set to stop the animation direction again. The same process was applied to the "right" key, but changing the animation direction to "forward" instead. Another key-up event (for the right key this time) to stop the animation movement when the button is released.
3) For the "up" button my keydown script looked like this:
double newangle = (animpos/nframes)*360;
vectoradd(&angle, &directional_velocity, newangle, 0.5001);
(since I'm not really sure what this does exactly, it probably came from the Asteroids demo as well) But it makes you move in the direction that you are facing in accordance with your animation position.
4)In the player's DRAW ACTOR script I had the following:
int w = view.width/2 + width;
int h = view.height/2 + height;
if(x > w) x = -w;
if( y > h) y = -h;
if(x < -w) x = w;
if(y < -h) y = h;
directional_velocity *= .955;
if(directional_velocity < 0.0001) directional_velocity = 0;
This directs it to go off the screen and re-appear on the opposite side, and sets the interia for the ship (the drag you spoke of). You can adjust the values on the last two lines until you get a level of interia that you like. I may post the source files for my asteroids game "HULL BREACH" before long if Makslane wants to put it in the demo section for people to download. Hope this was what you needed.