One of the first things we need to look at is how to give our character platform movement. It should move left or right when the left or right arrow keys are pressed. It should jump when the up arrow key is pressed and there should be gravity, so it should fall when it is not standing on a platform.
We are going to make our character move by changing its coordinates. By changing the x coordinate it can be made to move horizontally.
Create a character and a few blocks to make a platform to
walk on. I will use sprPerson
,
sprPlatform , objPerson
and objPlatform. (Don't forget to make your platform
solid.)Place them in the room |
||||||||||
|
|
Open the properties for your person object. Add a left
keyboard event. Check if the Relative position
(-4,0) is collision free (Control tab). If it
is then jump to that position.
|
|||||||||
|
|
Now add an event for the right keyboard, but use coordinates (4,0) relative instead. | |||||||||
|
|
Jumping
Add an event for the up key. Check if the relative position (0,1) has a collision (that means there is something solid 1 pixel below the player) If it is, then set the vertical speed to -10.
|
|||||||||
|
|
GravityNow we have started the jump, gravity should take effect as soon as the character is not touching the ground. We need to check that the character is touching the ground all the time, so we add it to the step event. Gravity will need to be downwards which is 270 degrees. (Click here to see why) Set the value for gravity to be 0.5. Later you can experiment with this and the vertical speed to get the right effect. Then add in an else action, this time set the gravity to 0 The only thing left to do is to limit the vertical speed of the character, otherwise gravity would cause it to get faster and faster. If the vertical speed is greater than 12, we will set it to be 12. Here is the final step event:
|
|||||||||
|
|
LandingNow we just need to make the character land on the platform correctly. Add an event for a collision with the platform object. Set the vertical speed to 0. There is one problem. Because of the game moving in steps, the character is not always correctly aligned with the ground when a collision is detected. So we need to move the player to a position touching the platform. Add a move to contact position action. This moves the character one pixel at a time until it contacts something. For the direction, put direction. This will use whatever direction the player was already moving in. The maximum value is the maximum number of pixels it can be moved. Set this to 12.
|
|||||||||
|
|
Climbing LaddersMake a ladder sprite that is 16x16 pixels and is transparent. Remove precise collision checking. Down the middle of the sprite draw a block of colour that is 4 pixels wide. Make a ladder object that will be invisible and sit on top of a tiled background where there is an object we can climb. The ladder object should not be solid and should not be visible. Add the ladder into your room. |
|||||||||
|
|
As soon as the character contacts the ladder, it should
no longer be affected by gravity and it should be able to climb up
and down. Also its sprite could be changed into a climbing
sprite.
Open the person object and its step event.
|
|||||||||
|
|
Now we need to enable climbing on the ladder. To the Up keyboard event, add in the following actions: Check if there is an objLadder at (0,0) relative. If the position (0, -3) relative is free, then jump to it. (The position (0, -3) relative is 3 pixels above the player)
|
|||||||||
|
|
Enable Climbing DownTo climb down the ladder, add in a keyboard down key event. Put in the same actions as for the Up key, but use coordinates (0,3) instead. |
|||||||||
| Now you just need to work on designing a room for your character to move in. You should place platforms that are possible to jump to. You need to make sure it is not too easy, but not too hard. The levels should get more difficult the further through the game you go. |