Learning Goals 3 min
By the end of this lesson you will be able to:
- Drive a sprite in four directions with four
when [right arrow v] key pressedscripts. - Give a sprite a life of its own with
foreverandif on edge, bounce. - Build a project where the player and the game are both moving something.
Warm-Up 7 min
Last lesson the target waited politely to be clicked. Today it does not wait. That one change is the difference between a puzzle and a chase.
Quick-fire puzzle
Nadia built this to walk her cat leftwards. It moves the right way, but the cat looks wrong. What did she leave out?
when [left arrow v] key pressed
point in direction (-90)
move (20) steps
Reveal the answer
The cat travels left but does it upside down, because direction −90 rotates the whole sprite. She left out set rotation style [left-right v], which you met in Lesson 12.
It belongs in the flag script, not in the arrow scripts, because it only needs setting once.
New Concept — the player half and the game half 15 min
Every action game has two kinds of movement in it. One kind waits for the player. The other happens whether the player is there or not. Today you build both and let them share a Stage.
Blocks reference
| Block | Category | What it does |
|---|---|---|
when [right arrow v] key pressed | Events | Runs once per press, and repeatedly if the key is held. |
set rotation style [left-right v] | Motion | Stops the sprite turning upside down. |
forever | Control | Repeats until the stop sign. Nothing can go below it. |
if on edge, bounce | Motion | Turns the sprite round when it reaches an edge. |
when this sprite clicked | Events | The catch — and the mouse is moving while you aim. |
Four hats, not one big script
It feels wasteful to build four almost-identical scripts. It is not. Each one listens for a different key, and Scratch runs whichever one matches — that is what makes the control feel instant.
Each arrow script is exactly three blocks: the hat, a point in direction, and a move. Twelve blocks in total gives you full four-way control.
Holding a key
Press and hold an arrow. After a short pause the cat keeps going, because the computer repeats a held key just like it does when you hold a letter in a text box.
That pause is why arrow-key control in Scratch always feels slightly sticky. It is not your bug, and Level 2 shows you the way around it.
Why the mouse needs forever
A mouse that moves once is not a chase. The forever loop is what turns a single move into continuous motion, and if on edge, bounce is what keeps it on the Stage.
Keep the move small. Four steps looks like running; forty steps looks like teleporting and is impossible to click.
Why it matters
Once two things move for two different reasons, you have the basic shape of every action game ever made. Everything after this is that same idea with more sprites and better rules.
Worked Example — build Cat Chase 15 min
New project. You need the Cat, the Mouse1 sprite, the Hall backdrop and a variable called caught.
Step 1 — The cat’s flag script
Select the cat. Set its starting state, including the rotation style so it never ends up upside down.
when flag clicked
set rotation style [left-right v]
set [caught v] to (0)
show variable [caught v]
go to x: (-120) y: (-80)
point in direction (90)
Step 2 — Right and left
Two scripts, three blocks each. Build the right arrow, test it, then build the left.
when [right arrow v] key pressed
point in direction (90)
move (20) steps
when [left arrow v] key pressed
point in direction (-90)
move (20) steps
Step 3 — Up and down
Same shape again. Direction 0 is up and 180 is down, and left-right rotation style keeps the cat upright for both.
when [up arrow v] key pressed
point in direction (0)
move (20) steps
when [down arrow v] key pressed
point in direction (180)
move (20) steps
Step 4 — The mouse comes alive
Select the mouse. This is the whole of its movement.
when flag clicked
set rotation style [left-right v]
go to x: (0) y: (60)
point in direction (90)
forever
move (4) steps
if on edge, bounce
end
Step 5 — Catching it
Still on the mouse. Clicking a moving target is much harder than clicking a still one, which is the entire game.
when this sprite clicked
start sound [Squeaks v]
change [caught v] by (1)
go to [random position v]
Step 6 — Tune the difficulty
Play it. If the mouse is too easy, raise the move from 4 to 6. If it is impossible, drop it to 3. Change one number, play again, decide.
This is real game design and it is done by playing, not by reasoning. Nobody gets the number right first time.
Step 7 — Give it an ending
Space ends the round. The cat announces the total, the same pattern you used last lesson.
when [space v] key pressed
stop [other scripts in sprite v]
say (caught) for (3) seconds
say [Flag to play again!] for (2) seconds
What changed: your projects used to move when you clicked. This one moves whether you touch it or not, and you have to keep up.
The full script list (your reference)
| Sprite | Hat | Job |
|---|---|---|
| Cat | when flag clicked | Reset position, direction, rotation style, score. |
| Cat | Four arrow hats | Four-way control, three blocks each. |
| Cat | when [space v] key pressed | End the round and announce the total. |
| Mouse | when flag clicked | Reset, then pace forever. |
| Mouse | when this sprite clicked | Score the catch and escape. |
Try It Yourself — three small builds 12 min
Goal: Make the cat faster than the mouse, then slower, and decide which is the better game.
when [right arrow v] key pressed
point in direction (90)
move (8) steps
Think: a cat that is too fast makes the game trivial. A cat that is too slow makes it annoying. There is a narrow band that is fun.
Goal: Make the mouse pace diagonally instead of straight across.
when flag clicked
go to x: (0) y: (0)
point in direction (45)
forever
move (4) steps
if on edge, bounce
end
Think: a diagonal path covers far more of the Stage than a straight one, so the cat has further to travel. Harder or just longer?
Mini-mission: two mice. Add a second mouse that moves differently from the first, so the player has to choose which one to chase.
It works if: both mice pace on their own, both are clickable, the fast one is worth more, and both reset properly on the flag. Keep each stack under 8 blocks.
Think: if the fast one is worth three, is it ever worth chasing the slow one? If not, change a number until it is.
Mini-Challenge — find the fun number 5 min
“Three speeds, one verdict”
Play your game three times with the mouse moving 3, then 6, then 10 steps. Same game, three different experiences.
It works if:
- You play all three speeds for the same length of time.
- You write down how many you caught at each.
- You pick one as the best and can say why in a sentence.
- Your final game uses the number you picked.
Teacher notes — why this is worth five minutes
Pupils tend to treat numbers in blocks as fixed facts rather than choices. Changing one number three times and feeling the difference is the fastest way to break that.
Expect the class to disagree about the best speed, which is the real lesson: difficulty is a decision about players, not a correct answer.
Recap 2 min
Action games have two kinds of movement: the kind the player drives with key hats, and the kind the game drives with a forever loop. Four arrow scripts of three blocks each give full control, and left-right rotation style keeps the sprite the right way up. A forever loop with if on edge, bounce gives a sprite a life of its own. And the right speed for a game is found by playing it, not by working it out.
- Player-driven movement
- Motion that only happens when the player presses something.
- Game-driven movement
- Motion that runs on its own from the flag onwards.
- Rotation style
- The setting that decides whether a sprite turns upside down.
- Tuning
- Changing a number, playing, and deciding — how difficulty is really set.
Homework 1 min
Swap the roles. Turn the chase around so the player is the one being chased.
- Keep the four arrow scripts on the cat exactly as they are.
- Change the mouse so that catching it costs a point instead of earning one.
- Add a second variable that counts how long you survived, using a key you press yourself.
- Play both versions and decide which is the better game.
Bring back next class:
- Both versions saved, clearly named.
- Your answer to: “What changed in the game when the goal became avoiding instead of catching?”
Heads up for next class: SCR-L01-45 is a build too, but a story rather than a game — a two-scene Hari Raya visit.