How to Make a Custom 8-directional Movement in just FOUR Lines of Code!
Author: | RapidFlash
|
Submitted: | 14th February, 2003
|
Views: | 5926
| Rated: |
|
|
How to Make a Custom 8-directional Movement in just FOUR Lines of Code!
Remember, to move to the left you subtract from x, to move to the right you add to x.
And as for up and down? To move up you subtract to y and to move down you add to y.
Here's how you do it:
First, let's say we have a 640x480 frame. Next, we have a 9x21 active object (width of 9, height of 21). We'll do the following code by pasting it in:
Repeat while (Player 1) moved left ---> X ( Active ) - 3 (Go to Active->Position->Set X Coordinate)
No more (Active) in zone (-43,0) to (0, 495)
Repeat while (Player 1) moved right ---> X ( Active ) + 3 (Same place above)
No more (Active) in zone (627,-5) to (688, 480)
Repeat while (Player 1) moved up ---> Y( Active ) - 3 (Go to Active->Position->Set Y Coordinate)
No more (Active) in zone (0,-128 ) to (640,0)
Repeat while (Player 1) moved down ---> Y( Active ) + 3 (Same place above)
No more (Active) in zone (0,456) to (661,573)
TADA! There's your custom movement! But now you may ask, But this doesn't have anything about moving up-left or down-right? How can that move in eight directions? The answer: It's automatically done. Pressing or holding up-left is like pressing or holding up AND left. So what basically happens is MMF/TGF/K&P does the Repeat while (Player 1) moved left event and the Repeat while (Player 1) moved up event, making the player move left and up at the same time.
NOTE: This code above only works perfectly with a 640x480 frame and a 9x21 active object. Remember to change the No more (Active) in zone (x,x ) to (x,x ) to suit your needs. You probably should change the amount the player moves, too.
One more thing: If you use this code during the game, PLEASE mention me somewhere in the credits.
|
|
RapidFlashSavior of the Universe Registered 14/05/2002
Points 2712
|