Make Your Own Maze Game with Game Maker

This is a tutorial which will guide you through the process of building your own maze game using the software Game Maker. Building games is a very rewarding pastime, and even more so building your first ever game. Due to Game Maker’s ease of use you don’t need any programming skill at all just the drive to try and create something unique. While one person working on their own can never build a game which will rival the million dollar budgets of big development houses in terms of graphics, there is nothing to stop us creating unique, highly playable games.

To start our game we first start to design (or perhaps find on the Internet) the graphics that we’ll be using for the game. To start with our needs are very simple, we just need a few sprites to get us started. Many sprites and tilesets can be found on the internet. Firstly we’ll need a stone block, then we’ll need a stone tile so we can build our first level. Then we’ll need something to collect. Lastly and most importantly we’ll need a character to move around the level. Right click and select ’save image as’ for each of them if you want to use these sprites in your game:

Once you have these sprites to hand, fire up Game Maker and have a look around. At first the interface can seem quite daunting, there are a ton of options. Thankfully it doesn’t take long to get used to the interface. If ever you get stuck and need some help with Game Maker, press F1 to bring up the Help file (which in itself is quite extensive).

In the left hand side bar right click on the ’sprites’ folder and select ‘add sprite’ from the menu which will bring up the add sprite screen. You will then be able to click on the ‘Load sprite’ button to select one of the sprites you created (or found) earlier. At the moment we are going to use a grid of sprites that are all 32×32 pixels in size. So our room is going to be composed of tiles that size. Ideally your character should also be 32×32. The one I’m using here is a bit taller than 32pixels tall, which is why I’ve selected the origin of the character to start 17 pixels down, and also manually set the bounding box to be within a 32×32 square. It might help you to start with it you settle for a character that is 32×32 then you can go with the default settings.

Notice that the ‘Transparent’ box is ticked. This feature of Game Maker takes the color from the bottom left (or was it right? I can never remember…) corner of the sprite and uses that as a transparent color. In this case, everything in bright neon green will become transparent. Notice we ticked, precise collision checking; this is processor intensive but that won’t matter for this small game. In more elaborate games, it’s best to untick this box wherever you can get away with it (when unticked Game Maker just uses the bounding box to check for collisions, more on collisions later). Finally we have ’smooth edges’ ticked,which will blur the edges making the sprite look better in the room and ‘Preload texture’ ticked ensuring that the sprite will be loaded before it is needed. If you use a 32×32pixel character for now then the origin will be x:0 and y:0 while bounding box can be left at automatic. Otherwise the bounding box will have to be within a 32×32 pixel square or else your character will get stuck in walls. Notice that we called the sprite ’sp_character’. The prefix is used so that we can tell the difference between different game elements. You’ll find out why soon. Press the ‘Ok’ button to continue.

Now add the other sprites. The block has different settings from the character sprite. It’s still transparent because it doesn’t fill the 32×32pixel area (although if you do have a block that fills the whole square then be sure to untick ‘transparent’) but in this case we have unticked precise collision checking since there are going to be a lot of these sprites, and we don’t need precision anyway since the bounding box is a close enough approximation of the block’s shape. Note that we called it ’sp_block’. As with before it is also preloaded.

We repeat the same process by adding the gem. Again we don’t need precise collision checking, because the character is only going to be bumping against it and picking it up. (advanced collision checking is more useful in games such as shoot-em-ups where you only want to die if you really are touched by the object).

At this juncture it’s probably a good idea to save your game if you haven’t already done so. Go to the file menu and select ’save as’ then give your game an appropriate name. This means if anything happens you can reload.

So now we should have a character a block and a gem in our sprites section. Now it’s time to add the floor tile. Three folders down from the sprites folder is the ‘backgrounds’ folder. Right click on this and the ‘Background Properties’ window will pop up. Load your floor tile into this as if it was a sprite and call it ‘bg_tile’. Note that the prefix is different because it’s a background. This naming convention is not needed by game maker, but comes in handy to keep things organized. The background properties allows you to load in background images and tile sets. Tile sets are an extremely powerful way of managing game graphics. All the sprites you need (to build the room) can be loaded into one sheet, and then loaded into game maker and used to create the level by layering them into a design. For now we’ll have to be content with one floor tile for the background.

