Platform Tutorial Page 1

PlatformGame

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 puzzle-solving 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:

  • Creating natural motion for the avatar.
  • Creating variations in monsters, backgrounds, and so forth.
  • Designing levels that are fun and increasingly challenging.
  1. Starting with the very basics
    two basic Objects

1 controls player

2block Object that is used for the floor and which ‘platforms’ that the avatar can walk on -cannot pass through as well.

  1. 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,

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.
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:
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> Eventand 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.

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:


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:

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:

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:

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.

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 1

Copyright © 2006 by Alan Emrich. All rights reserved.

Game Maker Tutorial: 4a – Page 1

Save it now game platform one

Copyright © 2006 by Alan Emrich. All rights reserved.