- Learnt28 min · a jump is a number, and only from the ground
- Basic24 min · walk and jump
- Challenge 1–327 min · jump power, the double jump, how far
- Extrabonus · the trampoline
Review — falling 5 min
y velocityis the speed upwards; gravity takes 1 off it every tick.- A landing overshoots, so
landpushes back out and sets the speed to 0. - The push-out runs without screen refresh, so you never see it.
Quick-fire
Pico is standing still on the grass. What is its y velocity? And what would happen on the next few ticks if something set it to 12?
Reveal the answer
It is 0. Set it to 12 and Pico moves up 11, then 10, then 9… slows to a stop, and falls back — gravity turns it round without being asked. That is a jump, and you have already written all of it except one block.
Today’s Topic 3 min
- A jump is
set [y velocity v] to (12) - The
on groundvariable — jumping only from something solid - Jump power, jump height and air time
- A double jump, and why it needs a hat block
Learning outcome
By the end of this lesson you will be able to:
- Make Pico jump with one block.
- Stop it jumping again in mid-air.
- Predict how high and how far a jump will go.
Learnt — the jump 28 min
1 · A jump is one block
Keep last lesson’s loop exactly as it is. To jump, set the speed to a positive number — that is all:
when flag clicked
forever
change [y velocity v] by (-1)
change y by (y velocity)
land :: custom
end
when [space v] key pressed
set [y velocity v] to (12)
set block every 1.2 seconds for you.How to use this: Click the green flag. Pico jumps three times on its own; watch the highest monitor.
2 · The flying bug
A game checks its keys inside the loop, so the jump moves in there too. Now try pressing space again while Pico is still in the air:
if <key (space v) pressed?> then
set [y velocity v] to (12)
end
How to use this: Click the green flag. Six presses, a third of a second apart — watch Pico climb out of the top.
3 · Only from the ground
Pico may jump only when it is standing on something. The land block already knows when that is — it is the moment it pushes Pico out of the grass. So land gets one more job: keeping a variable called on ground.
define land
set [on ground v] to (0)
if <touching color [#3FA34D]?> then
repeat until <not <touching color [#3FA34D]?>>
change y by (1)
end
set [y velocity v] to (0)
set [on ground v] to (1)
end
on ground is cleared every tick and set only by a real landing.
if <<key (space v) pressed?> and <(on ground) = (1)>> then
set [y velocity v] to (12)
end
How to use this: Click the green flag. The same six presses — count how many turn into jumps.
Basic — walk and jump 24 min
Open your meadow from last lesson. Pico already falls and walks; today it jumps.
Step 1 — the new variable
- Make a variable called
on ground. - Tick its box so you can watch it on the Stage while you test.
Step 2 — land keeps track
- Find the
landdefine hat you made last lesson — do not make a new block — and addset [on ground v] to (0)at the very top. - Inside the
if, after the speed is set to 0, addset [on ground v] to (1). - Run it. The monitor should read 1 while Pico stands and 0 while it falls.
Step 3 — the jump
- At the end of the forever loop, add
if <<key (space v) pressed?> and <(on ground) = (1)>> then. - Inside it:
set [y velocity v] to (12).
Step 4 — try to break it
- Hold space down. Pico should bounce along, never flying.
- Tap space in mid-air. Nothing should happen.
- Walk off the ledge and tap space while falling. Nothing should happen then either.
- Try to jump onto the ledge from the ground. You cannot — that is Challenge 1’s question.
when flag clicked
set rotation style [left-right v]
go to x: (-150) y: (-94)
set [y velocity v] to (0)
forever
if <key (right arrow v) pressed?> then
point in direction (90)
change x by (4)
end
if <key (left arrow v) pressed?> then
point in direction (-90)
change x by (-4)
end
change [y velocity v] by (-1)
change y by (y velocity)
land :: custom
if <<key (space v) pressed?> and <(on ground) = (1)>> then
set [y velocity v] to (12)
end
end
land from Learnt part 3.How to use this: Click the green flag. Walk with the arrows and jump with space. Try jumping in mid-air — you cannot.
Pico jumps once and then never again.
on ground is never set back to 1 — the set … to (1) is missing from inside the if in land.
Holding space still makes Pico fly.
The and is missing, or the jump is still under a when [space v] key pressed hat that does not ask about the ground. Delete the old hat.
Pico never jumps at all.
Look at the monitor while Pico stands still. If it says 0, set [on ground] to (0) is after the if instead of before it, so it always has the last word.
The jump is tiny, or enormous.
That is the number in the set block. Challenge 1 measures exactly what each number does.
Jump power
Three Picos jump at the same moment with powers of 8, 12 and 16.
- Each one records the highest point it reaches.
- Show how far each one rose above the ground.
- Guess the three numbers first.
How to use this: Click the green flag. All three jump together; read the three rise monitors.
Teacher note
The rise for a power p is (p − 1) + (p − 2) + … + 1: a triangle number. That is why it grows so quickly — 16 does not rise twice as far as 8, it rises more than four times as far. A power of 18 rises 153, which clears the ledge; pupils who find that by trying have done the Extra’s maths without noticing.
The double jump
Let Pico jump once more in mid-air — once, not for ever.
- A variable
jumps left, set back to 2 by every landing. - Each jump spends one, and a jump needs one to spend.
- A third press in the air does nothing until Pico lands again.
How to use this: Click the green flag. Three quick presses — watch jumps left run out. Then press space yourself.
Teacher reveal — why this one needs a hat block
when [space v] key pressed
jump :: custom
define jump
if <(jumps left) > (0)> then
set [y velocity v] to (12)
change [jumps left v] by (-1)
end
Inside the forever loop, a key that is held counts as pressed on every tick — so one press spends both jumps in two ticks and the double jump feels like a single tall one. when [space v] key pressed runs once per press, which is what a double jump needs. And land sets jumps left to 2 inside its if, so only a real landing refills it.
How far can Pico jump?
A running jump from the same spot, three times: walking at 2, then 4, then 6 pixels a tick.
- Measure from where Pico takes off to where it lands.
- Show all three lengths.
- Work out the rule that connects the speed and the length.
How to use this: Click the green flag and watch three running jumps from the same spot.
Teacher note
The air time does not depend on the walking speed at all — it is 24 ticks for a power of 12, whatever Pico’s feet are doing. So the length is the speed × 24, and a speed of 5 goes 120. Keep these numbers: next lesson builds platforms, and a gap wider than Pico can jump is a level nobody can finish.
The trampoline
The ledge is 140 above the ground, and Pico’s best jump is 66. Add a trampoline that launches Pico high enough to land on it.
- Touching the
Trampolinesprite setsy velocityto 18. - A
boingscounter — and one bounce must count once, not three times. - Walking into it from the side should launch Pico too.
How to use this: Click the green flag. Pico walks right into the trampoline and is thrown up onto the ledge.
Teacher note
Nothing about the trampoline is new: it is the jump block, run by a touch instead of a key. That is the idea to leave them with — every bounce pad, spring and launcher in a platform game is set [y velocity v] to ( ) with a different reason for running it.
Summary 5 min
- A jump is
set [y velocity v] to (12). Gravity does the rise, the top and the fall. on groundis cleared every tick and set only by a real landing.- Jump only when a key is pressed and
on groundis 1. - Height grows much faster than power: 8 rises 28, 16 rises 120.
- Air time does not depend on walking speed, so length = speed × air time.
- Jump power
- The speed a jump starts with.
- Air time
- How many ticks a jump spends off the ground — 24 for a power of 12.
- Flag variable
- A variable that is only ever 0 or 1, answering one yes-or-no question.
- Double jump
- One extra jump allowed in mid-air, refilled by landing.
Hand in
Save your meadow. Next lesson the ground grows steps — and you find out what happens when Pico walks into one instead of jumping onto it.