- Learnt27 min · the shark, the sea, four kinds of fish
- Basic25 min · build the whole game
- Challenge 1–327 min · your own version, animate it, two players
- Extrabonus · one fish you must not eat
Review — where we got to 5 min
Last lesson you learnt to make copies the right way.
- The real sprite hides and makes clones. The clones run
when I start as a clone. - One number in a repeat sets how many there are.
delete this clonegets rid of a clone.hideonly makes it invisible.
Quick-fire
How many bats are on the Stage after this runs?
when flag clicked
repeat (6)
create clone of [myself v]
end
Reveal the answer
Seven. Six clones, plus the real one that nobody hid. That extra bat never flies, and you cannot catch it. Check for it first when a clone game acts oddly.
Today’s Topic 3 min
- The Shark Game
- Flipping a costume so it faces the same way as the sprite
- Many kinds of one thing, each with its own clones
Learning outcome
By the end of this lesson you will be able to:
- Build a whole game with blocks you already know.
- Say why a costume that faces the wrong way makes direction blocks act oddly.
- Use clones to fill the Stage with many kinds of moving thing.
Learnt — the shark and the sea 27 min
The rules
| # | Rule | Where you learnt it |
|---|---|---|
| 1 | Arrow keys drive the shark. It starts in the middle. | Topic 1.6 |
| 2 | Space opens the mouth. Letting go shuts it. | Topic 1.7 |
| 3 | When it goes right, it faces right. When it goes left, it faces left. | Topic 1.7 |
| 4 | 12 to 20 fish. They appear in random places and move at random, at a steady speed. | Topic 1.9 and 1.10 |
| 5 | A fish only disappears into an open mouth. | Topic 1.8 |
| 6 | At least four kinds of fish, with about the same number of each. | Topic 1.10 |
| 7 | Fish bounce off the edges. | Topic 1.9 |
The shark
Shark at 60%, fish at 30%. The shark has two costumes: shark-swim with the mouth shut, and shark-bite with it open.
How to use this: Click the green flag, then click the stage once and use the arrow keys to move the Shark. The space bar does something as well — find out what.
The fish
There are four kinds. Each kind is a sprite that hides and makes three or four clones. Each clone swims in a random direction at a steady speed. It bounces off the walls.
You have made this script before. It was the bat in Topic 1.10. The only change is the costume.
when flag clicked
hide
repeat (4)
create clone of [myself v]
end
when I start as a clone
show
set size to (30) %
set rotation style [left-right v]
go to [random position v]
forever
point in direction (pick random (-180) to (180))
repeat (pick random (10) to (25))
move (3) steps
wait (0.05) seconds
end
end
Getting eaten
The fish checks two things, one inside the other. Am I touching the shark? Is its mouth open? The fish cannot see the shark’s costume. So it checks the space key, like in Topic 1.8.
when I start as a clone
wait (0.5) seconds
forever
if <touching [Shark v]?> then
if <key [space v] pressed?> then
delete this clone
end
end
end
That is four stacks on one fish sprite: make the clones, swim, bounce, get eaten. Each one does a different job at the same time.
Basic — build the game 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 use the arrow keys. The space bar does something as well — find out what.
Step 1 — the sea
Start a new project. Use the backdrop Underwater 1. Delete the cat. Add your shark and set it to 60%.
Step 2 — the shark swims
Build the controls. Set rotation style to left–right. Go to (0, 0). Add the four movement ifs. Set the facing in the left and right ones. Test all four keys.
Step 3 — the mouth
Add the if / else on key [space v] pressed?. It switches between the two costumes. Hold space and let go a few times.
Step 4 — one fish
Add a fish sprite. Build its maker stack, its swimming stack and its bouncing stack. Press the flag. You see four fish swimming about.
Step 5 — eating
Add the fourth stack. Test it both ways. Swim through a fish with the mouth shut. Then do it again with the mouth open.
Step 6 — three more kinds
Right-click the fish sprite and duplicate it three times. On each copy, change the costume and the number in the repeat.
Four sprites with 4, 4, 3 and 3 clones give you fourteen fish. The rules ask for about the same number of each. So keep the numbers no more than two apart.
Step 7 — play it
Eat every fish in the sea. Then press the flag again. Check that you get a new sea. Is a fish left over from last time? Then a hide is missing from a maker stack.
My shark swims backwards.
The costume faces left. Open the Costumes tab and use Flip Horizontal on both of them. Do not try to fix it in the code.
Fish disappear when I swim past with my mouth shut.
Your delete this clone is inside the touching-if. But it is outside the space-if. It needs to be inside both.
The same game, your world
Build a game that works like the Shark Game, but in a new place. It could be a cat collecting food, a bird collecting seeds or a robot collecting bolts. You choose.
- At least four kinds of thing to collect.
- All of them move at random. All of them are clones.
- One character you drive.
Animate it — but only when it moves
Give your character a walk cycle. But it must animate only while it is going somewhere. When it stops, it stays still.
Then add a second player on W A S D.
Done when: your character’s legs move while you hold a key. They stop as soon as you let go. You can drive both characters at once with two hands.Teacher reveal — animating only while moving
The neat answer puts next costume inside the movement ifs rather than in a stack of its own — so it only ever runs on a frame where a key was down:
if <key [right arrow v] pressed?> then
point in direction (90 v)
change x by (5)
next costume
end
It will animate very fast — one costume per frame. A wait (0.05) seconds would fix that but would also make the controls sluggish, which is a real trade-off worth discussing rather than solving.
Two hunters in one sea
Two players collect from the same group of things.
- Player 1 on W A S D with its own “collect” key.
- Player 2 on the arrow keys with its own.
- Either player can take any of them.
- Both animate while moving.
Teacher note
The collectible now has two ways to be taken, so it needs two touching-checks in its forever, each paired with its own collect key. It is the same shape as Topic 1.8’s two-player challenge — and the obvious next question, “who got more?”, is exactly what next lesson is for.
One you must not eat
Add a fifth kind that you are not meant to collect. It could be a jellyfish or a bomb. It must look very different.
Touch it and something bad happens. Your character shrinks, slows down, or goes back to the middle. You choose, but it must be easy to see.
Summary 5 min
- A whole game is not a new kind of thing. It is the parts you already know. Build them in order and test them one at a time.
- Flip a costume so it faces right. In Scratch, direction 90 means right. A picture that faces left makes every direction block confusing.
- Four kinds of one thing means four sprites. Each one clones itself. The scripts are the same. Only the costume changes.
- One fish sprite has four stacks: make, swim, bounce, get eaten.
- Collectible
- A thing in a game that the player should pick up.
- Hazard
- A thing in a game that the player should stay away from.
- Flip Horizontal
- The paint editor button that turns a costume to face the other way.
Hand in
Share your project and send the link to your teacher. Keep this project safe. Next lesson carries on from it.