In Moving on With Game Maker – A Maze Game, we looked at a couple of ways of how to get a player character to move under keyboard control.
Now it’s time to actually put a maze game together.
Defining Your Maze
If you played (or watched) the Pacman game, you’ll be familiar with the sort of maze I’m thinking of when I talk of a maze game – a walled area, populated by treasure and monsters; the player character has to get to get the chequered flag, avoiding the monstaers and collecting as much treasure as possible.
We’ll also cover how to improve the aesthetics of the maze, to produce something like this, for example:
(The study of maze and labyrinth design is actually quite involved. For an introduction, see An Introduction to the Typology of Labyrinths and Mazes (5 points for the first person to comment about what distinguishes a maze from a labyrinth;-))
With the room selected, add wall blocks to the room to create your maze. Place an instance of the player object at a start position within the maze and a goal object at the required end point within the maze.
In some games, there is the convention of leaving gaps in the the wall of the maze that correspond to that start and goal squares (that is, the entry to, and exit from points of the maze). We shall see later how a door can be added to the exit that bars further progress until it has been opened by completing a particular task.
Play the game. with the movement style and player speed you have selected, how easy is it to navigaet through the maze and get to the goal?
If you find you can’t get the player character to line up with the grid and get through narrow gaps in the wall, or it keeps getting stuck against the ends of the walls, add a Check Grid Alignment action to the player object before changing direction.
Adding a second room
It is possible to add a large number of rooms to your game and move from one to the next as you complete the challenge offered by each room. To create a second room for your maze game, simply select the Create Room option for a second time from the Game Maker Resources menu. Draw a maze using wall objects, and add the player object where you want it to enter the room, and a goal object where you want the player to leave the room.
One of the simplest ways of implementing the move from one room to another is to specify a particular goal within the first room, such that when the player character reaches it (that is, collides with it), the action moves to the next room.
In the goal object, inspect the collision event that tests for a collision with the player character. In the Main1 actions tab, you should see a set of actions relating to Rooms. Select the Check Next action.
This is a particular sort of action known as a conditional action. The action will test the state of the game world (in this case, to see if there is another room after the current room) and if the test succeeds then the next action will be executed. If the conditional test fails (there are no further rooms, for example, as may be the case when play is in the final room) then the next but one action (if any) will be executed next.
Configure the goal so that if there is another room the player moves to it, otherwise, end the game.
Add an instance of the goal object to the first room. When the player reaches the goal, play should move on to the next room.
Play the game – when you complete the first room, does the the player move to the second room? Does the game end when the goal in the second room is reached?
Without changing any of the objects, you can add as many rooms as you like, each describing a different maze (remember to add the player character where you want it to enter the room and the goal object at the exit). You can reorder the rooms by dragging and dropping them to rearrange them within the Rooms folder in the Game Maker sidebar.
Can you make one room more difficult than another, just by the way the walls are positioned?