Posted on

Scratch Coding – Animal Noise Reaction Timer

We are going to build a game that will test our reaction time, the player will hear an animal noise and will be given 2 seconds to click on the correct sprite to score a point. Each time the round resets the animals will move to a random location.

Sprites

We start by selected three animal sprites, these will already have the correct sounds attached to them.

We can resize these sprites to fit into the screen nicely.

Starting our Game:

We are going to use the Scratch the Cat sprite to tell the player how to play the game. We are going to setup our game a little bit different to normal games as we want to be able to keep repeating the game until the player fails.

We are going to first create a ‘score’ variable to keep track of the player score.

We then broadcast a message called ‘Start’.

We will have scratch the cat tell the player they have two seconds to click on the animal. Our ‘Receive message’ hat block is now working just like the green flag hat block.

We need to keep track of the animal that is going to be making the sound. To do that we will create another variable called ‘RandomAnimal’. We will set this variable to a random number between 1 and 3 (since we have three animals).

We will then broadcast the random number that got selected.

Animal Sprites:

Our animals will listen for their number to be broadcast. When it comes through, we will play the animal sound.

I’ve made my dog number 1:

The cat number 2:

The horse number 3:

If we test our game now, we will see that a random animal will start making noises.

Clicking on our sprites

We want our player to click on the sprite when the noises are made, on each of the animal sprites we are going to use the ‘when clicked on’ hat block. We need to check to see if the ‘RandomAnimal’ variable contains the same number as our clicked on animal.

We also need to check to see that the player clicked on the animal within two seconds.

My Dog sprite (number 1) looks like:

My Cat sprite (number 2) has:

And my Horse (number 3) has:

Notice how we also broadcast the ‘start’ message after the player has correctly guessed the animal? This will restart the game again.

Make the animals move to a random position.

Our animals can move to a random position when the start message is broadcast:

Put this on each of the animal sprites.