- Learnt27 min · a hop, a rock, and the two together
- Basic25 min · build the run
- Challenge 1–327 min · your world, a hop that clears, no cheating
- Extrabonus · a rhythm you cannot count
Review — where we got to 5 min
Space Race is finished. Today we use two things from it.
- Clones: one sprite, many copies. Each copy runs
when I start as a clone. - A switch: a variable that is
0or1. It stops a script running twice.
Quick-fire
The hare stays in one place all game. So why does it look like it is running?
Reveal the answer
Everything else moves left. Games have used this trick for a very long time. Your eyes believe it every time.
Today’s Topic 3 min
- A hop: up by an amount, then down by the same amount.
- Why a hop needs a switch, and what happens without one.
- Obstacles that come to you. They are clones that cross the Stage.
- A run that ends when something touches you.
Learning outcome
By the end of this lesson you will be able to:
- Build a hop that always lands back on the ground.
- Send obstacles across the Stage as clones.
- Say why the runner standing still is what makes it a game.
Learnt — a hop, a rock, and the two together 27 min
1 · Up, then down
A hop is two loops. One takes the hare up. The other puts it back. If the two numbers match, it lands just where it started.
- New project, cat deleted, the Hill backdrop.
- Add the Hare sprite. Set its size to
60. - Put it on the ground:
go to x: (-120) y: (-100). - Start a second stack with
when [space v] key pressed. - Inside it,
repeat (12)holdingchange y by (10), then the same again with-10. - Press the flag, click the Stage, then press space.
when [space v] key pressed
repeat (12)
change y by (10)
end
repeat (12)
change y by (-10)
end
How to use this: Click the green flag, click the stage once, then press the space bar to make the hare hop. Now press it twice quickly and watch what goes wrong.
2 · One hop at a time
The fix is the switch from Space Race. A variable called jumping is 1 while the hare is in the air. While it is 1, a new hop cannot start.
- Make a variable and call it
jumping. - On the flag stack, add
set [jumping v] to (0). - Wrap the whole hop in
if <(jumping) = (0)> then. - First line inside the if:
set [jumping v] to (1). - Last line inside the if:
set [jumping v] to (0). - Press the space bar again and again, very fast. The hare should ignore you.
when [space v] key pressed
if <(jumping) = (0)> then
set [jumping v] to (1)
repeat (12)
change y by (10)
end
repeat (12)
change y by (-10)
end
set [jumping v] to (0)
end
How to use this: Click the green flag, click the stage once, then hammer the space bar. The hare hops once and ignores the rest.
3 · The rock that comes to you
The hare never moves sideways. The rock does all the moving. Every rock is a clone.
- Add the Rocks sprite and set its size to
50. - Give it a flag stack:
hide, then aforever. The forever waits, then makes a clone. - Start a clone stack with
when I start as a clone. - Put the clone at
go to x: (240) y: (-125)and show it. - Walk it left with
repeat (60)holdingchange x by (-8). - Finish with
delete this clone.
when I start as a clone
go to x: (240) y: (-125)
show
repeat (60)
change x by (-8)
end
delete this clone
How to use this: Click the green flag and watch. Rocks arrive on their own every two seconds — nothing to press.
4 · Putting them together
The rock does the checking. It is already running a loop. So the question goes inside that loop.
- Inside the clone’s
repeat (60), addif <touching [Hare v]?> then. - Inside the if, put a sound, a broadcast and a delete.
- On the hare, receive the message. Say something, then
stop [all v]. - Play it. Clear some, miss some.
when I start as a clone
go to x: (240) y: (-125)
show
repeat (60)
change x by (-8)
if <touching [Hare v]?> then
start sound [Boing v]
broadcast [ouch v]
delete this clone
end
end
delete this clone
when I receive [ouch v]
say [Ouch!] for (2) seconds
stop [all v]
How to use this: Click the green flag, click the stage once, then press the space bar to hop the rocks. Touch one and the run ends.
Basic — build the run 25 min
Build it in this order. Make each step work before you start the next one.
Step 1 — the ground
- New project, cat deleted. Pick a backdrop with flat ground at the bottom.
- Add your runner. Make it smaller until it looks right.
- Give it a flag stack. It puts the runner on the left, on the ground.
Step 2 — the hop
- Build the two repeat loops on a space-key stack.
- Test it. It must land on the same spot it left.
- Add the jumping switch. Test it again by pressing the key very fast.
Step 3 — the rock
- Add an obstacle sprite and hide it on the flag.
- Build the clone factory: forever, wait, create clone.
- Build the clone stack: go to the right edge, show, walk left, delete.
- Watch ten of them cross before you go on.
Step 4 — the ending
- Add the touching question inside the clone’s loop.
- Broadcast a message from the rock.
- On the runner, receive it. Say something, then stop all.
Step 5 — make it playable
- Play five runs.
- Can you never clear a rock? Then the hop is too small or the rock is too fast. Change one number, not both.
- Do you clear every rock without looking? Then make the rock faster.
The hare hops but the rock goes straight through it.
The touching question is under the loop, not inside it. So it is only asked after the rock has gone.
The hare sinks into the hill a bit more every hop.
The two repeat numbers do not match. Up 12 and down 13 makes a hole after ten hops.
Nothing appears at all.
The clone stack has no show in it. The flag stack hid the sprite.
The rocks pile up along the left edge.
delete this clone is missing from the end of the clone stack.
Your runner, your road
A hare on a hill is my idea. Yours should look different.
- A different runner, in a different place.
- An obstacle that belongs in that place.
- The runner sits on the ground, not floating above it.
A hop that actually clears
Right now I chose the hop numbers. Find the numbers that get over YOUR obstacle. Say which ones you changed.
- A good hop gets over your obstacle with space to spare.
- It is not so big that you are always safe.
- You can clear five in a row.
Teacher note — one number at a time
A pupil who changes the hop height, the hop length and the rock speed at once has no idea which one helped. Make them change one, play, then change the next.
Make it impossible to cheat
There is a way to win your game without watching it. Find it. Then stop it working.
- Holding the key down must not keep the runner in the air.
- Hopping at the wrong moment must fail.
- Standing still must fail too.
Teacher note — the two cheats, and where they come from
The first is the double hop, and the switch has already fixed it. The second is subtler: a hop with a long wait at the top is safe forever. If a pupil has built one, ask them to time how long the runner is in the air.
The honest answer to this mission is often that no change is needed, and saying so with proof is worth full marks.
A rhythm nobody can count
One rock every two seconds is like a ticking clock. After thirty seconds, a player stops watching. They just count. Stop that.
How to use this: Click the green flag, click the stage once, then press the space bar to hop. The gap between rocks is never the same twice.
- Two obstacle sprites, not one.
- The gap between them changes every time.
- Both can still be cleared by a good hop.
- They never appear on top of each other.
Teacher notes — random waits, and the pile-up
wait (pick random (1) to (3)) seconds is the whole answer, and it is a block from Topic 1.9. The interesting part is what a pupil does when both rocks land on the same spot.
The usual fix is to give the two sprites different waits — one between 1 and 2, one between 2 and 4 — so they drift apart instead of marching together.
Going further: next lesson the run stops ending at the first mistake, and starts counting.
Summary 4 min
Just one key, but the player still has to think.
- A hop is up by an amount, then down by the same amount.
- A switch stops a new hop while the hare is in the air.
- Obstacles come to the player. The player stays put.
- The obstacle checks for the touch. It tells the others with a broadcast.
- Hop
- Up and down by the same amount. The runner lands where it started.
- Switch
- A variable that is 0 or 1. It stops a script running twice at once.
- Obstacle
- A clone that crosses the Stage. It ends the run if it touches you.
- Clone factory
- The hidden sprite. Its only job is making clones.
Next lesson: a score and three lives. You lose slowly, not all at once.