Gain Points by Touching the Sprite

Add coed to the Sprite.Touched event.

Step 1

Add code that will increase the score by one every time the Sprite is touched. To do this, add code to the when Sprite.Touched event handler. 

Hover the mouse over the word “Score” in the Variable block. Pull out set global Score and snap it in the when Sprite.Touched block, above the call Catch_Sound.Play command block.

Step 2

Challenge: See if you can find the rest of the blocks you need to increase the score by one. 

Hint: you will need a Math block with a “+” symbol.

Step 3

To make the game show the new score, use the new UpdateScore Procedure block you created. Open the Procedures drawer, drag out a call UpdateScore block and snap it underneath the Vibrate command block.

Step 4

Program the Sprite to move away immediately after it is caught. Open the Procedures drawer, drag out a call MoveRandom block and snap it underneath the call UpdateScore block. 

The finished code should look like this:

Step 5

The program will now do the following things when the Sprite is caught:

  • Increase the score by one
  • Play a sound
  • Vibrate
  • Show the score on the screen
  • Move the sprite away

Try it on your phone now!