Session 10 — Escape the Maze
Duration: 60 min · Format: live online
Session goal: by the end, students have built a playable maze game — a player they steer with the arrow keys, walls they cannot walk through, and a goal that says "You win!" and stops the game.
Soft skill focus — Teamwork
Today's human skill: Teamwork. The fastest way to find out if a maze is fair is to let someone else try to escape it.
- Build it in class: once mazes work, pair students up to swap projects and playtest each other's maze — each gives "two stars and a wish" (two things they liked, one idea to make it better). Insist on kind, specific notes.
- Reflection (wrap-up): ask "What did playing a partner's maze teach you about your own?"
Before class — prep
- Open Scratch in a tab (signed in so you can save) and be ready to screen-share the editor.
- Paint a simple maze backdrop ahead of time: Stage → Backdrops → paint thick walls all in one bold colour (e.g. blue). Leave a clear path from a start corner to a goal corner.
- Add a small Player sprite (a ball or dot) and a Goal sprite (a star or flag) at the end of the path. Delete the cat.
- Have the diagram below open to share.
Hook
Ask the class (chat or unmute):
- "In a maze game, what stops you from just walking straight through the walls to the exit?"
Take two answers. Then reveal: "Today we build Escape the Maze. You'll steer a player with the arrow keys — but the moment you touch a wall, the game pushes you back, so the only way out is the real path. Reach the goal and it shouts 'You win!'"
Teach — The plan: backdrop, player, walls, goal
Share this diagram and point to each part as you name it:
Explain the plan — a maze game is a small pile of familiar rules:
- A backdrop with walls all painted in one colour (say blue). The colour is what our code will "feel."
- A Player sprite you steer with the arrow keys (just like the basket last week).
- A Goal sprite at the end of the path.
- Two rules we'll build on the Player:
- 1 · Walls block you —
if touching color [blue]? thenundo the move you just made, so you can't pass. - 2 · You win —
if touching [Goal]? thensay "You win!" andstop [all].
Ask: "Why must every wall be the same colour?" (Because one touching color? block can only check one colour at a time.)
Teach — The "bounce off the wall" trick
Explain: the clever idea is that a wall doesn't have to stop you — it just has to push you back. If a move lands you in a wall, we immediately take a step the opposite way, so you never actually get through. Build the "up arrow" rule live on the Player sprite while they watch.
Build this together (on the Player):
1. From Events, add when green flag clicked, then send the player to the start: go to x: (-200) y: (-150) (adjust to your start corner).
2. Add a forever loop.
3. Inside it, add if <key [up arrow] pressed?> then. Inside that put change y by (5) to step up, then another if right under it: if <touching color [blue]?> then → change y by (-5) — that second block undoes the step if we hit a wall.
Your Player script so far reads:
when green flag clicked
go to x: -200 y: -150
forever
if key [up arrow] pressed? then
change y by 5
if touching color [blue]? then
change y by -5
Press the green flag and hold up into a wall — the player presses against it but can't pass. That's the whole trick: move, then undo if we're in a wall.
⚠ Watch for the wrong colour: the
touching color?block only works if the colour in the block exactly matches your wall paint. Click the colour swatch in the block, use the eyedropper, and click right on a wall to grab the exact colour. A near-miss colour means walls do nothing.
Ask: "The up rule moves +5 then checks the wall. If we hit a wall, what block sends us back?" (change y by -5 — the opposite step.)
Activity — Build the maze game step by step
Students build the whole game. You've done the up arrow together; now they add the other three directions and the win rule. Demo each step, then let them work and circulate.
Part A — set up (do together):
- If they don't have it: Stage → Backdrops → paint a maze with thick one-colour walls and a clear path. Add a small Player sprite at the start and a Goal sprite at the end. Delete the cat.
- On the Player, build the start blocks:
when green flag clicked → go to x: -200 y: -150 → forever.
Part B — steer with all four arrows (inside the forever loop):
- Add the up rule from the Teach:
if key [up arrow] pressed? then → change y by 5 → if touching color [blue]? then → change y by -5. - Right-click that whole
ifblock and duplicate it three times. Change each copy to make down, right, and left:
The four steering rules read:
if key [up arrow] pressed? then
change y by 5
if touching color [blue]? then
change y by -5
if key [down arrow] pressed? then
change y by -5
if touching color [blue]? then
change y by 5
if key [right arrow] pressed? then
change x by 5
if touching color [blue]? then
change x by -5
if key [left arrow] pressed? then
change x by -5
if touching color [blue]? then
change x by 5
- Press the green flag and drive around — you can follow the path but the walls block you on every side.
Part C — reach the goal and win (inside the same forever loop, below the arrows):
- Still inside the
forever, add one moreif <> then. In its hexagon drop Sensing →touching [Goal]?. - Inside it, add Looks →
say [You win!] for (2) seconds, then Control →stop [all]to end the game.
The finished Player script reads:
when green flag clicked
go to x: -200 y: -150
forever
if key [up arrow] pressed? then
change y by 5
if touching color [blue]? then
change y by -5
if key [down arrow] pressed? then
change y by -5
if touching color [blue]? then
change y by 5
if key [right arrow] pressed? then
change x by 5
if touching color [blue]? then
change x by -5
if key [left arrow] pressed? then
change x by -5
if touching color [blue]? then
change x by 5
if touching [Goal]? then
say [You win!] for 2 seconds
stop all
- Press the green flag and play! Steer from the start to the goal — touch it and the game says "You win!" and stops.
- Make it yours: shrink the player (
set size to 60 %) so it fits tighter paths, paint a harder maze, or add aplay sound [Cheer]before the win message.
Circulate and ask: "Show me the block that stops you passing a wall. What colour did you eyedrop?"
Debrief: ask 2–3 students to share their screen and race their maze for the class.
Check for understanding
Ask these aloud or in the chat. Answer key (for you):
- How does a wall stop the player if
touching color?can't actually block movement? → We move, thenif touching color [wall]?we take the opposite step to undo it — so the player never ends up inside a wall. - Why must all the walls be one colour? →
touching color?checks a single colour; walls of mixed colours would let the player pass through the ones we didn't check. - Which block ends the game when you reach the goal? →
stop [all](Control), inside theif touching [Goal]?rule, after the "You win!" message.
Wrap-up + homework
- Ask one student to explain, in one sentence, the "move then undo" trick for walls.
- Homework — Design a harder maze: repaint the backdrop with a longer, twistier path (same wall colour!), and add a
say [You win!]message in your own words. Save and screenshot it for your portfolio.
Teaching notes
- Correct this misconception: "the wall pushes the player back on its own." The backdrop is just a picture — it has no code. Our
if touching color?rule does the pushing by undoing the step. If the player walks through walls, that undoifis missing or the colour is wrong. - Fast finishers (extension): add a coin sprite the player must grab first (
if touching [Coin]? then hide → change [score] by 1), or a timer that ends the game with "Too slow!" usingstop [all]. Or add a trap colour (red) that sends the player back to the start withgo to x: -200 y: -150. - Low-tech fallback: no devices? Draw a maze on paper or tape one on the floor. A child is the player and may only move along open squares; a partner is the rule who calls "wall!" and makes them step back whenever they touch a line. Reaching the goal square wins. The idea — walls are a rule, not magic — is the lesson.
Vocabulary
| Term | Meaning |
|---|---|
| Backdrop | The picture behind the sprites — here, the maze with its walls |
touching color? |
A Sensing block that is true when the sprite touches a chosen colour |
| Eyedropper | The tool that picks an exact colour from the stage for a colour block |
| Undo (a move) | Taking the opposite step (e.g. change y by -5 after +5) to cancel it |
stop [all] |
A Control block that ends every running script — used to finish the game |
Resources
- Scratch editor — where students build (free, in the browser).
- Scratch Ideas — Make It Fly / Maze starter cards — official starter cards, including maze-style movement.
- Scratch Coding Cards (PDF) — printable recipes including "touching color" wall detection.
Practice set
Extra tasks to sharpen the maze game. Work them easy → hard, at lab time or for homework. Answers follow each arrow.
1. Colour clue. Which block family holds touching color? and touching [Goal]?? → Sensing (cyan).
2. Predict. The player has change y by 5 for the up arrow but no if touching color [blue]? check after it. What happens? → The player walks straight through walls — nothing pushes it back.
3. Direction. For the right arrow you move change x by 5. If that lands you in a wall, which block undoes it? → change x by -5 (the opposite step).
4. Fix it (spot the bug). A student's walls don't stop the player, even though the touching color? blocks are there. What's the likely cause? → The colour in the block doesn't match the wall paint. Fix: click the colour swatch, use the eyedropper, and click directly on a wall.
5. Make it (build task). Add a rule so touching the goal plays a sound before the win message. → Inside if touching [Goal]? then, add Sound → play sound [Cheer] before say [You win!] for 2 seconds.
6. Two rules (harder). Write the pseudo-code for a trap rule: if the player touches red, send it back to the start. → if touching color [red]? then → go to x: -200 y: -150.
Going deeper (optional)
Optional — for a class with a working maze that wants to understand collision.
Why "move then undo" beats "check then move." We could try to look ahead before moving, but that's hard — Scratch can't easily "peek" one step forward. Moving first and undoing if we're in a wall is simpler and always correct: the player may flicker at a wall for a frame, but never gets stuck inside it. Many real games use this same "move, test, resolve" pattern every frame.
Colour collision vs sprite collision. We used two kinds of sensing today: touching color? for the walls (a painted backdrop) and touching [Goal]? for the goal (a whole sprite). Point out the choice — walls are part of the picture, so we sense the colour; the goal is its own object, so we sense the sprite. Picking the right sensing block for the right thing is a real design decision.
Common mistakes & fixes
- Mistake: The wall colour in
touching color?doesn't match the paint, so walls do nothing. → Fix: use the eyedropper in the colour swatch and click right on a wall. - Mistake: Walls are painted in several colours. → Fix: repaint every wall in one colour so a single
touching color?catches them all. - Mistake: The undo block moves the same way as the step (e.g.
+5then+5), flinging the player deeper into the wall. → Fix: the undo must be the opposite sign of the move. - Mistake: The win rule uses
stop [this script](or nothing), so the game keeps running after "You win!". → Fix: usestop [all]to end everything. - Mistake: The steering
ifblocks sit outside theforeverloop, so the player moves once or not at all. → Fix: put all four arrow rules and the goal rule inside theforever.
Next session
Session 11 — Tell an Animated Story: students switch from games to storytelling — using costumes, say, wait and broadcast to make two sprites talk, take turns and act out a scene.