If you open GM and you don’t see these extra folders, then go to File > Advanced Mode…


Go to File > Open. Then click on Home > GameMaker …


Open the platformer starting file. Open the Objects folder; you should see the objects already there. Make sure you are in Advanced Mode!


Moving Left
Go into the object character and add the <Left> Keyboard event:

- Change Sprite: set to the left character sprite (don’t worry about subimage or speed)

- Check Empty: is just to the left of the character empty?
(-4,0), only solid, relative - Jump to Position: (-4,0), relative


Moving Right
Duplicate the previous event for the <Right> Keyboard event.

Open the Change Sprite action and change it to the right-facing character sprite.

Then change the X values to 4 for the Check Empty and Jump to Position actions. They should stay relative.


So your <Right> event looks like this…

Save then test the game, make sure the character moves left and right.

Jumping
Jumping up only if character on the floor
We have to let the character jump when the up arrow key is pressed. But this must only happen when the character is currently on the floor.
Add an <Up> event. We first test whether the position below the character creates a collision…

- Check Collision: is character on the floor/platform?
with only solid objects at (0,1), relative - Speed Vertical: set to -10


If character is in the air
Now add a Step event…add a Comment action (type in the box “check whether in the air”)

If character is in the air, if the position just below character is empty (no solid objects), then set the gravity to a positive number.

- Check Empty: (0,1), only solid, relative

- Set Gravity: direction = 270 (=down), gravity = .5 (not relative).
- Else
- Set Gravity: direction = 270, gravity = 0 (not relative)


We also want to limit the vertical speed so if it’s more than 12, we’ll set back to 12. So add a few more actions:

- Comment – “limit vertical speed”
- Test Variable: if variable vspeed > 12
- Speed Vertical: set to 12


Landing
In the character object, we have to make sure he lands correctly on the floor (when collides with a block object). We need to place the character back to its previous position just before the collision; if it’s already at the current position, it doesn’t move.
Add the Collision with block event.

- Move to Contact: direction = “direction” (indicates the current direction of motion of the object), maximum = “12”, against solid objects
- Speed Vertical: set to 0


Save then test your game.

Your character should be able to jump up and land on platforms.

Mushrooms
To give a bit of variation, the mushroom sprite contains 10 different mushrooms sub-images. We will set it so when the room loads, it randomly picks which subimage to show for each mushroom object.

Go into the mushroom object and double-click on the Change Sprite action…

- Change Sprite: subimage = random(10)

Collecting mushrooms
Go into the character object, add a Collision with mushroom event.

- Set Score: give player 10 points
- Destroy Instance: other (= mushroom)


Score Panel
Go into the controller object. Add the Draw event (so the player can see how many lives they have, the score and later if they have ammo).

Score Panel Rectangle
Start by adding the rectangle (fill and outline)…

- Set Color: a light color
- Draw Rectangle: x2 = 90, y2 = 45
this will draw a rectangle filled with the background color X1 & Y1 are where it starts drawing, X2 & Y2 are how wide/high the area is. These are starting values but you can play with them if you want to give your player bonus lives and need more room in the panel.


- Set Color: set to black (= the outline color)


- Draw Rectangle: x2 = 90, y2 = 45, change to “outline”

Draw Lives and Score
Now draw life images and the score.

- Draw Life Images: x = 10, y = 10, image = “life”
draw little life sprites to show how many lives the player has - Draw Score: x = 10, y = 25, caption default


Save and test your game.

- the score panel should show in the top left corner
- the mushrooms should all look different
- when you collect mushrooms, your score should go up

Next Level
Go into your player object and add a Collision with nextLevel. Add the actions as shown below…

Pits
Player Falls into Pit
Go into the character object and add a Collision with death event.
- Sleep
- Set Lives: lose a life (make sure it’s relative!)
- Restart Room


Player Jumps Outside Room
Add an Outside Room event for the character…

- Test Variable: y > room_height
test whether the character jumped outside the playing field - Restart Room


When testing this function in your game, you need to jump outside the areas where there are not blocks. The picture below shows where those areas are…

Save and test your game.

Test to see if the player jumps back to its starting position with these 2 scenarios:
- if the player lands on the pits/death object
- if it falls out of the room
KEEP THE GAME OPEN IN PLAY MODE TO GET CHECKED OFF!!!!
