Arcade Movement

Bring it on down!
Feb.23.2003 - 10:53 am - Revised Mar.07.2004
These shouldn't get longer then a few paragraphs so if I ramble beat me.
I will only show how to make Up, Down, Left and Right...but the ideas
can be applied to corner keys pretty easily. First open your Global
Script (Ctrl+G). Scroll down to the on_key_press function which will
have a list of a bunch of if(keycode==blah) blah blah...so on and so
forth. Just to try a little shock therapy I'm just gonna give the script
in whole...
if (keycode==372) { // up arrow
MoveCharacterStraight(EGO, player.x, player.y-200);
while ((IsKeyPressed(372)>0) && (character[EGO].walking)) Wait(1);
StopMoving(EGO);
}
if (keycode==375) { // left arrow
MoveCharacterStraight(EGO, player.x-200, player.y);
while ((IsKeyPressed(375)>0) && (character[EGO].walking)) Wait(1);
StopMoving(EGO);
}
if (keycode==377) { // right arrow
MoveCharacterStraight(EGO, player.x+200, player.y);
while ((IsKeyPressed(377)>0) && (character[EGO].walking)) Wait(1);
StopMoving(EGO);
}
if (keycode==380) { // down arrow
MoveCharacterStraight(EGO, player.x, player.y+200);
while ((IsKeyPressed(380)>0) && (character[EGO].walking)) Wait(1);
StopMoving(EGO);
}
|
So there it is. Up, Left, Right and Down...Goodbye!....... Okay I'll explain. The first line:
|
if (keycode==372) { // up arrow
|
Checks if the Up arrow is being pushed...whoop! The second:
|
MoveCharacterStraight(EGO, player.x, player.y-200);
|
Moves the character directly up. It is important to use
MoveCharacterStraight so that the character ignores walkable areas and
only moves in a straight path. If not people would think your character
is drunk. The third:
|
while ((IsKeyPressed(372)>0) && (character[EGO].walking)) Wait(1);
|
This is the important line. This checks if the key is still being
pressed and if the character is still moving...If it isn't on to line 4:
The character is stopped. Then the final brace ( '}' ) and the script
is done. notice the minor changes for each key to accomodate the
different keys to be pushed and different directions used...
|
|