- Learnt28 min · a level is a number; the handover
- Basic24 min · two levels
- Challenge 1–327 min · the pile-up, a title card, the best level
- Extrabonus · levels in a list
Review — a camera that follows 5 min
- Pico walks for real.
scroll the worldpulls everything back at the end of the tick. - World x is
((scroll x) + (x position)). - Respawns, enemies and checkpoints are world positions.
Quick-fire
Your Ground sprite switches to L1 screen 1, L1 screen 2… using join. What small change would make it draw a different set?
Reveal the answer
Put the level number in the join. L1 is “L” and 1. Make the 1 a variable called level. Then the same blocks draw level 2’s costumes. That is today’s first idea.
Today’s Topic 3 min
- A
levelvariable picks the screens and the sky - Rebuilding the world: old clones go, new ones are made
- A
next levelMy Block - Title cards, using Storm Flight’s state
Learning outcome
By the end of this lesson you will be able to:
- Choose a level’s costumes and backdrop from one number.
- Swap one level for another without leaving anything behind.
- Hold the game still while a title card is showing.
Learnt — levels 28 min
1 · A level is a number
Paint level 2’s screens as four more Ground costumes. Name them L2 screen 1 to L2 screen 4. Add a second backdrop. Name the backdrops Level 1 and Level 2. Now both choices use a join:
switch costume to (join (join [L] (level)) (join [ screen ] (screen)))
switch backdrop to (join [Level ] (level))
How to use this: Click the green flag. Level 1 scrolls past, then level 2 is built and scrolls past.
2 · The handover
When Pico reaches the flag, everything about the level has to change at once. One My Block does it. Every copy of Ground answers the build broadcast. A clone deletes itself, and the original builds the new level.
define next level
change [level v] by (1)
switch backdrop to (join [Level ] (level))
set [scroll x v] to (0)
go to x: (-180) y: (-104)
set [y velocity v] to (0)
broadcast [build v] and wait
broadcast [scroll v]
broadcast [build v] and wait. Then the new screens are there before anything is placed.
when I receive [build v]
if <(is clone) = (1)> then
delete this clone
else
build the level :: custom
end
build the level is last lesson’s clone-making script, moved into a My Block. is clone is for this sprite only. The original keeps 0. Every clone sets it to 1 as soon as it starts.How to use this: Click the green flag. Pico walks the last stretch of level 1 to the flag. Then it carries on into level 2.
Basic — two levels 24 min
Open your scroller from last lesson. Give it a second level.
Step 1 — paint level 2
- Duplicate the four Ground costumes. Rename them
L2 screen 1toL2 screen 4. Repaint them to be harder than level 1. - Keep the same green for solid ground and the same blue for water.
- Add a second backdrop. Name the two
Level 1andLevel 2.
Step 2 — the number
- Make
levelfor all sprites. Makeis cloneon Ground, for this sprite only. - Change the costume and backdrop switches to the joins from Learnt part 1.
Step 3 — build on request
- Change Ground’s
when flag clickedtowhen I receive [build v]. Add the clone check from part 2. - In the clone’s start script, add
set [is clone v] to (1). - Pico’s flag script sets
levelto 1, thenbroadcast [build v] and wait.
Step 4 — the flag
- Make the
next levelblock. - Touching the flag on level 1 runs it. Touching it on level 2 wins the game.
if <touching (Flag v)?> then
if <(level) = (2)> then
set [state v] to [won]
say [Both levels - you win!]
else
next level :: custom
end
end
if <(state) = [play]> then, as in Storm Flight.How to use this: Click the green flag. Use the arrows to walk and space to jump. Reach the flag on level 1, then on level 2.
Level 2 appears but looks like level 1.
The costume switch still says L1 instead of joining in level. Or it runs before level has changed.
Level 2 is drawn on top of level 1.
The old clones are not deleting themselves. That is Challenge 1.
Nothing is there at all after the flag.
A costume name does not match the join. Check for a missing space. If you ask for a costume that does not exist, Scratch keeps the old one.
Pico reaches the flag and skips straight to level 3.
Pico is still touching the flag on the next tick. next level must move Pico back to the start before anything else can check the flag again.
The pile-up
Count the screens. Build level 2 once without the delete, and once with it.
- A
screenscounter. Add 1 when a clone starts. Take 1 off when one deletes. - The original counts as one screen.
- Read the counter after each build.
How to use this: Click the green flag. Level 1 is built, then level 2. The old clones are left in place.
Teacher note
A pile-up is easy to miss, because the new screens are drawn over the old ones and most of the time look fine. The counter is the honest check — and three extra clones per level adds up fast against Scratch’s limit of 300.
A title card
Show “LEVEL 1” and “LEVEL 2” for a moment at the start of each level. The game must stay still.
- Set
statetotitleand show the card. Then set it toplay. - The loop only moves Pico when the state is
play. - Test it by holding the arrow key down through a card.
How to use this: Click the green flag. The arrow key is held down the whole time. Watch if Pico moves during the cards.
Teacher note
This is Storm Flight’s title screen, reused. The point worth drawing out: nothing had to be added to Pico’s physics, because the state check already wraps it — Lesson 3-23’s pause and today’s title card are the same idea.
The furthest level
Keep a best level that stays when you lose and start again.
- It is set to 0 only when the project is first opened.
- Every time a level starts, raise it if this level is higher.
- Starting again from level 1 must not lower it.
How to use this: Click the green flag. Pico reaches level 2, then starts again from level 1.
best level is on screen. It never goes down, however often you lose.Teacher note
The same shape as every best in this level — a high score in Storm Flight, a best time in Cheese Maze — on a new kind of number. By now the pupils should be writing it without being shown.
Levels in a list
Let a list decide the order of the levels. Change the list, and the game plays them in a different order. Not a single script changes.
- A list
level order. It holds2then1. - A
stagecounter. Stage 1 plays(item (stage) of [level order v]). - The flag moves on one stage, not one level.
How to use this: Click the green flag. Read which level each stage of the game turns out to be.
Teacher note
Watch for pupils who put the same level in the list twice. It works — and it is a perfectly good design choice, a revisited level. The list does not care.
Summary 5 min
- One
levelvariable chooses the screens and the sky, usingjoin. - A new level is a rebuild. Clones delete themselves. The original makes new ones.
next levelchanges the number and resets the scroll and Pico. Then it builds.- A title card is a state where the game loop moves nothing.
- Level
- One complete stretch of world, with its own screens and sky.
- Rebuild
- Throwing the old level’s clones away and making new ones for the next level.
- Title card
- A moment between levels when the game is held still.
- Data-driven
- A list or a variable decides what happens. You do not change the scripts.
Hand in
Save your game. Next lesson, both levels fill up with coins.