Now five folders down from the ‘backgrounds’ folder is a folder called ‘objects’. Right click on this now and select add object. There isn’t much to do yet. Just call him ‘obj_character’ and note now that we have a ’sp_character’ (which is the sprite) and ‘obj_character’ (which is an object). Objects in game maker are the things you can control the behavior of. By adjusting their behavior you create the rules by which the game is played. For now there is nothing to do except select the sprite you want for ‘obj_character’ which should be ’sp_character’. Then do the same for each of your sprites (create an object and select its sprite).

You should now have 3 sprites, a background tile, and 3 objects (with their sprites set to the appropriate object). Now it’s time to add a room. The folder below the ‘Objects’ folder is called ‘Rooms’. Right click on ‘Rooms’ and select ‘add room’ from the drop down menu. The room window will now open.

Change ’snap x’ and ’snap y’ both to 32. This means that your objects will snap to a grid of 32×32pixels and keeps things tidy (indeed it keeps the game working correctly). Notice that in the left hand bar we are in the objects tab, and that one of the objects you added earlier is selected in the drop down box. You can pick different objects and add them to the room using the left mouse button, and you can delete them using the right mouse button. Play about with this and then delete everything (because we’ll be adding the floor tiles first). Click the tiles tab in that side-bar. Now paint in your floor tiles. Holding down shift lets you paint in multiple tiles as you move your mouse around.

Once you’ve added your floor tiles, go back to the objects tab and start adding in some walls. You can turn the grid on and off by clicking on the button (with a little grid in it) beside ’snap x’ and ’snap y’. Now paint in your walls, making a loose maze configuration, add some gems, and your character. None of them will be able to do anything yet, but you can see how the first level is going to look. In the settings tab in the side bar you can set a caption for the room. The caption will appear in the window’s titlebar when you run the game. For now we’re happy with the room we’ve created, it’s time to program in some actions so our little character can run about the level and collect gems.

Double click on ‘obj_character’ and the object properties window opens. We want to give our character a keyboard event so that when the player presses the left key our character walks right, and so fourth through the different keys. Click the ‘Add Event’ button and from the event selector choose ‘Keyboard’ then < left >. Now we drag and drop actions into the actions box. Under the ‘control’ tab find the ‘If the instance is aligned with a grid’ icon:

Once you’ve located it, drag it into the actions box. It will then pop up with an options box. Choose ’snap hor:’ 32 and ’snap vert:’ 32 then click OK. This means to the program: If the instance is aligned with a grid 32 by 32 then perform the following action. Now all we have to do is add that action. Click on the ‘move’ tab and find the red (top left) icon ‘Start moving in a direction’ and click and drag it into the action’s box below the first icon. It will pop up with its properties box. The top radio button should already be set to ‘Applies to: Self’ so leave that alone then select the left arrow for ‘Directions’ and set the speed to 4. The relative checkbox should be left unchecked.

Now repeat the process, assigning the keyboard keys to each of the three remaining directions, right, up, and down. All will be set in the exact same way with exception to the arrow you click on in the ‘Start moving in a direction’ in the properties box.

Once you’ve done all four you might think that’s your character ready to roll, but not yet, we need a 5th key event. At the moment the character will just keep going in whatever direction you press without stopping, therefor we need to click ‘Add Event’ select Keyboard, and select ‘No Key’ from near the bottom of the list. Now in the ‘Start moving in a direction’ properties box, this time select speed: 0. And instead of clicking on an arrow direction click the square in the center. Press OK.

Now your character will move (as long as he is aligned with the grid) whenever you press a direction key, and stop when no key is pressed. Now is an ideal place to save your game. Now you can press the green play button to try out the game. Once it loads you’ll see you’re able to move your character about. But it’s not a very good game yet, since you can’t interact with anything. Close your game by clicking the close button in the top right or by pressing escape, and go back to the Game Maker window. It’s time to add some interaction.

Double click on ‘obj_character’ to bring up his properties window again, and this time add a new event ‘Collision’ and select ‘obj_block’. Now in the events box, stop him moving (use the same ‘Start moving in a direction’ icon and set it to the same preferences as in the No Key event) and snap him to the grid (32×32). So in English this means: when your character collides with a block, he stops and is snapped onto the grid. Snapping him onto the grid is an important step, otherwise he might end up stuck off the grid (and our movement is set up so that he can only move when he is correctly on the grid). We don’t want him to get stuck inside a wall.

At this juncture it’s probably a good moment to save your game and then click the green play button so you can see your character interacting with the walls. As an aside: I found when I did this that my character was bouncing about when I tried to walk into walls to the right of me. I fixed this by going back to my sp_character properties and unticking ‘precise collision checking’.

Now close your game and go back to the Game Maker screen. It’s time to add a points system and make gems collectible. Open up ‘obj_character’ properties again and create a new event. This time select the ‘Create’ event. This event is activated when the object is first created (ie. at the beginning of the game in this case). Under the ‘Control’ tab drag and drop the VAR (’Set the value of a variable) icon into actions box. For the Variable enter: ‘var_gems_collected’ and for the value enter: 0 (zero). Leave the ‘Relative’ checkbox unticked.

A variable is like a box that stores information. In this case we created a variable called ‘var_gems_collected’ and we will use this variable to store a count of the number of gems collected. By putting this in the create event we are initializing the variable at zero.

Next in the ‘create’ event we want to add another action, this time go to the ‘Score’ tab and drag ‘Set the Score’ into the actions box. Set the score to zero as well. So we have initialized both to zero at the beginning of the game. You could also add the lives to initialize that as well while we are here. Except in the case of lives you may want to initialize it to 3 or more.

Now (still in your ‘obj_character’ properties) add a new event. This time add a collision with ‘obj_gem’. Then drag the following actions into the actions box: (from the score tab) ‘Set the score’ and set it to 20 then make sure the relative checkbox is ticked. The relative checkbox means that it will take the existing score and add 20 to it. Then from the ‘Control’ tab select VAR and drag and drop it into the actions window. Type in ‘var_gems_collected’ and for the value put in 1 then tick the ‘Relative’ checkbox. This means that every time you collect a gem the count will go up by 1. Finally under the main1 tab drag the ‘Destroy the instance’ icon into the ‘actions’ box and select ‘applies to: other’ which means that the gem will be destroyed (ie picked up) when the character moves over it.

Now save and try out your game!

Now it’s time to add some more spites and some sounds. Firstly we’ll be needing some kind of goal to try and reach through the maze. Upon reaching the goal we’ll be taken to the next level. Secondly let’s add a bonus object that we need to collect to progress to the next level. Thirdly lets add a switch and some dynamite that let’s us blast through rocks. We’ll also be wanting some kind of ping sound for when we pick up the gems. Lastly some music would be nice.

Here is a flag, a rare coin (we need to collect them all to proceed), a block (to stop us getting to the exit before we’ve collected the rare coin), a bomb and a detonator. Again feel free to use these sprites. I’ve also acquired a sound in wav format (ping.wav) and music in midi format (music.mid). Music and sound effects can be found all over the Internet:

Add these sprites same as we did with the original three. Then add the music and then add the sound effect. I’ll not go into these steps in detail because we should be well versed at adding sprites. Adding sounds is the same as adding sprite except you’ll encounter a new window. Call the sound effect ’snd_ping’ and call the music ’snd_music1′. For ’snd_ping’ set the kind to ‘normal sound’ and try out the effects if you like. For ’snd_music1′ set the kind to ‘Background music’.

Now the fun part is adding the sound effect to our game. Open up the obj_character properties and the Collision with the gem event we created earlier. Click on the main tab and drag and drop the ‘Play a sound’ icon into the actions box. Place it before we change the score and select ’snd_ping’ as the sound to play. Set loop to ‘false’. Press OK. Now when you collect gems the game will make a satisfying little ping.

Time to add some background music. To do this, it’s best to add a controller object to the game. The controller will deal with all the background stuff. Right click on the ‘Objects’ folder and select ‘add object’ calling it ‘obj_controller’. It doesn’t have a sprite associated with it and will be invisible in the game. Next add it somewhere inside the room. It will appear as a little question mark in the level editor. Now open up the properties for ‘obj_controller’ and in the create event, (in the main1 tab) drag and drop the ‘Play a sound’ action into the actions box. Set the sound to be snd_music1 and tick the ‘loop’ checkbox. Now might be a good time to try the game. You might find you have to adjust the volume of each sound in the sound’s properties box, for example if the music is drowning out the sound effects.

