Now you’re going to add some dots that the player needs to collect.
Create a new sprite called ‘red’. This sprite should be a small red dot.
Add this script to your ‘red’ sprite to create a new clone of the sprite every few seconds:
If you click the green flag now, it looks like nothing is happening. This is because all of the cloned sprites are hidden, and they appear in the same place.
You are going to add code to make each new clone appear in one of the four corners of the Stage.
Create a new list called start positions
, click the list’s (+)
icon to add the values -180
and 180
.
Then you can hide the list by unselecting this box:
Notice that the coordinate for each corner of the Stage is a combination of 180
and -180
. This means you can use the list to pick a corner of the Stage at random.
Add this code to the ‘dot’ sprite to make each new sprite clone appear in a random corner and then slowly move towards the controller sprite.
This new code chooses either
or -180
for the x and y positions, meaning that each ‘dot’ sprite clone starts in a corner of the Stage.180
Test your project. You should see red dots appear in the corners of the Stage and move slowly towards the controller.
Create two new variables called lives
and score
.
Add code to your Stage to set the
variable to lives
3
and the
to score
0
at the start of the game.
Add this code to the end of the Stage’s script to make the game end when the player loses the last of the lives:
The player should win points for catching dots, and should lose lives for failing to catch dots. A dot can only be caught by matching the colour of the controller to the colour of the dot.
Go back to the ‘red’ dot sprite’s Scripts area to add some code blocks to the end of the sprite’s when I start as a clone
script.
First, make the dot clone move 5 steps
so that it overlaps the controller.
Then add code to either add 1
to score
if the colour of the dot clone matches the colour of the controller when they touch, or to take 1
away from lives
if their colours don’t match.
Test your game to make sure that: