- Pac-Man Image from arcade-museum.com
Prerequisites for the tutorial
- Have completed Part 1
- 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
Objectives of the tutorial
After completing this tutorial you should be able to:
- Manage collisions
- Collect objects
- Destroy Objects
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
Adding walls to the room
At this stage, we only have Pac-Man moving around the room, and we may need to ad more objects, including walls and dots to collect. Let’s add two sprites, one for the wall and one for the dots to be collected:
- From the top menu, select: Resources > Create Sprite
- A new window should appear
- In the section labelled “Name”, type “wall_spr”
- 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 “wall”, 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 these steps to create a sprite called dot_spr based on the sprite dot.gif
At this stage, you should have two additional sprites ready to be used for new objects as illustrated on the next Figure.
We will now create a corresponding object.
Creating new objects:
- From the top menu, select: Resources > Create Object
- A new window should appear.
- In the section labelled “Name”, type “wall_obj”
- Leave the box labelled “Solid” empty (we will use this feature at a later stage for AI)
- In the section labelled “Sprite”, click on the text “<no sprite> and select “wall_spr” from the list.
- Click on the button labelled “OK”.
- Repeat these steps to create an object labelled dot_obj that is using the sprite dot_spr created previously
Adding the new objects to the room
At this stage, we have two new object with associated sprites and we want to add them to the room, so that we can create corresponding interactions with Pac-Man:
- Open the properties of the room that you have created previously by double-clicking on its name in the list located on left-hand side of the screen
- Once the room properties window is open, 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 “wall_obj”, that you have created previously..
- Once this object has been selected, you can perform a left-click anywhere in the room to add the wall_obj object to the room. Note that to make things a little bit faster, you can keep the SHIFT key pressed after left-clicking, and just drag your mouse around the screen where you want to add new objects.
Managing collision between Pac-Man and the walls
Once you have created the walls, it is now time to manage collisions and this will be done using events:
- Double-click on the Pac-Man object on the left-hand side of the screen. This should display its properties
- Click on the button labelled “Add event”
- Click on the event “Collision” and select the object “wall_obj” to specify that you want to specify actions when the pac_man_obj object collides with a wall. This should add a “wall_obj” collision event in the event window
- Click on the tab labelled “Move”
- From the “Move” section of the window, drag the top left icon (red star) 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”. By doing this, we specify that the object should not move (or stop moving) as illustrated on the next Figure:
Once this has been done, click OK and test your game to ensure that the collision is accounted for.
Adding dots to the room
So far we have managed to account for collisions with walls as Pac-Man moves around the maze. However, in the original game, Pac-Man also need to collect dots (in fact all the dots in the level) to be able to proceed to the next level. Let’s add these dots and implement a pick-up mechanism.
- Open the properties of the room that you have created previously by double-clicking on its name in the list located on left-hand side of the screen
- Once the room properties window is open, 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 dot_obj, that you have created previously..
- Once this object has been selected, you can perform a left-click anywhere in the room to add the dot_obj object to the room. Note that to make things a little bit faster, you can keep the SHIFT key pressed after left-clicking, and just drag your mouse around the screen where you want to add new objects.
Last item: collecting dots
We can specify what should happen when Pac-Man collides with them. In this particular instance, the dot should disappear (we could also increase the score by 1).
- Double-click on the Pac-Man object on the left-hand side of the screen. This should display its properties.
- Click on the button labelled “Add event”
- Click on the event “Collision” and select the object “dot_obj” to specify that you want to set actions when the pac_man_obj object collides with a dot. This should add a “dot_obj” collision event in the event window
- Click on the tab called “Main1” and drag and drop the icon “Change Sprite” to the action window, as illustrated on the next figure.
- In the new window, select the option “other” to specify that the other object involved in the collision (i.e., the dot) should be destroyed, as described on the next figure.
- Click OK and test your game
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
Congratulations, you can now move to Part3.