Now that that is done it’s time to make a flag object. Create a new object and call it ‘obj_flag’. Give it the flag sprite. Click on ‘Add Event’ and select ‘Collision’ (with obj_character) then in the main1 tab drag and drop the action ‘If the next room exists’ then the ‘go to next room’ action. Select the transition you would like in the pop up dialog. This means that when the character touches the flag, the game will check to see if there is a next room to go to, and if so it will go to it.

Time to make a new room. Add a room and add all your walls diamonds and a flag to it. Remember to add your character at whatever position you want him to start off in. Don’t forget to add the ‘obj_controller’ to room2. Then go back to your first room and add a flag to that one. Save your game and run the game. You should be able to walk through the first level to the flag then the game will take you to level 2.

Time to add a precious object to the game and then a block that will only disappear once the precious object has been collected. Add the following objects: ‘obj_rarecoin’ and ‘obj_blocker’ giving them the appropriate sprites. Set the obj_blocker’s parent object as being obj_block. This means that the obj_blocker will function just like the other blocks we have.

Now open up obj_character’s properties and in the ‘Create’ event add another VAR and this time this time calling the variable ‘var_rare_collected’ and initializing it at zero, just like we did with the gems variable. This will count the number of rare coins we have collected. It will become useful later. Now click on the ‘Add Event’ button and create a collision with obj_rarecoin event. This will be similar to the gem collision event; we play a sound (ping though you can change it to something more impressive if you want) set the score relative to 200, and increment the ‘var_rare_collected’ variable by one, before finally destroying the other instance. Now we only need to make a minor modification to the obj_blocker in order to make it disappear when the rare coin has been collected. Open up the obj_blocker properties and click on ‘Add Event’. Select step, then (under the control tab) drag the action ‘If the number of instances is a value’ into the action box. In the properties box that presents itself, select the ‘object’ as being ‘obj_rarecoin’, set the ‘number’ to 0 (zero) and ‘operation’ as ‘Equal to’.

Now go back through the levels you’ve created and add blockers that will stop the player going directly to the flag. Then add a Rare Coin somewhere in the level (as long as the place is still accessible to the player ie not behind the blockers). Save your game, and then hit the green play button again to see how it’s shaping up. Your game has come a long way!

You might also notice before they get collected that the character is beneath certain objects, such as the coins and gems. The level at which every object sits can be controlled in its properties window. Since obj_character is sitting at 0 (zero) depth, give other objects such as coins, blocks, and gems an increased depth of 100. Conversely if there is ever anything you want to give the appearance of being above the character you can set a negative depth such as -100 to raise it above other objects. There appears to be no limit to the numbers you can use for depths (it goes ten digits both ways). You can use a variety of depths to achieve some powerful effects.

