Whack-A-Mole is an awesome game about “moles” that pop up from the “ground”. To play, a player uses a hammer-like tool to “whack” as many moles and as quickly as possible. And if you’re really good at it, you might win a prize!

Whack-A-Mole has been played for decades at carnivals, amusement parks, and arcades. You can even play Whack-A-Mole online and free. So today is your chance to learn how to create this popular game using Scratch coding!

This article will walk you step-by-step through how to make a Whack-A-Mole game on Scratch. It's probably a little easier than you think, and we'll even give you some ideas for customizing your game. Then, if you want to build on your new skills, check out our Scratch coding for kids classes. Let's get started!

Screen-Shot-2021-09-07-at-6.19.41-PM

What type of game is Whack-A-Mole?

If you’ve played Whack-A-Mole, then you know that it is a simple game that requires very minimal thought and effort. Fast reaction is the only skill needed. Whether with the click of the mouse if playing online, or a fast arm if you’re playing in person, either way, this game is straight forward and easy to get. Just keep up with the mole and you will up your score.

From a programming perspective, however, this game requires a little more thought and effort. But don’t worry, we’ve got you covered. We simplify the logic behind the game to make it easy and fun to make. And by the time we are done with this tutorial, you will have the basic functionalities for the game which opens the door for complexity you may want to add.

How to make a Whack-A-Mole game on Scratch

In this tutorial, we’ll show you how to build a Whack-A-Mole game (here's our project) by putting together some of the most used blocks such as clone, show/hide, wait, etc. We’ll tackle the logic with if/then and forever conditional block. We’ll use a variable for score and Sprites for functions. We’ll break down the few rules of the game into sections, and work on coding each one starting with the easiest.

1. Make Your Mole and Hammer Sprites

For the ease of this step, we’ve decided to go with a Squirrel Sprite to represent the mole(s), and a Goalie to represent the hammer. We resized both Sprites and tweaked the Goalie’s costume to add a hint of animation as the user catches up with moles. If you wish, you can either create your own Scratch Sprite by selecting the Paint icon when you hover over the Sprite Library icon, or you can import an image by selecting Upload Sprite option, which is above the Paint icon:

Graphical user interface, application, chat or text message

Description automatically generated


Graphical user interface, text, application, chat or text message

Description automatically generated

2. Create Your Backdrop of Choice

Pick a backdrop of your own choice by clicking on the Backdrop Library icon which is next to the Sprite Library. For this game, we will go with Wetland to fit our theme:

Graphical user interface, application

Description automatically generated

3. Clone the Mole (Squirrel)

We’ll use one Squirrel Sprite. But we will clone it throughout the game to make it look as there are multiple “moles” popping up from the ground. Then we’ll pick a random spot for each new clone, but we will avoid the upper part of the Wetland backdrop. We’ll use show/hide blocks to make it more challenging for the player to “Whack-A-Mole”:

Graphical user interface, text, application

Description automatically generated

4. Customize the Sprite for Whacking

Our slightly customized Goalie Sprite will be used as the hammer in the game, to whack moles with. We’ll set it so that it is always following the player's mouse pointer as the game is played. The player will click on the Squirrel Sprite as it pops in and out of the ground, and the Goalie Sprite will switch between the two costumes upon every click. This part takes care of the whacking of the mole rule in the game:

Graphical user interface, text, application

Description automatically generated

5. Keep Track of Whacks

Click on Variables category on the left and create a new variable. Name it whacks. Each time the player “whacks” a mole by right clicking on one, the value of the variable will go up by 1. Since we created 10 clones, the player needs at least 11 whacks to win the game (the original Squirrel Sprite plus 10 clones of it from our Repeat 10 block). We set the value at 0 at the beginning of the game by placing that block right below When [green flag] clicked event block:

Graphical user interface, text

Description automatically generated

6. You Win! Sprite and Backdrop

And finally, we’ll work on the winning rule of the game. Remember, it takes at least 11 whacks to win, so we’ll add a the conditional if/then block and check for the score using a math block from the Operators category on the left. We will switch backdrops when this condition is true. And based on our backdrops, we will trigger an event to show the winning Sprite (Unicorn) with a message that the player has won. By contrast, we need to switch backdrops back to Wetland whenever the game starts again to bring our Squirrel and Goalie Sprites, and hide the winning Sprite Unicorn:

Graphical user interface

Description automatically generated
Graphical user interface, text, application

Description automatically generated

Remixes and examples of Whack-A-Mole games on Scratch

To make this game more original, you can use the drawing tools on Scratch to draw your own mole, hammer, and backdrop. You can also add sounds whenever a mole pops up from the ground or once it’s whacked. Check out the Sound tab and use Sound category for blocks. You can make the game run longer by creating more clones or you can add more animation to the winning Sprite and Backdrop.

Need a little more inspiration? Check out this unique Whack-A-Mole Scratch game by Hobson-TV, where the catchy background music fits the game but scoring a single point is impossible. And if you need an easy example on how to make your own backdrop for the game, a Scratcher by the name of infinitum3d has a very neat and easy to draw backdrop with what appears to be a field with holes in it.

Now you know how to make a Whack-A-Mole game in Scratch

The Whack-A-Mole game is not a complex game to play, therefore it shouldn’t be hard to program. Just like with any other program, the most important part of building something is understanding the concept and having a clear vision of every detail that makes up the logic behind it. All that’s needed for your Whack-a-Mole game is creativity!

Want to learn more about creating cool games in Scratch? Join us virtually at Create & Learn, where we offer the world’s best-in-class live STEM classes designed by Google and Stanford experts, including advanced Scratch, taught by experienced and passionate instructors.

Screen-Shot-2021-09-07-at-4.07.01-PM


Written by Sandra Dizdarevic, a Create & Learn instructor with 6 years of experience teaching STEM to children in the 3rd through 11th grade. She has an Undergraduate as well as a Masters Degree in Management Information Systems from UNO.