Learning Goals 3 min
By the end of this lesson you will be able to:
- Drive a cat sprite around the Stage using four arrow-key hat blocks.
- Build a mouse sprite that wanders the Stage on its own using if on edge, bounce.
- Score a point each time you click the mouse — your "catch" — and watch the score climb on the Stage.
Warm-Up 7 min
Last lesson, you built a falling-food catch game. Today the food doesn't fall — it runs away. You chase it with the arrow keys.
Quick-fire puzzle
Priya snapped this stack onto a mouse sprite. The mouse starts at x = -200. Predict — what does the mouse do when the green flag is clicked?
when flag clicked
forever
move (4) steps
if on edge, bounce
end
Reveal the answer
The mouse moves 4 steps to the right, again and again, until it hits the right edge of the Stage. Then if on edge, bounce flips its direction so it heads back to the left. When it hits the left edge, it flips again. The mouse paces side to side, forever — perfect "running target" behaviour for a chase game.
New Concept — arrow keys + a wandering target 15 min
A chase game needs two ingredients. One: the player controls a sprite with the keyboard. Two: the target sprite moves on its own. In Scratch, both are tiny — four arrow-key hats for the player, one short forever loop for the target.
The blocks we'll snap together
| Block | Category | What it does |
|---|---|---|
| when [right arrow v] key pressed | Events | Starts a script when the right-arrow key is pressed. There's one hat per arrow. |
| change x by (10) | Motion | Nudges the sprite 10 pixels to the right (negative number nudges left). |
| change y by (10) | Motion | Nudges the sprite 10 pixels up (negative number nudges down). |
| point in direction (90) | Motion | Faces the sprite in a chosen direction. 90 = right, -90 = left, 0 = up. |
| if on edge, bounce | Motion | If the sprite is touching the Stage edge, flip its direction. |
| when this sprite clicked | Events | Starts a script when you click the sprite — our "catch" trigger. |
| change [score v] by (1) | Variables | Adds one to the score on each catch. |
The Stage layout
The cat (player) starts at the centre. The mouse (target) starts on the left side and runs side to side. The player drives the cat onto the mouse, then clicks the mouse to catch it.
Why it matters
Arrow-key hat blocks are the simplest way to put a player inside a Scratch project. Once you can move a sprite with the keyboard, every later game — Pong, maze, platformer — is just a remix of this same idea.
Worked Example — build Cat Chase, sprite by sprite 15 min
Open Scratch. We'll build six short scripts across two sprites. None of them goes over 5 blocks — short, simple, side by side.
Step 1 — Set up the cat (the player)
Click the cat in the Sprite list. In Sprite Properties, set x = 0, y = 0, Size = 80, Direction = 90.
Step 2 — Add the mouse sprite (the target)
Click the blue cat-plus icon → "Choose a Sprite" → pick Mouse1. In Sprite Properties, set x = -150, y = -100, Size = 60, Direction = 90.
Step 3 — Make a score variable
In the Variables category, click "Make a Variable", name it score, choose "For all sprites", and tick its checkbox so it shows on the Stage.
Step 4 — Cat scripts: four arrow-key hats
Click the cat in the Sprite list. Build these four short stacks side by side in the Script Area:
when [right arrow v] key pressed
change x by (10)
point in direction (90)
when [left arrow v] key pressed
change x by (-10)
point in direction (-90)
when [up arrow v] key pressed
change y by (10)
when [down arrow v] key pressed
change y by (-10)
Step 5 — Cat script: reset the score on flag click
Still on the cat. Add one more short stack so each new game starts with score = 0:
when flag clicked
set [score v] to (0)
Step 6 — Mouse script: wander forever
Click the Mouse1 card in the Sprite list. Build:
when flag clicked
forever
move (4) steps
if on edge, bounce
end
Step 7 — Mouse script: catch on click
Still on the mouse, add a second stack:
when this sprite clicked
change [score v] by (1)
Step 8 — Click the green flag and play
Click the green flag. The mouse starts pacing. Use the arrow keys to drive the cat onto the mouse. Click the mouse — score goes up. Click the flag again to reset and play another round.
What changed: compared to the roti canai catch game, the player is now inside the action. Four small hats let you drive a sprite around the Stage in real time.
Try It Yourself — extend the project 12 min
Goal: Make the cat move faster. Change every arrow-key stack's change x by (10) or change y by (10) from 10 to 20.
when [right arrow v] key pressed
change x by (20)
point in direction (90)
Think: Doubling the step doubles the cat's speed. Easier to chase, but harder to stop on the mouse without overshooting.
Goal: Speed the mouse up over time. Change the mouse's forever loop to add a tiny wait, then bigger and bigger move steps with a counter.
when flag clicked
forever
move (4) steps
if on edge, bounce
wait (0.05) seconds
end
Think: Adding a tiny wait inside the forever lets you tune the mouse's pace by hand — try 0.02 for a hyper-mouse or 0.2 for an old-mouse.
Goal: Make the mouse jump to a new spot whenever it's clicked, so it's harder to catch twice in a row. Use a go to x: (...) y: (...) block right after the score-bump.
when this sprite clicked
change [score v] by (1)
go to x: (150) y: (-100)
Think: The mouse teleports across the Stage on every catch. (Pure random will come in L3 — for now, the fixed position keeps it predictable.)
Mini-Challenge — add a second cat 5 min
"Two-player Cat Chase"
Add a second cat sprite driven by the W A S D keys instead of arrow keys. Both cats chase the same mouse. Whoever clicks the mouse first wins the point.
It works if:
- There are now two cat sprites on the Stage — one driven by arrows, one driven by W/A/S/D.
- Each cat's arrow-key stacks use only the four hats from this lesson (using when [w v] key pressed etc for the second cat).
- Clicking the mouse bumps the same shared
scorevariable.
Reveal one valid solution
Duplicate the cat (right-click → Duplicate). Rename the copy Cat 2. Open Cat 2's scripts — each "when [right arrow v] key pressed" needs its key dropdown changed to d; "left arrow" → a; "up arrow" → w; "down arrow" → s. Move Cat 2 to a different starting x in Sprite Properties so the two cats don't overlap.
when [d v] key pressed
change x by (10)
point in direction (90)
when [a v] key pressed
change x by (-10)
point in direction (-90)
when [w v] key pressed
change y by (10)
when [s v] key pressed
change y by (-10)
Now player 1 drives with arrows and player 2 drives with W/A/S/D. Whoever clicks the mouse first scores.
Recap 2 min
Today you built a chase game. Four arrow-key hats let you drive the cat in real time. A short forever loop on the mouse made it pace side to side using if on edge, bounce. Clicking the mouse counted as a catch. Multiple short scripts on multiple sprites — same shape as last lesson, but now the player is inside the action.
- arrow-key hat block
- An Events block like when [right arrow v] key pressed that starts a script when that key is tapped.
- if on edge, bounce (block)
- A Motion block that flips the sprite's direction when it touches the Stage edge — perfect for wandering targets.
- player sprite
- A sprite whose scripts respond to keyboard or mouse input from the human playing the game.
- target sprite
- A sprite that moves on its own and is the goal — the thing the player is chasing or avoiding.
Homework 1 min
Chase the Cendol. Remix your Cat Chase project so the target is a cendol sprite (or any cup-shaped sprite from the library). Keep the four arrow-key hats on the cat. Pace the cendol up and down instead of left and right.
- Open your Cat Chase project from class.
- Replace the mouse sprite with a cup-shaped sprite, renamed Cendol.
- Change the cendol's forever loop to point upward first: add a point in direction (0) before the forever, so it paces up and down instead of left and right.
- Play five rounds. Note your best score.
- Take a screenshot of the Stage with the score watcher visible.
Bring back next class:
- A screenshot of your Cendol-Chase Stage.
- Your written answer: "What was harder to chase — the side-to-side mouse, or the up-and-down cendol? Why?"
Heads up for next class: SCR-L01-45 Two-Scene Story: Hari Raya swaps the chase game for a short animated story. You'll switch backdrops, change costumes between scenes, and write your first multi-sprite dialogue.