MIT Scratch Project Instructions
Maze Escape Game

In this Scratch project, you will create a maze game where the player controls a character, moves through a maze, avoids enemies, collects a key, unlocks a door, and reaches the exit before time runs out.

Project Goal

Create a Scratch game where the player moves through a maze and reaches an exit. The game must include arrow key movement, wall collision detection, a countdown timer, multiple levels, enemies, keys, doors, win conditions, and lose conditions.

Project Requirements

Your game must include:

  1. A player character that moves with the arrow keys.
  2. A maze with walls.
  3. Wall collision detection.
  4. A countdown timer.
  5. At least one key to collect.
  6. At least one locked door.
  7. At least one enemy that patrols the maze.
  8. A win condition.
  9. A lose condition.
  10. Multiple levels.

Required Challenge Features

Sprites Needed

Sprite Purpose
Player The character controlled by the user.
Maze Walls The maze background or wall sprite.
Key The item the player must collect.
Door A locked door that opens after collecting the key.
Exit The goal area the player must reach.
Enemy A patrol enemy that causes the player to lose.
Timer Display A variable that shows the time remaining.

Variables Needed

Variable Name Purpose
timer Counts down the time remaining.
level Tracks the current level.
hasKey Tracks whether the player has collected the key.
lives Optional: tracks player lives.
gameState Optional: tracks whether the game is playing, won, or lost.

For hasKey, use the following values:

0 = Player does not have the key
1 = Player has the key

Step 1: Create the Maze Background

Create a maze using one of the following options:

Use one solid wall color so collision detection is easier.

Walls = black
Path = white
Exit = green
Door = brown

Step 2: Program Player Movement

Select the Player sprite and add this starter code:

when green flag clicked
go to x: -200 y: 150
set hasKey to 0
set level to 1

Create movement using the arrow keys:

when green flag clicked
forever
    if key right arrow pressed
        change x by 3
        if touching color black
            change x by -3
        end
    end

    if key left arrow pressed
        change x by -3
        if touching color black
            change x by 3
        end
    end

    if key up arrow pressed
        change y by 3
        if touching color black
            change y by -3
        end
    end

    if key down arrow pressed
        change y by -3
        if touching color black
            change y by 3
        end
    end
end

How the Movement Works

The player moves first. Then Scratch checks if the player is touching a wall. If the player touches a wall, the movement is undone.

change x by 3
if touching wall
    change x by -3

Step 3: Add Wall Collision Detection

Use a wall color that is easy to detect. For example, if your maze walls are black, use the Scratch block:

if touching color black

Teacher Tip

If collision does not work, check the following:

Step 4: Create the Countdown Timer

Create a variable called timer.

Add this code to the Stage:

when green flag clicked
set timer to 60
forever
    wait 1 seconds
    change timer by -1
    if timer = 0
        broadcast Game Over
    end
end

Game Over Code

Add this code to the Stage:

when I receive Game Over
say Game Over! for 2 seconds
stop all

You may also create a Game Over backdrop and switch to it.

Step 5: Add the Key

Select the Key sprite. Place it somewhere inside the maze.

when green flag clicked
show
go to x: 100 y: 80

When the player touches the key:

when green flag clicked
forever
    if touching Player
        set hasKey to 1
        hide
    end
end

The key disappears when collected. The variable hasKey changes from 0 to 1.

Step 6: Add the Locked Door

Select the Door sprite. Place it in front of the exit or in a hallway.

when green flag clicked
show
go to x: 180 y: -100

Door behavior:

when green flag clicked
forever
    if touching Player
        if hasKey = 1
            hide
        else
            say You need the key! for 1 seconds
        end
    end
end

If the player has the key, the door opens. If the player does not have the key, the door stays locked.

Step 7: Add Enemy Patrols

Create an Enemy sprite and place the enemy inside the maze.

Example enemy movement:

when green flag clicked
go to x: -50 y: 50
forever
    glide 2 seconds to x: 50 y: 50
    glide 2 seconds to x: -50 y: 50
end

This creates a simple side-to-side patrol.

Enemy Touching Player

Add this code to the Enemy sprite:

when green flag clicked
forever
    if touching Player
        broadcast Game Over
    end
end

Required Enemy Challenge

Your game must have at least one enemy that patrols the maze.

Your program should include:

Step 8: Create the Exit

Create an Exit sprite or use a green area on the maze.

when green flag clicked
show
go to x: 220 y: -150

Win condition:

when green flag clicked
forever
    if touching Player
        if hasKey = 1
            broadcast Next Level
        else
            say Find the key first! for 1 seconds
        end
    end
end

Step 9: Add Multiple Levels

Create at least two maze backdrops:

Level 1
Level 2
Win Screen
Game Over Screen

On the Stage:

when green flag clicked
set level to 1
switch backdrop to Level 1

When the player reaches the exit:

when I receive Next Level
change level by 1

if level = 2
    switch backdrop to Level 2
    set hasKey to 0
    set timer to 60
    broadcast Reset Level
else
    switch backdrop to Win Screen
    say You Win! for 2 seconds
    stop all
end

Step 10: Reset Sprites for Each Level

Player Reset

when I receive Reset Level
go to x: -200 y: 150

Key Reset

when I receive Reset Level
show
go to x: 100 y: 80

Door Reset

when I receive Reset Level
show
go to x: 180 y: -100

Enemy Reset

when I receive Reset Level
go to x: -50 y: 50

For Level 2, you may choose different positions.

when I receive Reset Level
if level = 1
    go to x: -50 y: 50
end

if level = 2
    go to x: 80 y: -40
end

Step 11: Add Win and Lose Conditions

Lose Conditions

The player loses if:

  1. The timer reaches zero.
  2. The player touches an enemy.
broadcast Game Over

Win Condition

The player wins if:

  1. The player collects the key.
  2. The player unlocks the door.
  3. The player reaches the exit.
  4. The player completes all levels.
broadcast You Win

Example:

when I receive You Win
switch backdrop to Win Screen
say You escaped the maze! for 2 seconds
stop all

Required Student Checklist

Optional Extra Challenges

  1. Add background music.
  2. Add sound effects for collecting the key.
  3. Add a sound effect when hitting an enemy.
  4. Add more enemies.
  5. Add more levels.
  6. Add different keys for different doors.
  7. Add a lives system.
  8. Add a high score system.
  9. Add moving walls.
  10. Add a secret shortcut.

Grading Rubric

Category Points
Player moves with arrow keys 10
Maze has working wall collision 15
Countdown timer works 10
Key can be collected 10
Door requires key to open 10
Enemy patrols the maze 15
Touching enemy causes game over 10
Multiple levels included 10
Win and lose conditions work 10
Total 100

Submission Requirements

Submit the following:

  1. Scratch project link or .sb3 file
  2. Screenshot of your game
  3. Short explanation of how your game works
  4. Video demonstration showing:
    • Player movement
    • Wall collision
    • Key collection
    • Door opening
    • Enemy patrol
    • Timer
    • Win or lose condition