Create a PacMan Game in 20 minutes with Game Maker: Part 1

Pac-Man Image from arcade-museum.com

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
  • Timers
  • Changing Sprites
  • Managing Collisions
  • Managing Inheritance
  • And more…

About Game Maker

Game Maker Logo Image from appindex.com

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

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.

  1. Launch Game Maker from the shortcut located on your desktop
  2. From the top menu, select: Resources > Create Sprite
  3. A new window should appear
  4. 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.
  5. Click on the button labelled Load Sprite.
  6. 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).
  7. Open the folder labelled pacman, that you have created previously (from the zip file that was downloaded).
  8. 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.
  9. Click the button labelled OK
  10. 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.

pacmansprites

Four Sprites for Pac-Man

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.

pacman_toolbar

Shortcut to create sprites.

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

  1. From the top menu, select: Resources > Create Object
  2. A new window should appear.
  3. In the section labelled Name, type pac_man_obj
  4. Leave the box labelled Solid empty (we will use this feature at a later stage for walls)
  5. In the section labelled Sprite, click on the text <no sprite> and select pac_man_stand_spr from the list.
  6. Click on the button labelled OK.
createobj

Creating an object

Note that you can also use a shortcut to add objects, as described on the next figure:

pacman_toolbar_obj_shortcit

Shortcut to create objects

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:

  1. From the top menu, select: Resources > Create Room
  2. A new window should appear
  3. 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.

    creating_room

    Creating a room

  4. Click on the tab Settings
  5. In the section labelled Name, enter the text Level1. We, could, however,  call this room any other name.
  6. Click on the tab labelled Objects: this tab is used to add/remove objects from the scene
  7. 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.
  8. Once this object has been selected, you can perform a left-click  anywhere in the room to add the pac_man_obj object
  9. 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
  10. Press the <ESC> key on your keyboard to go back to game maker

Moving Pac-Man

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.

  1. Double click on the “pac_man_obj” object, this should open a window with the properties of this object.
  2. Click on the button Add Event located at the bottom of the window
  3. 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.
  4. 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.
  5. 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.
  6. 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 fixedAdding Movement to Pac-Man
  7. Adding movement
  8. In the new window, click on the right arrow and set the speed to 2.

    move_fixed

    Applying movement

  9. Click on the button labelled OK
  10. Repeat steps 2 to 9 to create movement to the left, up, and down.
  11. 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.

Stopping Pac-Man:

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:

  1. Double click on the pac_man_obj object, this should open a window with the properties of this object.
  2. Click on the button Add Event located at the bottom of the window
  3. 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.
  4. 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”.
  5. In the new window, click on the middle square and set the speed to 0.
  6. 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.

  1. Double click on the pac_man_obj object (left-hand window).
  2. Select the event Press <Right>.
  3. Click on the tab called Main1 and drag and drop the icon Change Sprite the action window, as illustrated on the next figure.

    change_sprite

    Changing the appearance of Pac-Man

  4. 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
changesprite_b

Selecting a new sprite

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:

all_moves

All Events and Actions

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

You can now try to complete the second part of this tutorial: Part 2

Related Articles: