Ibnovate Scratch Creators
⏱ 60 minLive session

Session 10 — Escape the Maze

Duration: 60 min · Format: live online

What you'll learn: by the end, you'll have built a playable maze game — a player you steer with the arrow keys, walls you cannot walk through, and a goal that says "You win!" and stops the game.

Soft skill focus — Teamwork

Today you'll also grow Teamwork. The fastest way to find out if a maze is fair is to let someone else try to escape it.

What you'll need


Hook

Let's think about this:

Here's the plan: 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

Look at this diagram and find each part as it's named:

A maze game: move the sprite to the goal, but if it touches a wall it cannot pass

Here's the plan — a maze game is a small pile of familiar rules:

Think about it: 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

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, you immediately take a step the opposite way, so you never actually get through. Build the "up arrow" rule on the Player sprite.

Build this (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 you 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 you're in a wall.

⚠ Watch out 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.

Think about it: the up rule moves +5 then checks the wall. If you hit a wall, which block sends you back? (change y by -5 — the opposite step.)


Activity — Build the maze game step by step

You've done the up arrow; now add the other three directions and the win rule.

Part A — set up:

  1. If you 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.
  2. 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):

  1. 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.
  2. Right-click that whole if block 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
  1. 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):

  1. Still inside the forever, add one more if <> then. In its hexagon drop Sensing → touching [Goal]?.
  2. 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
  1. Press the green flag and play! Steer from the start to the goal — touch it and the game says "You win!" and stops.
  2. Make it yours: shrink the player (set size to 60 %) so it fits tighter paths, paint a harder maze, or add a play sound [Cheer] before the win message.

As you build, find the block that stops you passing a wall. What colour did you eyedrop?


Check yourself

Try these:

  1. How does a wall stop the player if touching color? can't actually block movement? → You move, then if touching color [wall]? you take the opposite step to undo it — so the player never ends up inside a wall.
  2. 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 you didn't check.
  3. Which block ends the game when you reach the goal?stop [all] (Control), inside the if touching [Goal]? rule, after the "You win!" message.

Wrap-up


Tips & extra challenges

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

Practice set

Practise on your own with these tasks to sharpen the maze game. Work them easy → hard. 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). Your 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 when you have a working maze and want to understand collision.

Why "move then undo" beats "check then move." You could try to look ahead before moving, but that's hard — Scratch can't easily "peek" one step forward. Moving first and undoing if you'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. You used two kinds of sensing today: touching color? for the walls (a painted backdrop) and touching [Goal]? for the goal (a whole sprite). Notice the choice — walls are part of the picture, so you sense the colour; the goal is its own object, so you sense the sprite. Picking the right sensing block for the right thing is a real design decision.

Common mistakes & fixes

If it's not working, check these:

What's next

Session 11 — Tell an Animated Story: you'll switch from games to storytelling — using costumes, say, wait and broadcast to make two sprites talk, take turns and act out a scene.

Ibnovate · Build · Innovate
Type to search · Esc to close
Welcome back
Sign in to continue building.
Accounts are created by Ibnovate — ask your instructor for your login.
🔒