Make a Whack-a-Mole Game in Scratch for Kids

KidsKod original illustration.

 

Ready for a fast, funny game you can build in one afternoon? In this KidsKod project you will make a Whack-a-Mole game in Scratch: cheeky moles pop out of holes, and you click them as fast as you can before the timer runs out. If you enjoyed our Catch the Stars game in Scratch, this one uses some of the same ideas, plus a countdown timer and random hiding spots.

What you need

  • A computer or tablet with a web browser
  • Free Scratch at scratch.mit.edu (an account lets you save your game, but you can also try it without one)
  • About 45 minutes and a grown-up nearby to cheer you on

What you will learn

  • How to use variables to keep score and count down time
  • How to move a sprite to random positions
  • How to use show and hide to make things pop up
  • How to react to clicks with when this sprite clicked
  • How to broadcast a message to end the game

Step 1: Set up the stage

  1. Open Scratch and click Create.
  2. Right-click the cat sprite and choose delete.
  3. Click the Choose a Backdrop button and pick a grassy one, or paint your own green field.
  4. Use the paint tool to draw 3 to 6 dark ovals as mole holes. Remember roughly where they are!

Step 2: Add your mole

  1. Click Choose a Sprite. Scratch has no mole, so pick a cute animal (the Hedgehog or a Mouse works well) or paint your own mole.
  2. Rename the sprite to Mole.
  3. Make it small enough to fit in a hole. Set its size to about 50.

Step 3: Make two variables

  1. Go to the orange Variables blocks and click Make a Variable.
  2. Create Score (for all sprites).
  3. Create Time (for all sprites).
  4. Keep both check boxes ticked so they show on the stage.

Step 4: Make the mole pop up in random holes

Click the Mole sprite and build this script:

  • when green flag clicked
  • hide
  • forever
    • go to x: (pick random -180 to 180) y: (pick random -120 to 80)
    • show
    • wait (pick random 0.5 to 1.2) seconds
    • hide
    • wait (pick random 0.3 to 1) seconds

Tip: Want the mole to appear only in your holes? Instead of random x and y, make a list called HolesX and HolesY with the position of each hole, then use pick random 1 to (length of HolesX) to choose a hole number.

Step 5: Score points when you whack it

  1. Add a new script to the Mole: when this sprite clicked.
  2. Add change Score by 1.
  3. Add start sound (Pop) from the Sound blocks for a fun bonk.
  4. Add hide so the mole ducks away after it is hit.

Step 6: Add a 30-second countdown

Click the Stage (bottom right) and build:

  • when green flag clicked
  • set Score to 0
  • set Time to 30
  • repeat until (Time = 0)
    • wait 1 seconds
    • change Time by -1
  • broadcast (Game Over)

Step 7: End the game

  1. Back on the Mole sprite, add when I receive (Game Over).
  2. Add hide, then stop (other scripts in sprite) so no more moles pop up.
  3. Add a new sprite with the words Game Over! Make it hide when the green flag is clicked and show when it receives Game Over.

Step 8: Test and tweak

  • Click the green flag and play. Can you beat 15 points?
  • Too hard? Make the wait times bigger. Too easy? Make them smaller.
  • Ask a friend or family member to play and see who gets the high score.

Wrap-up and challenge

Great job! You built a real game with variables, random numbers, a timer and broadcasts, the same ideas game designers use every day. Now try a level-up challenge:

  • Golden mole: duplicate the Mole, color it gold, and make it worth 5 points but appear rarely.
  • Don't whack the bunny: add a sprite that takes away 2 points if you click it.
  • Speed up: make the moles pop faster when Time is less than 10.

Share your game on Scratch and keep coding with KidsKod!

Previous Post
No Comment
Add Comment
comment url