Page 1 of 1

Rotating Actor

PostPosted: Sat Jul 14, 2007 12:26 pm
by Nova
Hey, I'm working on an asteroids type game, and I'd therefore like to have my actor rotate left or right when the left or right key is pressed or held. Also, because it is in space, I'd like to have some drag, so that if the player lets go of left or right, the ship is still moving for a second or two.

Also, I have it at the moment so that when a particular key is pressed, the ship moves forward, so Y=Y-1 however, this will be impractical when I have implemented the rotating, so could somebody suggest a better alternative for me? I'd also like some drag with that.

Thanks all, I'm sorry if my questions seem a bit newbie-ish, i've only just picked up this program, it's ace!

PostPosted: Sat Jul 14, 2007 3:22 pm
by d-soldier
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.

PostPosted: Sun Jul 15, 2007 1:36 am
by berighteous
In OidZone I use 2 angle table arrays with with dx and dy thrust amounts for each of the 24 directions. 24 is plenty for an asteroids game. It's very smooth. When I thrust the ship I index into the tables to add the dx and dy values to the xvelocity and yvelocity of the ship. I have a speed limit set to about 5 pixels in either direction.

Once you're moving in a direction you keep moving in that direction. To stop, you need to do a 180 degree rotation and thrust to slow down.

When I hyperspace I drop the speed in both directions by half.

There's a playable demo in the dev thread. I can't release the source files, but if you PM me I'll answer any question. In 1997 I wrote the game for the pc in vga 320x200 and I wrote a book on the game. Now I'm writing it for the Gp2x. I'm hoping it will be the ultimate Asteroids game.
:D

PostPosted: Sun Jul 15, 2007 7:25 pm
by Nova
Thanks guys, it's all sorted now, your help has been valuable.

I have another question, if anyone wouldn't mind answering this one.

When my ship shoots an enemy, I want it to respawn in a random location somewhere else, so there are always 28 enemys in the play area at once (though not all on the view area, as the game scrolls).

If this is too difficult to do, I'd like to have the enemy respawn after a set time in the same place.

I'd prefer it if anyone could help me do the first, but I don't mind the second if there is no alternative.

Thanks again.

PostPosted: Sat Jul 21, 2007 12:30 pm
by Nova
Nova wrote:Thanks guys, it's all sorted now, your help has been valuable.

I have another question, if anyone wouldn't mind answering this one.

When my ship shoots an enemy, I want it to respawn in a random location somewhere else, so there are always 28 enemys in the play area at once (though not all on the view area, as the game scrolls).

If this is too difficult to do, I'd like to have the enemy respawn after a set time in the same place.

I'd prefer it if anyone could help me do the first, but I don't mind the second if there is no alternative.

Thanks again.


Anyone?

PostPosted: Sat Jul 21, 2007 6:11 pm
by pixelpoop
make a destroy actor event -> script editor

in the script editor write(change the actorname and actor_animation to match):

CreateActor("actorname", "actor_animation", "(none)", "(none)", (view.x+rand(view.width)), (view.y+rand(view.height)), true);

note:this assumes the play area is the view actor, you may have to change the code for your play area