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.
Add code to the red sprite so that, when the sprite is clicked, it broadcasts
a ‘red’ message to the character sprite:
A
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.broadcast
Add similar code to the blue, green, and yellow sprites to make them
messages about their own colour.broadcast
Do you remember that the
is like a loudspeaker message? You will add code to make it the character sprite’s job to respond to the broadcast
messages.broadcast
When your character sprite receives the message red
, the code should check whether the number 1
is at the start of the
list (which means that sequence
is the next colour in the sequence).red
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.
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
. Change the duplicated code so that it sends the message red
blue
.
When the sprite responds to the message
, which bit of code should stay the same, and which bit should change? Remember that each colour has a corresponding number.blue
Change the character sprite’s code so that the character responds correctly to the
message.blue
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
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.sequence
Add this code to the end of your character’s when flag clicked
script:
Switch to the Stage, and import the drum machine
sound or another sound you like.
Add this code to play a sound and make the backdrop change colour when the player wins.