Platform Game

Platform Tutorial Page 1
Platform Game
Tutorial: Creating Platform Games
.
In a platform game, the player views the world as a
scrolling experience, walking their avatar through
it to overcome obstacles and collect rewards. The
different vertical levels that the avatar can reach
are called “platforms.” The avatar might jump up
or down from one platform to another, or employ
ladders, ropes, and other methods to reach different
platforms within the game. Each platform offers its
own challenges to a player’s reflexes and puzzlesolving skills with rewards that are consummate
with the challenges.
It is not easy to create a good Platformer, even in
Game Maker. This tutorial will help you with three important aspects:



I.
Creating natural motion for the avatar.
Creating variations in monsters, backgrounds, and so forth.
Designing levels that are fun and increasingly challenging.
Starting with the very basics
two basic Objects
1 controls player
2 block Object that is used for the floor and which ‘platforms’ that the avatar can walk on cannot pass through as well.
A. Make the first two Sprites:
First, make ‘spr_block,’ a black square that is ‘visible’
turn off ‘Precise collision checking.’
second - add ‘spr_ball.’ All the default settings are fine for this Sprite.
B. Now each requires an Object in the game.
Make ‘obj_block,’ using the matching Sprite. Make sure it is ‘Visible,’ ‘Solid,
Walk or Run?
Another question is whether the avatar’s motion has constant speed or should it accelerate when you keep the key pressed?
For simplicity, we’ll keep the motion constant. Although allowing for acceleration (“running”) can create more interesting gameplay (e.g., the player
must run to jump over a wide hole), it is a bit much to learn at this moment.
1. Motion: This is crucial in a platform game
First, we need the avatar to walk on top of floors; no intersecting with a floor object that
jumps or falls off a platform, it must land correctly on the next one.
Tutorial by Alan Emrich.
Platform Tutorial Page 2
In Game Maker there are many ways to make a character walk, jump, and fall (different
platform games use different methods), but we’ll start with a simple way of handling this
using the left, right, and up arrow key to move the avatar.
2. Create an Object called ‘obj_avatar’ and use ‘spr_ball’ for the picture; the default settings
are fine.
a) Add a Keyboard <Left> Event then tab to control to set its Actions. There are only
two:
In Platformers, it is normally the
easiest to let the vertical
(“jumping”) motion be done
automatically (as you will soon
see), and to define the
horizontal motion ourselves as
we do for the <left> and <right>
arrow keys.
The first Action is ‘If a position is collision free’ with ‘x’ set to ‘–4,’ and ‘y’ set to
its default at ‘0’ only with ‘Solid objects’ that are ‘Relative’ to the avatar’s position.
You’ve just told the avatar to “look” 4 pixels to the left and make sure that the coast
is clear.
The second Action is to physically move the avatar 4 pixels to the left. That is, we’ve
looked, and now we can “leap” since it is not blocked. Tab to move and select ‘Jump
to a given position’ and set ‘x’ to ‘–4,’ leave ‘y’ at ‘0,’ and make it ‘Relative’ to the
avatar’s current location. That will move the avatar 4 pixels to the left (if the path is
unblocked). It should look like this:
b) Now do the same thing again, but this time add a Keyboard <Right> Event. In this
Event, change the Actions so that ‘x’ = ‘4’ (that is, 4 pixels to the right of the avatar’s
present, or ‘Relative,’ location) instead of ‘–4’ (which is 4 pixels to the left).
c) That takes care of <Left> and <Right>; now for <Up>. Add a Keyboard <Up> Event
and assign it the following two Actions:
Tab to the control page and select ‘If there is a collision at a position.’
Leave ‘x’ at ‘0’ this time, and change ‘y’ to ‘1’ against ‘Only solid’ object that are
‘Relative’ to the avatar’s current position.
In other words, look to see if there is something solid 1 pixel below – that is, see if the
avatar is standing on a platform. next Action, which is to jump up.
Next, tab to move and ‘Set the vertical speed’ to ‘–10’ as shown to the left.
Thus, when you jump, it will be “up” (that is, a negative vertical number) at a motion
speed of ’10.’
Without any gravity, what goes up never comes down. We’d better fix that with
another Event.
The event we need is Sequence of Play
d) Add a Step: Step Event so that we can check to see if we’re floating around after
jumping.
Tab to control and let’s leave a comment for ourselves.
Tutorial by Alan Emrich.
Platform Tutorial Page 3
Select ‘Put some comment’ (the yellow triangle with an exclamation point in it)
comment can be “Check whether in the air.”
The first real Action is to check to see if we’re really in the air or if we’re standing on
something. So, drag over ‘If a position is collision free’ and leave ‘x’ at ‘0,’ change
‘y’ to ‘1,’ against ‘Only solid’ objects that are ‘Relative’ to our location. In other
words, make sure that there is nothing solid in the pixel below us. As shown below:
Gravity
When you set the gravity for a particular
Object
Object can have its own unique gravity
setting – they need not be constant, you
must specify a direction (i.e., an angle
between 0 and 360 degrees) and a
speed.
Each Step, this amount of speed in the
given direction is added to the current
motion of the Object instance.
Typically you want a downward
direction look at the picture I put
below just like the one in your notes
already.setting it to 270 degrees as
shown in the illustration below- only set
a very small speed increment (like 0.01).
If you check the ‘Relative’ box, you will
be increasing the gravity speed at very
fast.
Have fun practicing You may want to
experiment and try to play a game with
this setting on just to see what
happens…
If that’s the case, our next Action can be found on the move tab, ‘Set the gravity.’
The direction is ‘270’ and the gravity “pull” itself is set to ‘0.5.’
Do not check the ‘Relative’ Box
Action, tab back over to control and select ‘Else.’ Then tab back to move and ‘Set
the gravity’ back to direction ‘270’ but with a gravity pull of ‘0.’ This action is also
not ‘Relative.’ What you’ve done is “turned off” the gravity effect if the current
relative position of the avatar Object is not collision free one pixel beneath it. You
don’t want gravity “oppressing” the avatar as it walks left and right on a platform.
e) Now we need to keep this Object from falling too fast in case it makes a long drop. In
other words, we need a “speed limit” while falling or it will not only look bad, but
might cause problems with the avatar falling so fast that it could pop right through a
solid object during a single Step!
Tab back to control and ‘Put some comment’ in to tell yourself that the next section
in the Sequence of Play you’re creating during this Step Event is to “Limit the
vertical speed.”
Now grab ‘If a variable has a value’ and in the pop-up window set the variable to
‘vspeed’ the value to ‘12’ (this is, a vertical speed of 12), and operation to ‘larger
than.’
“Is this Object’s vertical speed larger than 12?” as shown below:
Tutorial by Alan Emrich.
Platform Tutorial Page 4
If that’s true, it performs the next Action. Since we don’t want it to fall any faster, we
grab ‘Set the value of a variable’ set ‘vspeed’ to ’12.’ That way, it will never go
any faster than speed 12 while falling.
When you’re done, your Step Event should look like this:
Might have a problem test it I did
The avatar jumps when the up arrow
key is pressed. However, this must only
happen when the character is currently
on the floor, which is why we test
whether the position below the
character creates a collision.
If it does, we set the vertical speed e.g.
to –10.
You might want to play a bit with the
vale of –10 for the vertical speed and
the value of +0.5 for the gravity to get
the exact motion you want.
The “gravity” direction is set to
‘270’ which means, in Game
Maker terms, “straight down.”
The first Action is going to slow
down the jumping up speed
(which you set to –10) by +0.5
per step. Thus, in 2/3 of a
seconds (20 steps with 30
steps per second), all upward
motion will cease from the
slow increasing of downward
pressure from gravity. After
that, it will start it’s own
downward movement, slowly
at first, and maxing out at a
speed of ’12.’
Tutorial by Alan Emrich.
Platform Tutorial Page 5
f) But there is one big problem left; while what goes up now comes down, it currently
never stops going down!
Add a Collision Event with ‘obj_block’ for this, our obj_avatar.
Tab to move and grab the Action ‘Move to contact position’ from the middle. We
want to set the new direction after this collision to be the same direction we were
previously moving it, so for direction, use the variable ‘direction.’ Set the maximum
distance to ‘12’ against ‘Solid objects’ and shown below:
Move to Contact Position
A Happy Landing
When the avatar lands on a platform, it has to land correctly,
which requires two Actions instead of one.
The obvious Action to take is to ‘Set the vertical speed’ to ‘0.’
In other words, “stop falling when you land on something
solid.”
But doing this might leave the avatar floating a bit above the
ground. This is because the avatar is automatically placed (by
“default”) back in its previous position before the Collision
Event.
That is why we move the avatar to the exact point where the
collision occurs (and not the default point before that) with the
‘Move to contact position’ Action.
With this Action you can move the
instance of an Object in a given
direction until a contact position with
another Object is reached.
If there already is a collision at the
current position, the instance is not
moved. Otherwise, the instance is
placed just before a collision occurs
(by default).
You can specify a new direction and
a maxim distance to move. You can
also indicate whether to consider
solid object only or all objects.
When that happens, we need the Action ‘Set the vertical speed’ to ‘0.’ That’s it. That
will stop the avatar from falling once it touches a solid object.
This will give you an Event block that looks like this:
An intellectual exercise: At first, you might think that that the avatar should only stop in this manner
when it falls down on a floor from above… but that’s not true.
We also want it to move to the contact position if it hits a floor from below (i.e., it jumps up and hits a
‘ceiling’) or smacks into a wall from the side.
We have one important caveat in our “programming logic” here, and that is that we’re working on the
assumption that the previous position is collision free. Obviously, you would expect this, but it is not
always the case.
Consider those times when a character has an animated image and its collisions are based upon a
Bounding Box that conforms to its image and not the entirety of its Sprite. This could mean that the new
image at the previous location again causes a collision! This is why we have to make sure that the Sprite
has a single “collision mask” for every picture in its animation. You’ll learn more about this in Advanced
Game Prototyping.
Tutorial by Alan Emrich.
Platform Tutorial Page 6
3. Make room.
You have the basis for the platform game. Simply design a Room (level) with some floors
and walls, constructed from instances of obj_block (the block Object).
Place an instance of the avatar in the room, and you are done. An example is illustrated
below. Try it out and check out the jumping and gravity effects. Feel free to adjust them if
you want to experiment
Tutorial by Alan Emrich.
Game Maker Tutorial: 4a – Page 7
Save it now game platform one
I am going to place my games in my the t drive so
you can check it SAVE AS Platform 1 lastlame
Copyright © 2006 by Alan Emrich. All rights reserved.