- 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 was the end of the first part of Level 1. Three ideas from it come back today.
- Clones. One sprite made many copies of itself. Each copy ran the same script.
- Touching. A fish asked
touching [Shark v]?and deleted itself if the answer was yes. - The controller. A
foreverwith anif <> thenin it for each key.
Quick-fire
In the Shark Game every fish swam in a random direction. Today’s muffins do something much simpler. What is it?
Reveal the answer
They fall. Every one falls straight down, 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 move 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 gets to the ground.
- Steer a catcher left and right while things are falling.
Learnt — a falling muffin 27 min
Nearly every game has something falling in it, like rain, apples, bombs or snow. They are all built the same way. That is what we learn today.
Three questions
Any falling thing has to answer three questions.
- 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 under it.
The x is the fun part. What if it was always 0? Every muffin would fall down the middle. The game would be far too easy.
- 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. That is why 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. That is the height of the Stage, from top to bottom. So the loop ends just as the muffin gets to 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. 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 when 300 are on the Stage. Then your game stops working.
The whole muffin, in two stacks
The real 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 really does
- Hide the real sprite. Nobody ever sees it.
- Wait a second. Make a clone.
- The clone shows itself. It 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. Then delete myself.
The catcher
You built this in Topic 1.6. The bowl uses those controls, with up and down taken out. 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. 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 controls from the Learnt section.
- Click the flag and click the Stage. Then hold each arrow key.
- The bowl should slide along the bottom. It should never move up or down.
Step 3 — one muffin, falling
- Click the Muffin. Build the maker stack. It is 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 make it fall.
- Click the flag. A muffin 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. Change the dropdown to Bowl. - Put
delete this cloneinside the if. - Play it. A caught muffin should vanish as soon as 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. They should not pile up 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 likes.
My muffins 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, not the clone stack. Every clone needs to pick its own x.
One muffin hangs at the top and never falls.
That is the real 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. They are hidden or stuck. Scratch allows 300 at once. Check that both delete this clone blocks are there.
Your own stall
Build the same game with sprites nobody else in the room has picked. It could be a basket of plum, a hat catching raindrops, or 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. It also vanishes when it lands.
Two kinds of muffins
Add a second falling sprite. It must look different from the first. It must fall at a speed that is easy to see as different.
- Both kinds fall from random places along the top.
- One is quicker than the other. You can see which one without being told.
- Both can be caught. 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 fall at three speeds, all at once. And the bowl cannot go off the edge of the Stage.
Try it as it is first. Hold the right arrow for five seconds. The bowl goes off the Stage, and you cannot play. 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 muffin in your stall does not fall straight. It slides sideways on the way down. So just being under 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. The sideways part is not the same every run.
- It can still be caught. It still disappears at the bottom.
- The other kinds of muffins stay the same.
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 can delete itself in two ways: when it is caught, and when it lands.
The catcher is last lesson’s controls with half of them taken out. Most of a new game is old blocks used in a new way.
- 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 way to reach one, or the Stage fills up.
- Catcher
- The sprite the player moves. In this game it only moves sideways.
Next lesson: the game keeps score, and you can lose.