- Learnt27 min · falling clones, and a bowl that slides
- Basic25 min · build the stall yourself
- Challenge 1–327 min · your stall, two kinds, three speeds
- Extrabonus · a muffin that dodges
Review — where we got to 5 min
The Shark Game finished Level 1’s first arc. Three ideas from it come back today.
- Clones. One sprite made many copies of itself, and each copy ran the same script.
- Touching. A fish asked
touching [Shark v]?and deleted itself when the answer was yes. - The controller. A
foreverwith anif <> theninside it for each key.
Quick-fire
In the Shark Game every fish swam about in a random direction. Today’s muffins do something much simpler. What is it?
Reveal the answer
They fall. Straight down, every one of them, from the top of the Stage to the bottom. The only surprise is where along the top each one starts.
Today’s Topic 3 min
- Falling objects — clones that start at the top and travel down
go to x: () y: (170)with(pick random (-200) to (200))in the x slotchange y by (-10)inside arepeat (10)- A catcher that only moves sideways
Learning outcome
By the end of this lesson you will be able to:
- Make a sprite that drops from a random place along the top of the Stage.
- Delete a clone when it is caught, and when it reaches the ground.
- Steer a catcher left and right while things are falling.
Learnt — a falling muffins 27 min
Nearly every game has something falling in it. Rain, apples, bombs, snow. They are all built the same way, and it is today’s whole lesson.
Three questions
Any falling thing has to answer three questions. Nothing else.
- Where do I start?
- How do I go down?
- When do I disappear?
Question 1 — where do I start?
At the top. The top edge is y = 180, so 170 puts the muffin just inside it.
The x is the interesting part. If it were always 0, every muffin would fall down the middle and the game would be over in a second.
- Drag
go to x: (0) y: (0)from Motion. - Open Operators and drag
(pick random (1) to (10))into the x slot. - Type −200 and 200 into its two boxes.
- Type 170 into the y box.
- Click the block a few times. The muffin jumps about along the top.
Question 2 — how do I go down?
In small steps, inside a loop. One big jump would be over before anyone saw it. This is the same reason the Shark Game moved five pixels at a time.
change y by (-340)
repeat (34)
change y by (-10)
end
Thirty-four steps of ten is 340, which is the height of the Stage from top to bottom. So the loop ends exactly as the muffin reaches the ground.
How to use this: Click the green flag to start it. Nothing else to press — watch it through, then use ↺ Reset to run it again.
Question 3 — when do I disappear?
There are two endings, and a falling thing needs both.
- Caught. It touched the bowl, so it goes.
- Missed. It reached the ground, so it goes.
A clone that never deletes itself is a real problem. Scratch stops making new ones once 300 are on the Stage, and your game quietly dies.
The whole muffin, in two stacks
The original sprite hides and makes clones. Each clone falls.
when flag clicked
hide
forever
wait (1) seconds
create clone of [myself v]
end
when I start as a clone
show
go to x: (pick random (-200) to (200)) y: (170)
repeat (34)
change y by (-10)
if <touching [Bowl v]?> then
delete this clone
end
end
delete this clone
What the computer actually does
- Hide the original. Nobody ever sees it.
- Wait a second. Make a clone.
- The clone shows itself and jumps to the top, at a random x.
- Move down ten. Is the bowl touching me? No.
- Move down ten. Is the bowl touching me? No.
- …thirty-four times, and then delete myself anyway.
The catcher
You built this in Topic 1.6. The bowl is that controller with the up and down parts removed, because a bowl on a table does not fly.
when flag clicked
go to x: (0) y: (-140)
forever
if <key [right arrow v] pressed?> then
change x by (10)
end
if <key [left arrow v] pressed?> then
change x by (-10)
end
end
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl.
Basic — build the stall 25 min
Build it in this order and test after every step. Do not skip the testing.
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl.
Step 1 — the stall
- Start a new project and delete the cat.
- Choose the backdrop Colorful City. That is our market.
- Add the Bowl sprite. Add the Muffin sprite for the muffin.
The Scratch library has no muffin, so the muffin stands in for one. Your own game can use anything you like.
Step 2 — the bowl slides
- Click the Bowl. Build the controller from the Learnt section.
- Click the flag, click the Stage, then hold each arrow key.
- The bowl should slide along the bottom and never move up or down.
Step 3 — one muffin, falling
- Click the Muffin. Build the maker stack: hide, then a forever with a wait and a clone.
- Build the falling stack under
when I start as a clone. - Leave the touching-if out for now. Just get it falling.
- Click the flag. A muffins should appear every second and drop to the ground.
Step 4 — catching
- Drop an
if <> theninside the repeat, under the change y. - Drag
touching [mouse-pointer v]?into the diamond and change the dropdown to Bowl. - Put
delete this cloneinside the if. - Play it. A caught muffins should vanish the moment it lands in the bowl.
Step 5 — clear the leftovers
- Check there is a
delete this clonebelow the repeat as well. - Let three or four muffins hit the ground without catching them.
- They should disappear, not pile up in a row along the bottom.
Step 6 — make it fair
- Play for thirty seconds. Too easy? Change the wait to 0.6.
- Too hard? Make the repeat 68 and the change y −5.
- That is the same fall, at half the speed. Pick the numbers your class enjoys.
My muffin all fall down the middle.
The (pick random (-200) to (200)) is in the y slot, or the go to block is in the maker stack instead of the clone stack. Every clone needs to choose its own x.
One muffin hangs at the top and never falls.
That is the original sprite, not a clone. It needs hide under its when flag clicked.
After a while no new muffins appear.
Old clones are still on the Stage, invisible or stuck. Scratch allows 300 at once. Check that both delete this clone blocks are there.
Your own stall
Build the same game out of sprites nobody else in the room has picked. A basket of plum, a hat catching raindrops, a plate under falling pancake.
- Your catcher moves left and right only.
- Your falling thing starts somewhere different every time.
- It vanishes when it is caught, and when it lands.
Two kinds of muffins
Add a second falling sprite. It must look different from the first, and it must fall at a clearly different speed.
- Both kinds fall from random places along the top.
- One is quicker than the other, and you can see which without being told.
- Both can be caught, and both disappear when they land.
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl.
Teacher note — the fastest way to a second kind
Right-click the first muffin sprite and choose duplicate. The whole script comes with it. Then change the costume and the two numbers in the repeat. Pupils who rebuild it by hand are not wrong, but they will run out of time.
The whole stall
Three kinds of muffins, three speeds, all falling at once. And a bowl that cannot be pushed off the edge of the Stage.
Try it as it is first: hold the right arrow for five seconds. The bowl walks off the Stage and the game is unplayable. Your job is to stop that.
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl.
Teacher reveal — keeping the bowl on stage
when flag clicked
go to x: (0) y: (-140)
forever
if <key [right arrow v] pressed?> then
change x by (10)
end
if <key [left arrow v] pressed?> then
change x by (-10)
end
if on edge, bounce
end
if on edge, bounce is the block they already know, and inside a forever it becomes a fence. It does turn the bowl round, which looks odd — that is honest, and it is what left-right rotation style fixes in Topic 1.3.
A pupil who instead writes if <(x position) > (220)> then has reached into Level 2 on their own. Accept it and say so.
The muffin that dodges
One kind of muffins in your stall does not fall straight. On the way down it slides sideways, so being underneath it is not enough.
How to use this: Click the green flag, then click the stage once and hold ← or → to slide the Bowl.
- It still starts at a random place along the top.
- It moves sideways as well as down, and the sideways part is not the same every run.
- It can still be caught, and it still disappears at the bottom.
- The other kinds of muffins are unchanged.
Teacher notes — where the randomness goes
The neat answer puts a second random inside the falling loop, so the muffin picks a new sideways nudge on every step:
repeat (34)
change y by (-10)
change x by (pick random (-12) to (12))
if <touching [Bowl v]?> then
delete this clone
end
end
One block, and the whole feel of the game changes. Pupils who instead glide to a random x halfway down have made something smoother and harder; both are good.
Going further: point towards [Bowl v] from Motion makes a muffin that chases the player instead of running away. Nobody has met it yet. It is one block.
Summary 4 min
A falling thing is a clone that answers three questions.
- It starts at the top, at
(pick random (-200) to (200)). - It comes down in small steps, inside a
repeat (10). - It deletes itself twice over: once when caught, once when it lands.
The catcher is last lesson’s controller with half of it removed. Most of a new game is old blocks in a new shape.
- Falling object
- A clone that starts at the top of the Stage and moves down in small steps.
- Spawn point
- Where a clone appears. Here it is a random x along the top.
- delete this clone
- Removes one copy. Every clone needs a route to one, or the Stage fills up.
- Catcher
- The sprite the player steers. In this game it only moves sideways.
Next lesson: the game keeps score, and you can lose it.