- Learnt27 min · the hammer, nine holes, a mole that flips a coin
- Basic25 min · build the whole game
- Challenge 1–327 min · hammer and holes, the mole, the full game
- Extrabonus · two moles at once
Review — where we got to 5 min
Last lesson you finished the Shark Game and gave it a score.
- A variable is a named box.
set [score v] to (0)at the start,change [score v] by (1)when it should go up. - “For all sprites” means everybody shares one box.
change [score v] by (1)goes beforedelete this clone, or it never runs.
Quick-fire
What is on the monitor after this runs?
when flag clicked
set [score v] to (0)
repeat (4)
change [score v] by (3)
end
Reveal the answer
12. Three, four times over. change [score v] by (1) adds to what is already in the box — it does not replace it.
Today’s Topic 3 min
- A sprite that follows your mouse pointer
- Nine holes made with clones
- A mole that decides for itself whether to appear
- A clock, and a game that ends with a verdict
Learning outcome
By the end of this lesson you will be able to:
- Make a sprite follow the mouse and react when you click.
- Place clones at exact positions rather than random ones.
- Use chance to decide whether something happens at all.
- End a game on a timer and say whether the player won.
Learnt — mouse, holes and moles 27 min
New blocks today
| Block | Category | What it does |
|---|---|---|
go to [mouse-pointer v] | Motion | Jumps the sprite to wherever your pointer is. |
mouse down? | Sensing | True while the mouse button is held, like a key-pressed question. |
go to [front v] layer | Looks | Puts a sprite in front of everything else, so it is never hidden behind. |
repeat until <> | Control | Loops until a question becomes true. A countdown is exactly this. |
() > () and () = () | Operators | Compare two numbers. They are pointed, so they go inside an if. |
The hammer follows the mouse
go to [mouse-pointer v] inside a forever and the hammer is glued to your pointer.
The swing is a separate stack. It has to be, or the hammer would stop following you while it was swinging — the same rule as every parallel script since Topic 1.3.
when flag clicked
go to [front v] layer
forever
go to [mouse-pointer v]
end
when flag clicked
point in direction (90 v)
forever
if <mouse down?> then
point in direction (150 v)
else
point in direction (90 v)
end
end
Nine holes, one sprite
The holes sit on a grid: x on −132, 0, 132 and y on 86, 0, −86. Nine places.
Topic 1.10’s clones made copies in random places. This time you want them in exact places — so the maker stack moves to each spot and clones itself there.
when flag clicked
hide
set size to (55) %
go to x: (-132) y: (86)
create clone of [myself v]
go to x: (0) y: (86)
create clone of [myself v]
go to x: (132) y: (86)
create clone of [myself v]
when I start as a clone
go to [back v] layer
show
The mole tosses a coin
A mole that pops up every single time is a metronome, not a game. The deck’s trick is to give it a 50% chance each turn.
pick random (0) to (1) gives you a 0 or a 1 — a coin. Ask whether it came up 1, and act only then.
when flag clicked
hide
forever
wait (pick random (1) to (1.5)) seconds
if <(pick random (0) to (1)) = (1)> then
go to x: ((pick random (-1) to (1)) * (132)) y: ((pick random (-1) to (1)) * (86))
switch costume to [half out v]
go to [front v] layer
show
wait (0.3) seconds
switch costume to [fully out v]
wait (0.5) seconds
hide
end
end
Getting smashed
A second stack on the mole watches for the hammer. It only counts if the mouse is down — otherwise waving the hammer over a hole would score.
when flag clicked
forever
if <touching [Hammer v]?> then
if <mouse down?> then
switch costume to [smashed v]
change [score v] by (1)
wait (0.2) seconds
hide
end
end
end
The referee
The clock and the verdict do not belong to the hammer or the mole. They belong to the game. So they get their own sprite, hidden, that does nothing but keep time.
when flag clicked
hide
set [score v] to (0)
set [time v] to (30)
repeat until <(time) = (0)>
wait (1) seconds
change [time v] by (-1)
end
show
if <(score) > (5)> then
say [You win!] for (2) seconds
else
say [You lose!] for (2) seconds
end
stop [all v]
Basic — build the game 25 min
Step 1 — the hammer
Add your hammer sprite. Build the two stacks: follow the mouse, and swing on mouse down?. Test before anything else exists.
Step 2 — one hole
Add the hole sprite. Set its size so it looks right on your backdrop — the deck uses 300% for a small picture; ours is 55%. Yours will differ.
Step 3 — nine holes
Build the maker stack: nine go to x: () y: () and create clone of [myself v] pairs, walking the grid. Add the when I start as a clone stack with go to [back v] layer and show.
Step 4 — the mole appears
Add the mole with its three costumes. Build the coin-toss stack. Watch it for a minute and count how often it comes up — it should be about half the turns.
Step 5 — smashing
Add the second mole stack. Test: swing at an empty hole (nothing), wave the hammer over a mole without clicking (nothing), click on a mole (it goes).
Step 6 — score and clock
Make the two variables, score and time. Add the referee sprite with the countdown. Right-click each monitor and choose large readout, then drag score to the left and time to the right.
Step 7 — music
Click the Stage, add a sound, and give it set volume to (20) % before a forever that plays it. Twenty per cent — the game needs to be heard over it.
The hammer disappears behind the holes.
It is missing go to [front v] layer, or the holes are missing go to [back v] layer. Layers are decided by whoever ran last, so say it explicitly on both.
I score just by holding the mouse down and waving about.
That is correct behaviour for the blocks you wrote, and it is worth thinking about. The deck’s fix is to make only the head of the hammer count — a colour on the costume, and touching color [#003FFF]? instead of touching [Hammer v]?. That is next lesson.
Hammer and holes
Get the board ready.
- Nine holes, made with clones, on the nine grid positions.
- A hammer that follows your mouse and swings when you click.
- The hammer is always in front, the holes always behind.
A mole worth hitting
- The mole appears in a random hole, about half the time.
- It comes up, waits, and goes back down on its own.
- Clicking on it while it is up scores 1 point and knocks it down.
- Clicking an empty hole scores nothing.
Teacher note
The coin toss is the interesting block here. pick random (0) to (1) is the first time chance decides whether rather than where, and it is worth asking the class what the game would feel like without it. A mole that always appears is a chore; one that sometimes does not is a game.
The whole game
The deck’s own mission. Finish it.
- Nine holes, made with clones.
- Thirty seconds of play, counting down on the Stage.
- One point per mole smashed.
- Nine points or more within the thirty seconds wins. Less loses.
- A sprite that says which, and then everything stops.
Teacher note
Nine points in thirty seconds is deliberately tuned — with a 50% coin and a 1 to 1.5 second wait, about twelve moles appear in a round, so nine is a real target and not a formality. Pupils who find it too easy have usually shortened the wait; that is a fair change as long as they can say what they changed and why.
The verdict sprite needs go to [front v] layer before it shows — third time this lesson, and worth saying out loud.
Two moles at once
The deck ends with a question: can you make more than one mole come out at once?
Do it. Two moles up at the same time, in different holes — never both in the same one.
Summary 5 min
go to [mouse-pointer v]in a forever glues a sprite to your pointer.mouse down?is the click.go to [front v] layerandgo to [back v] layerdecide what covers what. Say it explicitly or Scratch decides for you.- Clones can be placed exactly: move, clone, move, clone. A clone keeps the position it was made at.
pick random (0) to (1)is a coin toss — chance deciding whether something happens at all.repeat until <(time) = (0)>is a countdown, and a hidden referee sprite is a tidy place to keep it.
- Layer
- Which sprite is drawn in front of which.
- Coin toss
- A random choice between two things, used to decide whether something happens.
- Referee sprite
- An invisible sprite that holds the rules of the game rather than a character.
Hand in
Share your project and send the link to your teacher. Keep it safe — the next three lessons build on this game.