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.
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.
Your game must include:
| 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. |
| 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
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
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
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
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
If collision does not work, check the following:
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
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.
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.
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.
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.
Add this code to the Enemy sprite:
when green flag clicked
forever
if touching Player
broadcast Game Over
end
end
Your game must have at least one enemy that patrols the maze.
Your program should include:
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
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
when I receive Reset Level
go to x: -200 y: 150
when I receive Reset Level
show
go to x: 100 y: 80
when I receive Reset Level
show
go to x: 180 y: -100
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
The player loses if:
broadcast Game Over
The player wins if:
broadcast You Win
Example:
when I receive You Win
switch backdrop to Win Screen
say You escaped the maze! for 2 seconds
stop all
| 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 |
Submit the following:
.sb3 file