Now that the blocker is working, lets add a bomb. Earlier I forgot that I would need an explosion. Since I don’t have one to hand I photoshopped this rudimentary explosion and saved the sequence as 8 or so individual gif files. I then used a fantastic little freeware application called ‘UnFREEz 2.1′ by WhitSoft Development ( http://www.whitsoftdev.com/ ) to turn the separate gif files into one single animated gif. Again feel free to save this and use it:

Time to add a new sprite. Load the animated explosion into Game Maker as ’sp_boom’. Set it as transparent, turn off precise collision checking, tick the ‘Smooth Edges’ check box, and preload texture. Assuming you’re using the 96×96pixel explosion gif I’ve provided you with set the origin as being x:33 and y:33 (the middle of the explosion will sit over the grenade tile). Notice where it says ’show’ in the left of that box, you can scroll through the different images in the sequence. Okay that.

Now make an object, ‘obj_boom’ and in its ‘Create’ event. In the actions under the ‘main1′ tab, drag the ‘Change the sprite’ action into the actions box. In the dialog that presents itself set the ’sprite’ to ’sp_boom’ and set the ’subimage’ to ‘0′ (zero) then set the ’speed’ to ‘1′. This means that the explosion will start at frame 0 and cycle through the animation.

Now ‘Add Event’ select ‘other’ and from the drop down list select ‘Animation End’. In the actions for this event drag the ‘Destroy the instance’ event and set it to ’self’. One final event. ‘Add Event’ and select ‘Collision’ with ‘obj_block’ and in the actions box put ‘Destroy the instance’ and set it to other. So when the explosion comes into contact with blocks it should destroy them.

Now create the ‘obj_bomb’. Give it the appropriate icon and add a new event ‘Alarm 0′. In the ‘Alarm 0′ event drag the ‘Create an instance of an object’ action into the actions box. Set the object as ‘obj_boom’ (the explosion) and the x and y to ‘0′ (zero) then make sure relative is ticked. Next use the destroy the object (self) to destroy the bomb (having now released the explosion). Okay so now we have a bomb that goes off when its ‘Alarm0′ is triggered. Time to create the detonator.

Create ‘obj_trigger’ and give it the appropriate sprite. Next create a collision event with ‘obj_character’ and then under the actions ‘Set alarm 0 to 2′ and in the box above where it says ‘applies to’ select ‘object:’ and from the drop down list choose ‘obj_bomb’. This means when the player touches the trigger a collision event is called which sets ‘alarm0′ to 2 in ‘obj_bomb’ in two steps time the bomb will go!

Now create a third room within which to try out your new toys. Notice in the screenshot here the Rare Coin is needed to open up the route to the finish flag, but this is behind some blocks. The bomb is situated nearby so that the player can blow up the blocks and reach the coin, opening up the route to the exit.

Congratulations, you’ve got a pretty good number of elements. Now it’s time to expand on that. With the puzzle elements all ready, now would be a good time to put in some monsters. Get your monster sprite ready. Add it as a sprite. Here’s one so you don’t have to go hunting:

Then create an object for the monster. In the monster’s ‘Create’ event set it to move left or right using the ‘Start moving in a direction’ action. When the dialog pops up, choose both the left and right arrows, which means your monster will walk either left or right. Next ‘Add Event’ and select collision with obj_block, then in actions choose the ‘Snap to a grid’ and select 32×32. Next add the ‘Start moving in a direction’ action once again and set it for left and right.

Finally open up your character’s Object Properties and click ‘Add Event’ choose ‘Collision’ then select ‘obj_monster’ and in actions, do the following (you should by now have some idea how to do this):

Set the score relative -200

Set the lives relative -1

Restart the current room

This means that 200 will be deducted from the score and 1 will be deducted from your lives. Then the room will be restarted.

Now open up the Object properties for ‘obj_controller’ click on ‘Add Event’ then select ‘Other’ then select ‘No more lives’ and then add the following events.

Show the high score table

Restart the game

Earlier on we set the score and the lives in the ‘create’ event of the character. Cut both of those actions and put them in the create event of the ‘obj_controller’ instead, then set the ‘obj_controller’ as being persistent. This means that when the room is reset after being killed the obj_controller wont be effected

So now you know how to create monsters, you might want to create monsters that go up and down, as well as left and right. You might also want to create monsters that move about in interesting sequences. Anything is possible.

I guess we are done with this tutorial. Whatever improvements you want to make to your game are up to you. You might want to animate your character so that he actually walks. You might then want to add more puzzles such as blocks that can be pushed around, holes in the ground, extra monsters. The possibilities are limitless. The only thing holding you back is your imagination. I hope you’ve enjoyed this tutorial and good luck with your Game Making!

8
Liked it

6 Comments

  1. Gurtaton
    Posted September 30, 2008 at 5:32 am

    This is the longest article I ever read….

  2. rusty
    Posted February 28, 2009 at 2:17 am

    It is way to long but it was worth it.

  3. Will Wright
    Posted March 1, 2009 at 2:29 pm

    Awesome article, but it took me ages to get through it!

  4. joshuacw
    Posted April 4, 2009 at 1:53 am

    it is so long but so good!

  5. Abbie x
    Posted October 2, 2009 at 9:07 am

    Omg i didnt even read it

    it was so long haha

    also do you lot not get that if you go through all the trouble to working this out like downloading it and stuff then it will mess up your computers.

    so dont bother messing up your really nice computers when you can just do it on paper.

    also you will save you electrisity bills.
    if you do use this you will be wasting your money. you dont want to do that.

    this is just a simple campaign :)

    you wont here no more from me.

    Bye Abbie x

  6. your mum
    Posted October 21, 2009 at 9:51 pm

    How do you get the monster, by using the same sprite to go up and down.

Leave a Reply