Game Maker Tutorial - Platform Game
Game Maker Tutorial - Platform Game
Game Maker Tutorial - Platform Game
TABLE OF CONTENTS
LESSON 1 - BASIC PLATFORM .............................................................................................................................................................3
RESOURCE FILES ......................................................................................................................................................................................... 4
SPRITES .................................................................................................................................................................................................... 4
OBJECTS ................................................................................................................................................................................................... 5
EVENTS/ACTION SUMMARY ......................................................................................................................................................................... 5
EVENTS/ACTION SUMMARY ......................................................................................................................................................................... 7
LESSON 2 - ADDING BACKGROUNDS ..................................................................................................................................................8
RESOURCE FILES ......................................................................................................................................................................................... 8
SPRITES .................................................................................................................................................................................................... 8
OBJECTS ................................................................................................................................................................................................. 10
BACKGROUNDS & TILE SETS ....................................................................................................................................................................... 10
ROOMS .................................................................................................................................................................................................. 11
LESSON 3 - MONSTERS ..................................................................................................................................................................... 15
RESOURCE FILES ....................................................................................................................................................................................... 15
SPRITES .................................................................................................................................................................................................. 15
SOUNDS ................................................................................................................................................................................................. 16
OBJECTS ................................................................................................................................................................................................. 16
MONSTER COLLISIONS ............................................................................................................................................................................... 16
EVENTS/ACTION SUMMARY ....................................................................................................................................................................... 17
OTHER COLLISIONS ................................................................................................................................................................................... 18
MONSTER MOVEMENT.............................................................................................................................................................................. 19
1|P a g e
2|P a g e
We will be building towards a more complex platform game but initially the lessons will be to establish a
relatively basic platform game so that you can get the hang of some new GameMaker events and actions.
3|P a g e
SPRITES
1. Create a new Game Maker file (File>New) then save as platform1. Remember to save the file every few
minutes.
2. You will need to add a number of sprites for this game. To do this right-click on the Sprites folder and select
Insert Sprite.
3. Click on the Load Sprite button and select the ball.gif file. Type sprBall in the Name box and remove the
background then click OK.
4. You will also need to create a sprite manually. Right-click the Sprites folder and select Insert Sprite.
5. Click the Edit Sprite button then double-click the sprite. This will take you into the Image Editor window.
6. Using the Fill Bucket
select a black colour then click on the image. Resize the image so that it is 16 x 16
pixels. Click the close and save button
twice then name the sprite sprBlock and ensure that the
background has not been removed.
4|P a g e
keyboard, <right>
keyboard, <up>
collision, objBlock
Action List
Action
Settings
Control
x: -4, y: 0, relative
Move
x: -4, y: 0, relative
Control
x: 4, y: 0, relative
Move
x: 4, y: 0, relative
Control
x: 0, y: 1, relative
Move
Move
Move
vert speed: 0
EVENTS/ACTION SUMMARY
The combination of events and actions will allow the ball to move left or right depending on whether or not
there is an obstacle blocking its path.
8. Add a new room (right click Room folder>Insert Room) then click the settings tab and change the room size
to a width of 640 and height of 480. Change both the snap X and snap Y values to 16.
5|P a g e
10. Test the game by pressing F5. When you click the left or right arrow key the ball should move in the
appropriate direction. When you click the up arrow the ball should move straight up without stopping. We
clearly need to add some more events and actions to give the ball a more realistic trajectory. In other words,
after jumping up, it will fall back down in the same way that gravity works on Earth.
6|P a g e
Action List
Action
Settings
Step, step
Control
x: 0, y: 1, relative
Move
Control
Move
Control
Control
EVENTS/ACTION SUMMARY
The Step event works by checking exactly what the objBall is doing at each moment during the game. The first
two actions check that there isn't a solid object underneath the ball and then allows the ball to drop back to the
ground using a gravity value of 0.5. Otherwise, gravity is set to zero. The last two actions prevent the vertical
speed from exceeding 12. As can be seen from the diagram below, setting the direction to an angle of 270
ensures that the player moves down.
12. Save and test the game again to make sure it works correctly.
7|P a g e
RESOURCE FILES
The files needed for this tutorial are located in the Lecture Resources/Resources 4 directory in the Game
Maker folder that was copied earlier.
SPRITES
The current platform game needs a little more refinement to make the interface look more attractive and
professional. For example, the player (which is currently the ball) will be changed into something more
meaningful like a person. The background is a little dull and will also require some major changes.
1. Two different sprites (one for when the player moves left and another when they move right) are needed. Add
the following sprites:
File
Name
Remove Background
player_left.gif
sprLeft
Yes
player_right.gif
sprRight
Yes
Uncheck the Precision collision checking box and set the Bounding Box for both sprites to manual. This is to
prevent the sprites from being caught in a wall or a ceiling as they are different sizes.
2. You will also need to create two more sprites manually. Because these sprites will be smaller versions of
sprBlock, it would be easier to duplicate the sprite created in the last lesson. Right-click the sprBlock sprite and
select Duplicate then type sprBlockH in the name box.
3. Click the Edit Sprite button and then double-click the image to edit the sprite...
8|P a g e
...Select the Transform menu and choose Stretch. Uncheck the Keep aspect ratio box and change the height to 8
pixels then click OK. Set the Origin Y value to 8. Save and close the sprite.
4. Duplicate the sprBlock sprite again. Name the new sprite sprBlockV and modify the settings so that its width
is 8 pixels and the height is 16 pixels.
9|P a g e
Action List
Action
Settings
Keyboard <left>
Main1
Keyboard <right>
Main1
6. Create objects for sprBlockH (objBlockH) and sprBlockV (objBlockV) and set the parent to Block for both
objects.
Ensure that the Visible property for all the blocks is unchecked. The reason for this is that the background tile
that we will be adding to the game a little later will have its own 'objects' which need to be visible during
gameplay.
10|P a g e
7. To add the sky background, right-click the Background folder and select Create Background. Click the Load
Background button and select sky.gif (located in the GameMaker/Background folder). Change the name
to bkdSky then save and close.
8. Repeat the above step and add the tiles.gif to the background. Check the Transparent and Use as tile
set boxes and type 1 into the horizontal and vertical sep: boxes. Change the name to bkdTiles then save and
close.
ROOMS
9. Double-click the room to edit the room then remove all the objects that were created in the last lesson. Click
on the Tiles tab and select bkdTiles.
11|P a g e
11. Repeat this process by selecting the other objects in the tile set and place them where needed until the room
looks like the example below.
12. To make the bkdSky visible, click the Backgrounds tab and modify the settings as shown below:
12|P a g e
13. The tile set images although visible are not solid and won't allow the player to walk on the or collide with
them. Click the Objects tab and cover the tiled images using the various blocks. The blocks if you recall have
been made invisible but are solid, so the game will give the impression that the player is walking on the various
images that have been placed from the tile set.
14. Repeat the above step until all tile elements are covered with blocks. For the smaller objects such as the
cloud and platform edges, you will need to change the snap settings for the room to 8 x 8. By doing this, you
can now add the block objects objBlockH and objBlockV to fill in the smaller sections.
13|P a g e
15. Change the snap settings back to 16 x 16 then add the objPlayer object to the room as shown. Save and test
the game. The player should be able to walk and jump along the platforms.
14|P a g e
RESOURCE FILES
The files needed for this tutorial are located in the Lecture Resources/Resources 4 directory in the Game
Maker folder that was copied earlier.
SPRITES
To help generate and maintain the player's interest more features need to be included in the game. For example,
there might be some monsters that need to be avoided or some objects that can be collected that will increase the
player's score.
1. Add the following sprites to the platform game:
File
Name
Remove Background
monster_1_left.gif
sprMonsterL
Yes
monster_1_right.gif
sprMonsterR
Yes
monster_1_flat.gif
sprMonsterFlat
Yes
monster_2_left.gif
sprFlyingL
Yes
monster_2_right.gif
sprFlyingR
Yes
sprMushroom
Yes
sprLevel
Yes
mushrooms.gif
levelexit.gif
Uncheck the Precision collision checking box and set the Bounding Box for all sprites to manual.
2. You will also need to create two more sprites from scratch. Duplicate sprBlock and name this sprite
sprMarker then change the fill colour to blue. Duplicate sprBlockH and name this sprite sprDeath then change
the colour to red.
15|P a g e
Name
boing.wav
monsterkill
ao.wav
killplayer
ploup.wav
getmushroom
harp.wav
finishlevel
OBJECTS
4. Create objects for each of the new sprites using the image below as a guide:
MONSTER COLLISIONS
There are two types of monsters that the player will encounter - the walking monster and the flying monster.
The way that the players reacts to each monster will also be different. For example, the player will be able to
destroy the walking monster by jumping on top of it. All other collisions with other monsters will result in the
player losing a life.
5. Add the following events/actions to objPlayer:
16|P a g e
Action List
collision,
objMonster
Control
Action
Settings
vspeed> 0 and y < other.y+8
Control
Control
Main1
sound: killmonster
Score
Move
no move, other
Main1
Control
Control
Control
Control
Main1
sound: killplayer
Main2
milliseconds: 1000
Main1
Control
collision, objFlyer
Main1
sound: killplayer
Main2
milliseconds: 1000
Main1
EVENTS/ACTION SUMMARY
The first action is checking to see if the player is in the air and above the monster. If this condition is met, then the player will be
able to destroy the monster. The actual sequence of events following the player jumping on top of the walking monster is as
follows: Play sound of killing monster, Add 50 to score, Stop the monster from moving, Change the normal 'alive' monster
sprite into the dead monster. For all other collisions with the monster, the player dies and the room is then restarted.
17|P a g e
Mushroom - This will add points to the player's score and destroy the mushroom
Level Exit - This will proceed to a new room if it exists, otherwise it will display the high score table
and restart the game
Death - This will kill the player and restart the room
Another event (other, outside room) will check if the player has moved beyond the height of the room, and will
result in the player losing a life and the room restarting.
6. Add the remaining events/actions to the objPlayer object:
Event
Action List
collision, objMushroom
Main1
sound: getmushroom
Score
Main1
destroy: other
Main1
sound: finishlevel
Main1
milliseconds: 1000
collision, objLevelExit
Action
Settings
Main1
Control
Main1
Control
Control
Control
Score
Main2
Control
18|P a g e
background: bkdSky
Action List
Main1
Action
Settings
sound: killplayer
Score
milliseconds: 1000
Score
Main1
other, outside room
Control
variable: y, value:
room_height, operation:
larger than
Control
Main1
sound: killplayer
Main1
Main1
milliseconds: 1000
Control
MONSTER MOVEMENT
Each of the monsters will follow a similar movement pattern during the game. The only difference is that one of
the monster types will appear to be flying. Both monsters will move in a particular direction until they encounter
either a block or a marker, after which they will reverse their direction. To take into account this direction
switch, the monster sprite will change into either a left-facing or right-facing monster.
7. Add the following events/actions for objMonster:
Event
Action List
Action
Settings
Create
Move
Control
Main1
Control
Main1
collision, objBlock
Move
collision, objMarker
Move
19|P a g e
Action List
Action
Settings
create
Move
Control
Main1
Control
Main1
collision, objBlock
Move
collision, objMarker
Move
The variable hspeed is used to determine the direction that the monster is travelling, and hence which sprite
(left or right monster) it must change into. When hspeed is greater than 0, this means that the monster is moving
from left to right.
9. Add the following events/actions for objMonsterDead:
Event
Action List
Action
Settings
create
Main2
alarm, alarm 0
Main1
self
Action List
create
Main2
Action
Settings
sprite: sprMushroom, subimage:
random(10), speed: 0
When the mushrooms are added to the game in the next step, they will all appear to look the same. However, by
using the event/action created above, the game will change the appearance of the mushroom to one of ten
possible sub-images available within this sprite.
20|P a g e
11. Select the Objects tab and add the objects shown below. Save and test the game.
21|P a g e
RESOURCE FILES
The files needed for this tutorial are located in the Lecture Resources/Resources 4 directory in the Game
Maker folder that was copied earlier.
SPRITES
This version of the game will include the addition of features such as the player being able to climb vines and
walk up and down ramps.
1. Add the following sprite to the platform game:
File
Name
Remove Background
player_up.gif
sprClimbing
Yes
Uncheck the Precision collision checking box and set the Bounding Box for all sprites to manual.
2. You will also need to create a new sprite. Duplicate sprBlockV and name this sprite sprLadder then change
the backcolour to black and the fill colour to green. Make it transparent.
OBJECTS
3. Create the object objLadder using the sprite sprLadder and set visible to false.
22|P a g e
Action List
Step, step
Control
Action
Control
Settings
object: objLadder, x:0, y:0,
relative
Control
Move
Control
Main1
Control
The complete set of actions for objPlayer step event should like the following:
23|P a g e
Action List
Keyboard <up>
Control
Action
Settings
object: objLadder, x:0, y:0,
relative
Control
Control
Move
Control
Control
Control
Control
Move
Control
Keyboard <down>
Control
Control
Control
Move
x: 0, y:3, relative
Control
24|P a g e
Action List
Action
Settings
Keyboard <left>
Main1
Control
Move
Control
Control
Control
Move
Move
Control
Keyboard <right>
Main1
Control
Move
Control
Control
Control
Move
Move
Control
25|P a g e
26|P a g e
27|P a g e
28|P a g e
RESOURCE FILES
The files needed for this tutorial are located in the Lecture Resources/Resources 4 directory in the Game Maker folder
that was copied earlier. For the final version of the platform game, the following new features will be added:
The player will be able to collect ammunition and shoot the monsters.
There will be moving platforms as well as platforms that disappear when the player jumps on them.
SPRITES - AMMUNITION
1. Add the following sprites to the platform game:
File
Name
Remove Background
bullet.gif
sprBullet
Yes
ammunition.gif
sprAmmunition
Yes
OBJECTS
2. Create objects objBullet and objAmmunition using the sprites created in the previous step.
3. When the game first starts, the player will have no ammunition to shoot. It is only when the player collects
the ammunition object that it will then have the capability to fire bullets at the monster. Modify the objPlayer by
adding the new events/actions as shown below:
Event
Action List
Create
Control
collision, objAmmunition
Control
Main1
destroy: other
29|P a g e
Action
Settings
Action List
Control
Action
Settings
variable: ammo, value:0,
operation: larger than
Control
Control
Main1
Control
Main1
Control
Control
4. The next sequence of events/actions will deal with the bullets being fired from the player's gun. Add the
following events/actions to the objBullet object:
Event
Action List
collision, objBlock
collision, objMonster
collision, objFlyer
30|P a g e
Action
Settings
destroy: self
Control
sound: killmonster
Control
Control
destroy: other
Main1
destroy: self
Control
sound: killmonster
Main1
Control
destroy: other
Control
destroy: self
destroy: self
Collision with objBlock - This will destroy the bullet when it hits any of the walls, platforms, etc.
Collision with objMonster and objFlyer - This will destroy the monster as well as the bullet and add 50
to the score (as well as play the killmonster sound).
Outside room - This will destroy the bullet as soon as it leaves the room.
ROOMS
5. Open the room and place the objAmmunition object anywhere in the room. Save and test the game. When the
player collects the ammunition, they should be able to fire at and kill the monsters in the room.
Name
Remove Background
fallingblock.gif
sprFallingBlock
Yes
7. This sprite needs to be made into an animated gif where it will start as a solid object then slowly fade away.
Click the Edit Sprite button.
8. Click the Animation menu and select Disappear. Type 5 for the number of frames.
9. Ensure that the Remove Background option is selected then click OK.
31|P a g e
Action List
Create
Control
variable: image_single;
value: 0
Step, step
Control
object: objPlayer; x: 0;
y: -2; relative
Control
variable:image_single;
value: 0
Control
variable: image_single;
value: -1
Main1
self
Animation, end
Action
Settings
ROOM
12. Modify the room to include the falling blocks in the bottom right corner (just above the pit) as shown below:
32|P a g e
SPRITES
9. Add the following sprite to the platform game:
File
Name
Remove Background
heart.gif
sprBonus
Yes
OBJECTS - BONUS
10. Create the object objBonus using the sprite sprBonus created in the last step.
11. Modify the objPlayer by adding the new events/actions as shown below:
Event
Action List
Action
Settings
Collision, sprBonus
Control
Control
Main1
self
33|P a g e
Action List
Score
new lives: 3
Score
Score
Action
Settings
Main2
Draw
34|P a g e
Draw
color: green
Draw
x1: view_xview + 5
y1: view_yview + 1
x2: view_xview + 100
y2: view_yview + 45
filled: filled
Draw
color: black
Draw
x1: view_xview + 5
y1: view_yview + 1
x2: view_xview + 100
y2: view_yview + 45
filled: outline
Score
x: view_xview+10
y: view_yview+10
image: sprLife
Score
x: view_xview+10
y: view_yview+28
score: Score
Control
variable: objPlayer.ammo
value: 0; operation: larger than
Main1
x: view_xview+70
y: iew_yview+2
subimage: 0
EXTENSION
Create some more additional rooms with extra challenges to make the game more interesting.
35|P a g e