SCRATCH GOLD II
SCRATCH GOLD I
2 of 3

4.03 Gain points or lose lives

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.

Red dot sprite

Add this script to your ‘red’ sprite to create a new clone of the sprite every few seconds:

Red dot sprite

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.

screenshot

Create a new list called start positions, click the list’s (+) icon to add the values -180 and 180.

Red dot sprite
List of 180 and -180
  • Click on Make a List under Variables.
Make a list
  • Type in the name of your list. You can choose whether you would like your list to be available to all sprites, or to only a specific sprite. Click OK.
List name
  • Once you have created the list, it will be displayed on the stage, or you can untick the list in the Scripts tab to hide it.
List show/hide
  • Click the + at the bottom of the list to add items, and click the cross next to an item to delete it.
List show/hide
  • New blocks will appear and allow you to use your new list in your project.
List blocks

Then you can hide the list by unselecting this box:

Hide the list

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.

Red dot sprite

This new code chooses either -180 or 180 for the x and y positions, meaning that each ‘dot’ sprite clone starts in a corner of the Stage.

Test your project. You should see red dots appear in the corners of the Stage and move slowly towards the controller.

screenshot

Create two new variables called lives and score.

Red dot sprite

Add code to your Stage to set the lives variable to 3 and the score to 0 at the start of the game.
Stage sprite

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:

Stage sprite

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.

  • 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
Red dot sprite

Test your game to make sure that:

  1. You lose a life if you don’t match a dot with the correct colour
  2. You score a point if you match a dot correctly
×
×

Cart