- 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. Two things from it come straight into today.
- Clones: one sprite, many copies, each running
when I start as a clone. - A switch: a variable that is
0or1and stops a script running twice.
Quick-fire
The hare stays where it is all game. So what makes it feel like it is running?
Reveal the answer
Everything else moving left. A runner that never moves is the oldest trick in games, and your eyes fall for 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, as clones crossing 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 exactly 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, and the hop refuses to start while it is.
- 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). - Test it by hammering the space bar. 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 travelling, and every rock is a clone.
- Add the Rocks sprite and set its size to
50. - Give it a flag stack:
hide, then aforeverthat waits and 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 is the one that notices. 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, a sound, a broadcast, and a delete.
- On the hare, receive the message, say something, and
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. Each step works before the next one starts.
Step 1 — the ground
- New project, cat deleted, a backdrop with a flat bottom to it.
- Add your runner. Shrink it until it looks like it belongs there.
- Give it a flag stack that puts it 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 and test it again by hammering the key.
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, and stop all.
Step 5 — make it playable
- Play five runs.
- If you can never clear a rock, the hop is too small or the rock is too fast. Change one number, not both.
- If you clear every rock without looking, speed the rock up.
The hare hops but the rock goes straight through it.
The touching question is under the loop instead of inside it, so it is only asked once the rock has already gone.
The hare sinks into the hill a bit more every hop.
The two repeat numbers do not match. Up 12 and down 13 is a hole after ten hops.
Nothing appears at all.
The clone stack has no show in it, and 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 mine. Yours should not look like it.
- 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 the hop is a number I chose. Find the numbers that make YOUR obstacle clearable, and be able to say which ones you changed.
- A good hop gets over your obstacle with air to spare.
- It is not so big that you are safe for the whole run.
- 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 take it away.
- 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 a metronome. After thirty seconds a player is not watching any more, just counting. Break 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.
- Neither ever appears on top of the 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
One key, and a game that already asks something of the player.
- A hop is up by an amount, then down by the same amount.
- A switch stops a hop starting while a hop is happening.
- Obstacles come to the player. The player stays put.
- The obstacle notices the touch, and says so with a broadcast.
- Hop
- Up and down by the same amount, so the runner lands where it started.
- Switch
- A variable that is 0 or 1, used to stop a script running twice at once.
- Obstacle
- A clone that crosses the Stage and ends the run if it touches you.
- Clone factory
- The hidden sprite whose only job is making clones.
Next lesson: a score, three lives, and a game you lose slowly instead of all at once.