SCRATCH GOLD II
SCRATCH GOLD I
2 of 3

1.04 Repeat the sequence

Now you’re going to add four buttons the player has to press to repeat the colour sequence.

Add four new sprites to your project to represent the four buttons.

  • Edit the new sprites’ costumes so that there is one sprite in each of the four colours
  • Put the sprites in the same order on the stage as the costumes: red, blue, green, yellow
screenshot

Add code to the red sprite so that, when the sprite is clicked, it broadcasts a ‘red’ message to the character sprite:

red-drum

broadcast is like a message announced over a loudspeaker, which you can for example hear in schools or supermarkets. All of the sprites can hear the broadcast , but only the sprite whose job it is to respond will do something.

Add similar code to the blue, green, and yellow sprites to make them broadcast messages about their own colour.

Do you remember that the broadcast is like a loudspeaker message? You will add code to make it the character sprite’s job to respond to the broadcast messages.

When your character sprite receives the message red, the code should check whether the number 1 is at the start of the sequence list (which means that redis the next colour in the sequence).

If 1 is at the start of the list, the code should remove the number from the list, because the player remembered the correct colour. Otherwise it’s game over, and the code needs to stop all to end the game.

ballerina

Add to the code you just wrote so that a drum beat also plays when the character sprite receives the correct broadcast.

Duplicate the code you used to make your character sprite respond to the message red. Change the duplicated code so that it sends the message blue.

When the sprite responds to the message blue, which bit of code should stay the same, and which bit should change? Remember that each colour has a corresponding number.

Change the character sprite’s code so that the character responds correctly to the bluemessage.

Duplicate the code again twice (for the green and yellow buttons), and change the necessary parts so that the character responds correctly to the new broadcasts.

Remember to test the code! Can you memorise a sequence of five colours? Is the sequence different each time?

When the player repeats the whole colour sequence correctly, the sequence list is empty and the player wins. If you want, you can also display some flashing lights as a reward once the sequence list is empty.

Add this code to the end of your character’s when flag clicked script:

ballerina

Switch to the Stage, and import the drum machine sound or another sound you like.

  • Select the sprite you want to add the sound to.
sprite
  • Click the Sounds tab, and click Choose a Sound:
sounds and choose a sound highlight
  • Sounds are organised by category, and you can hover over the icon to hear a sound. Choose a suitable sound.
menu of sounds
  • You should then see that your sprite has your chosen sound.
new sound shown against the sprite

Add this code to play a sound and make the backdrop change colour when the player wins.

ballerina
×
×

Cart