In this tutorial series, we will get started with Game Maker relatively fast by creating the old time classic Pac-Man. Through the creation of this game, we will get to learn a lot of the core functionality of Game Maker including:
- Moving Characters
- Create and Manage Events (e.g., Keys, Timers, Collisions, Create, etc.)
- Collecting Items
- Changing Sprites
- Managing Collisions
- Managing Inheritance
- And more…
About Game Maker
For this tutorial, we will be using Game Maker, a very powerful game engine that makes it possible to create games (essentially 2D) using drag and drop features. This software requires no programming skills, although you may, if you wish, use a built-in scripting language (GML) to harness more advanced features.
Prerequisites for the tutorial
- Be comfortable with using a mouse and a keyboard
- An interest in game development
- A computer equipped with Mac OS X or Windows XP/Vista/7
- Game Maker or Game Maker Studio installed
Length of the tutorial
This tutorial should take 5 minutes to complete (excluding installation time for Game Maker)
Objectives of the tutorial
After completing this tutorial you should be able to:
- Create sprites
- Create objects
- Create a room
- Move a character based on keyboard inputs (e.g., arrows)
- Change Sprites based on direction
Acquiring the assets for your game
- Download the assets to create your game here.
- Save the zip file on your desktop
- Unzip the folder, you should obtain a folder called ‘pacman’ that includes images
Creating your sprites
To create a moving character, we need to create an object; this object will be using a sprite that will define its appearance, and the object will then be added to a room, which is where the game takes place.
- Launch Game Maker from the shortcut located on your desktop
- From the top menu, select: Resources > Create Sprite
- A new window should appear
- In the section labelled Name, type “pac_man_left_spr”: it is often useful to give unique names to your resources, and a good practice to add _spr to sprites’ names and _obj to objects’s names.
- Click on the button labelled Load Sprite.
- In the new window labelled Open Existing File, click on the folder where you have saved the sprites downloaded previously, and display its content (e.g., Desktop).
- Open the folder labelled pacman, that you have created previously (from the zip file that was downloaded).
- Select the image labelled pacman_left, and click on the button labelled Open. This should display a preview of the animated image on the right-hand side of the sprite window in Game Maker.
- Click the button labelled OK
- Repeat steps 2 to 9 to create additional sprites for Pac-Man using the following labels and files:
- New sprite labelled pac_man_right_spr using the image pacman_right
- New sprite labelled pac_man_up_spr using the image pacman_up
- New sprite labelled pac_man_right_down_spr using the image pacman_down
- New sprite labelled pac_man_stand_spr using the image pacman_stand
At this stage, you should have five different sprites ready to be used for your character as illustrated on the next Figure.
Note that , so far we have created sprites using the menu Resources so far. However, we can also use the corresponding shortcut located on the tool bar.
We will now create a corresponding object. An object is a container that you can move around the room and which appearance is defined by a sprite. As we will see later, the appearance of your object can change overtime, based, for example, on its movement (e.g., animated character).
Creating your object
- From the top menu, select: Resources > Create Object
- A new window should appear.
- In the section labelled Name, type pac_man_obj
- Leave the box labelled Solid empty (we will use this feature at a later stage for walls)
- In the section labelled Sprite, click on the text <no sprite> and select pac_man_stand_spr from the list.
- Click on the button labelled OK.
Note that you can also use a shortcut to add objects, as described on the next figure:
Creating a room and adding the main character
At this stage, we have an object with an associate sprite and we want to add it to the room, to possibly move it with the arrow keys. First, let’s add this object:
- From the top menu, select: Resources > Create Room
- A new window should appear
- At the top of the window, enter the number 32 in both fields labelled SnapX and SnapY: this is because the sprites that we will be using in this room have a size of 32 by 32 pixels; so that they “snap” perfectly to the room tiles, we arrange the room accordingly.
- Click on the tab Settings
- In the section labelled Name, enter the text Level1. We, could, however, call this room any other name.
- Click on the tab labelled Objects: this tab is used to add/remove objects from the scene
- In the new tab, click on the empty field below the label “Object to add with the left mouse” and select the object pac_man_obj, that you have created previously. As you can see, this object is already displayed by default. As we will see later, the last object created in your project will usually appear first in this list.
- Once this object has been selected, you can perform a left-click anywhere in the room to add the pac_man_obj object
- Select Run> Run Normally from the top menu (or the green triangle from the tool bar located at the top of the GameMaker window ; this should display your first level, which, for now, just consists of a Pac-Man object
- Press the <ESC> key on your keyboard to go back to game maker
So far we have added Pac-Man to the first level; however, we need to control our character so that it can navigate through the level.
- Double click on the “pac_man_obj” object, this should open a window with the properties of this object.
- Click on the button Add Event located at the bottom of the window
- In the new window, click on the button Key Press, then on the button <Right>. This should add the event “Press <Right>” to the event window.
- At this stage, we need to associate an action to the event that we have defined. In other words, we need to tell GameMaker what should happen in the “event” that the user presses the right arrow key. What we would like, in this situation, is for Pac-Man to start moving to the right and we will select the corresponding action in Game-Maker.
- You will notice a selection of tabs to the right of the action window, one of them is labelled “Move” and contains actions related to characters’ movements.
- From the “Move” section of the window, drag the top left icon (red star) and drop it in the “Action” section, as described in the next figure; this should open a window called “Move fixed”
- Adding movement
- In the new window, click on the right arrow and set the speed to 2.
- Click on the button labelled OK
- Repeat steps 2 to 9 to create movement to the left, up, and down.
- Test your game (Run > Run Normally). You should see Pac-Man moving in all four directions as you press the left, right, up, and down arrows.
At this stage, you should have a Pac-Man moving in all four directions. However, you need to make sure that it stops when the keys are released; let’s modify our programme accordingly:
- Double click on the pac_man_obj object, this should open a window with the properties of this object.
- Click on the button Add Event located at the bottom of the window
- In the new window, click on the button Release <Any Key>. This events correspond to any key being released. So in our case, if any of right, left, up or down keys are released, this event will be triggered.
- From the “Move” section of the window, drag the top left icon (red star; same a previously) and drop it in the “Action” section; this should open a window called “Move fixed”.
- In the new window, click on the middle square and set the speed to 0.
- Close the window for this object and test your room again. You should now notice that Pac-Man stops whenever a key is released.
Last Step: Changing Pac-Man’s appearance
At this stage, Pac-Man can navigate in all four directions and stop when a key has been released; however we could improve the appearance of the game by changing the sprite representing Pac-Man depending on its direction.
- Double click on the pac_man_obj object (left-hand window).
- Select the event Press <Right>.
- Click on the tab called Main1 and drag and drop the icon Change Sprite the action window, as illustrated on the next figure.
- In the new window, click on the button to the right of the label “Sprite” and select the corresponding sprite from your the folder where you saved all the images for this tutorial, as described on the next figure
Once this is done, click OK and repeat the previous steps to add animations (sprites) for Pac-Man using the following labels and files, for the events:
- Event Press <Left>: sprite labelled pac_man_left_spr .
- Event Press <Up>: sprite labelled pac_man_up_spr.
- Event Press <Down>: sprite labelled pac_man_down_spr.
- Event Release <Any>: sprite labelled pac_man_stand.
Once this has been done the property window for your pac_man_obj object should look as follows:
The End … (for now)
That’s it. You have managed to move Pac-Man in all four directions and to stop its movement when the keys are released. You can, of course, apply these principles, to any other game object or type of game. The important principles to bear in mind here are as follows:
- Actions are performed when an event occurs
- An event is defined for a particular object
- Each object needs to be created and added to the room
- Each object can be based on sprites that need to be created accordingly
- The appearance of an object can change overtime by allocating different sprites