In this screencast, you’ll add a timer that will keep score for your game. The longerthe player sprite avoids the chaser sprite, the higher the timer score. Watch this screencastfirst to see how to add a timer, then try it on your own.
To start, click on the chaser sprite and find the “timer” variable in the sensing menu.
For example, the timervariable stores the time the game has been played.
See the check box next to the timer variable? When you click it, it displays the value ofthe timer on the stage. The value of the timer block will always be the same as the valueshown on the stage. When a player clicks the flag, the timer resetsand starts running from zero. To start, drag out the timer variable.
When the chaser sprite catches the player, the chaser sprite will need to say the score.
Click on the looks menu, drag out a “say for 2 seconds” block, and place the timervariable inside it.
Test this now by running the program and clicking on the “say” block.
Whenever you click on the “say” block, the chaser sprite should say the value ofthe timer. Remember, variables hold values. So instead of saying the word “timer,”the chaser sprite will say the number stored in the timer, which is how long the game hasbeen played.
Hmm.. You might notice that the chaser never stops saying the score. To fix this,add an empty "say" block after the "say for 2 sec" block.
This clears the text that the sprite is saying and makes the "say" bubble disappear.
The timer will be used to keep score, so thechaser should say the time if touching the player.
To make that happen, select the control menu, and drag an if statement into the foreverloop you already programmed. Then, click on the “say” block with thetimer inside that you created earlier, and drag it into this if statement.
Finally, create a condition for this if statement, such as:Click Sensing, and drag out a "touching" block that willserve as the condition of this if-statement. Change the value to thename of your “player” sprite. Remember, computer scientists test their codemany times along the way to make sure it does what they expect. Go ahead and test yoursnow, and play your game.
Nice! If you want to make your game more challenging, add more chaser sprites by right clickingthe chaser sprite and selecting “duplicate.”
You might want to name your game too!
This project is going to be called "Moon Chase."
You can continue to explore different ways to customize your game and make it more challengingin the add-ons.