🎮 Phase 3 · Game Development 🔵 Intermediate MODULE 10

Maze Game

⏱️ 40 min
📖 Theory + Build
🧩 5 Quiz Questions
🎮 Full Game Build
Your progress in Phase 350%
🎯 What you'll learn: Colour detection — how to make sprites react to specific colours on the stage. This is the key technique for Maze Games, where touching a wall colour resets the player!

Colour Detection in Scratch

Scratch can detect when a sprite is touching a specific colour. This is how maze games work — the walls, the goal, and the path are all different colours. The sprite's code checks what colour it's touching and reacts!

THREE COLOURS — THREE ACTIONS
DARK GREY
Touching wall colour → go back to start!
LIGHT BLUE
Touching path colour → safe to move!
GREEN
Touching goal colour → You Win! 🎉
Simple Maze Layout
😊
Wall (bad!)
Path (safe)
Start (player)
Goal (exit!)
How to detect a specific colour
SCRATCH BLOCKS
-- The key Sensing block --
if <touching color [grey]?> then
  go to x: (-200) y: (-150)   ← reset to start position

if <touching color [green]?> then
  say [You escaped! 🎉]
  stop [all]

-- Pick the colour by clicking the colour swatch --
→ Then use the eyedropper to click the colour on the stage!
🎨
Use the Eyedropper to match colours exactly!
When you click the colour swatch in "touching color?" — select the eyedropper tool — then click directly on the wall colour on your stage. This ensures Scratch detects the exact same colour as your maze walls!

Drawing Your Maze

Your maze is drawn in the Backdrop — not on a sprite. This way it stays static while the player sprite moves around on top of it!

1
Open the Backdrop editor
Click the Stage in the bottom right → click Backdrops tab → click on "Backdrop1" to open the drawing editor.
2
Fill with the path colour
Use the Fill tool to fill the entire backdrop with a light blue or white colour — this is the safe walking area.
3
Draw the walls
Use the Rectangle tool with a dark grey colour to draw your maze walls. Make them thick enough (about 20-30px) so the player can't slip through!
4
Add the goal
In the corner of the maze, draw a bright green rectangle — this is the exit/goal. When the player sprite touches green, they win!
5
Note the start position
Look at where you want the player to start. Hover your mouse over that spot to see the X/Y coordinates — you'll need these in your code!

Coding the Player Sprite

Complete Player Sprite Code
SCRATCH BLOCKS
when 🚩 clicked
set size to (30) %           ← small enough to fit in corridors!
go to x: (-200) y: (-150)    ← starting position

forever

  -- Arrow key movement --
  if <key [right arrow] pressed?> then
    change x by (3)
  if <key [left arrow] pressed?> then
    change x by (-3)
  if <key [up arrow] pressed?> then
    change y by (3)
  if <key [down arrow] pressed?> then
    change y by (-3)

  -- Hit a wall? Reset to start! --
  if <touching color [dark grey]?> then
    go to x: (-200) y: (-150)
    play sound [pop]

  -- Reached the goal! --
  if <touching color [green]?> then
    say [Escaped! 🎉] for (3) seconds
    stop [all]
Sprite size matters!
If the sprite is too big, it will always be touching walls and can never move. Set the sprite size to 30% or less. Also shrink the sprite in the sprite properties panel to make it small before you start coding!
🧩 Knowledge Check — Lesson 10
5 questions on colour detection and maze games!
1. Where is the maze drawn in a Scratch Maze Game?
2. Which Scratch block detects if a sprite is touching a specific colour?
3. What is the best way to select the exact wall colour in the "touching color?" block?
4. Why is it important to make the player sprite small?
5. When the player touches the wall colour, what should the code do?
💪
Maze Challenge — Lesson 10
Colour detection · Intermediate Level
Challenge: Timed Maze with Multiple Levels! ⏱️

Upgrade your maze game with a timer and 2 levels!

Requirements:
1. Add a timer variable that counts down from 30 seconds
2. If time runs out → Game Over
3. When the player reaches the goal → switch to a second, harder maze backdrop
4. The second maze should be more complex with tighter corridors
5. Add a "Level 2" message when the second maze appears
💡 Show hints if you're stuck
  • Timer: set timer to 30 → forever: change timer by -1 → wait 1 second → if timer = 0 then game over
  • Level 2: when reaching green goal → switch backdrop to Maze2 → move player to level 2 start position
  • Draw Maze2 as a second backdrop in the Stage editor — same colour scheme!
  • Bonus: add a lives system — 3 lives, lose 1 each time you hit a wall
Finished this lesson?
Mark it complete to track your progress.
🏃

Lesson 10 Complete!

Colour detection mastered! Next: Quiz Game — learn to ask questions and check answers!

Module 10 of 16Phase 3 — Game Development