GameMaker Maze Game

High School Game Development Lesson
Project Skills
Maze Game Walls, Collisions, and Rooms
Grade Level: 9–12
Difficulty: Beginner
Estimated Time: 1–2 class periods
Programming: GameMaker Language (GML)

Learning Objectives

By the end of this lesson, students will be able to:

Game Goal

Create a maze game where the player uses the arrow keys to travel through a maze.

Open GameMaker and create a new project.

Name the project:

PX_lastname_MazeGame
  1. Create 2 files:
  2. file one: PX_lastname_MazeGame.png (Screen print of the program inside the game maker ide)
  3. file two: PX_lastname_MazeGame.mp4 (Video of you playing the game. I need at least 7 seconds)
  4. Be sure to drop off the two file into your google drive for class under 2026_27KleinCollins\your class name
  5. Drop your two files into google classroom.

The player must:

Part 1: Create the Project

Open GameMaker and create a new project.

Name the project:

MazeGame

Choose a GameMaker Language (GML) project.

Part 2: Create the Player Sprite

Create a new sprite and name it:

spr_player

A good starting size is:

32 x 32 pixels

Create a simple square, circle, character, robot, or other image to represent the player.

Part 3: Create the Player Object

Create a new object and name it:

obj_player

Assign the following sprite to it:

spr_player

Part 4: Add Player Movement

Add a Step Event to obj_player.

Enter the following code:

var move_speed = 4;

if (keyboard_check(vk_right))
{
    x += move_speed;
}

if (keyboard_check(vk_left))
{
    x -= move_speed;
}

if (keyboard_check(vk_up))
{
    y -= move_speed;
}

if (keyboard_check(vk_down))
{
    y += move_speed;
}

Understanding the Movement

The command keyboard_check() checks whether the player is currently holding down a keyboard key.

Code Movement
x += 4 Move Right
x -= 4 Move Left
y += 4 Move Down
y -= 4 Move Up
Show Your Teacher - Checkpoint 1

Part 5: Create a Wall Sprite

Create another sprite and name it:

spr_wall

Use a size of approximately:

32 x 32 pixels

You can make the wall look like:

Part 6: Create the Wall Object

Create a new object named:

obj_wall

Assign:

spr_wall

as the wall object's sprite.

Part 7: Add Wall Collision

The player should not be able to walk through obj_wall.

Replace the original movement code in the player's Step Event with the following:

var move_speed = 4;

var hspeed_player = 0;
var vspeed_player = 0;


// Horizontal movement

if (keyboard_check(vk_right))
{
    hspeed_player = move_speed;
}

if (keyboard_check(vk_left))
{
    hspeed_player = -move_speed;
}


// Vertical movement

if (keyboard_check(vk_down))
{
    vspeed_player = move_speed;
}

if (keyboard_check(vk_up))
{
    vspeed_player = -move_speed;
}


// Horizontal collision

if (!place_meeting(x + hspeed_player, y, obj_wall))
{
    x += hspeed_player;
}


// Vertical collision

if (!place_meeting(x, y + vspeed_player, obj_wall))
{
    y += vspeed_player;
}

Understanding place_meeting()

The GameMaker function:

place_meeting()

checks whether an object would collide with another object.

For example:

place_meeting(x + 4, y, obj_wall)

This asks GameMaker:

Would the player collide with a wall if the player moved 4 pixels to the right?

The symbol:

!

means:

NOT

Therefore:

if (!place_meeting(x + hspeed_player, y, obj_wall))

means:

If there is NOT a wall in the player's next position, allow the player to move.

Part 8: Create the Maze Room

Create a new room named:

rm_maze

A good starting room size is:

Setting Value
Width 960
Height 640

Part 9: Build the Maze

Open rm_maze and place multiple instances of obj_wall in the room.

Create:

Example Maze

XXXXXXXXXXXXXXXXXXXX XP X X XXXXXXXX XXXXXXX X X X X X XXXX XXX XXXXXXX X X X X X X X XXXXXXXXXXXXXXXX X X X XXXXXXXXXXXXXXXXXXXX

Where:

Place one instance of obj_player near the beginning of the maze.

Show Your Teacher - Checkpoint 2

Part 10: Test the Game

Run the game and use:

Test the following:

Show Your Teacher - Checkpoint 3

Demonstrate that the player can move through the maze but cannot move through the walls.

Part 11: Create a Goal

Create a new sprite named:

spr_goal

Your goal could look like:

Create a new object named:

obj_goal

Assign:

spr_goal

to the object.

Place obj_goal at the end of the maze.

Part 12: Detect the Goal

Add a Collision Event to obj_player.

Choose collision with:

obj_goal

Add:

show_message("You escaped the maze!");

When the player reaches the goal, GameMaker will display a message.

Part 13: Restart the Room

After displaying the message, restart the maze using:

show_message("You escaped the maze!");

room_restart();

Part 14: Add a Second Room

Create another room named:

rm_maze2

Create a harder maze in the second room.

Change the goal collision code in Level 1 to:

show_message("Level 1 Complete!");

room_goto(rm_maze2);

Now the player progresses from Level 1 to Level 2.

GameMaker Concept: Rooms

Rooms are the areas where GameMaker games take place.

A room could represent:

For this project:

Room Purpose
rm_maze Level 1
rm_maze2 Level 2
Show Your Teacher - Checkpoint 4

Student Challenge

Improve your Maze Game by completing

Extension Challenge: Add Coins

Create a sprite:

spr_coin

Create an object:

obj_coin

Create a Collision Event between obj_player and obj_coin.

Add:

instance_destroy(other);

Later, you can add a score variable to count how many coins the player collects.

Extension Challenge: Restart Key

Add the following code to the player's Step Event:

if (keyboard_check_pressed(ord("R")))
{
    room_restart();
}

Now the player can press R to restart the maze.

Show Your Teacher - Checkpoint 5

Demonstrate at least three improvements that you added to your Maze Game.

Vocabulary

Term Meaning
Sprite The image used to represent something in the game.
Object An item that contains game behavior and programming.
Instance A copy of an object placed inside a room.
Room The area or level where the game takes place.
Collision When two game objects touch or overlap.
Step Event An event that runs repeatedly while the game is running.
x The object's horizontal position.
y The object's vertical position.
place_meeting() Checks whether a collision would occur.
room_goto() Moves the game to another room.
room_restart() Restarts the current room.

Assessment Questions

  1. What is a GameMaker room?
  2. What is the difference between a sprite and an object?
  3. What does the x value control?
  4. What does the y value control?
  5. What does place_meeting() do?
  6. Why do we check for a collision before changing the player's position?
  7. What object is used to create the maze walls?
  8. What command restarts the current room?
  9. What command moves the game to another room?
  10. Describe one way you could make the maze more difficult.

100-Point Grading Rubric

Requirement Points
GameMaker project created correctly 5
Player sprite 5
Player object 5
Keyboard movement 15
Wall sprite 5
Wall object 5
Maze design 15
Wall collision works correctly 20
Goal object 5
Goal collision works 5
Game successfully completes, restarts, or changes rooms 5
Three student enhancements 10
Total 100