Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

4. Tenere il punteggio


In this screencast, you’ll add a timer that will keep score for your game. The longer the player sprite avoids the chaser sprite, the higher the timer score. Watch this screencast first 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 timer variable 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 of the timer on the stage. The value of the timer block will always be the same as the value shown on the stage. When a player clicks the flag, the timer resets and 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 timer variable 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 of the 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 has been 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.

Much better!

The timer will be used to keep score, so the chaser should say the time if touching the player.

To make that happen, select the control menu, and drag an if statement into the forever loop you already programmed. Then, click on the “say” block with the timer 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 will serve as the condition of this if-statement. Change the value to the name of your “player” sprite. Remember, computer scientists test their code many times along the way to make sure it does what they expect. Go ahead and test yours now, and play your game.

Nice! If you want to make your game more challenging, add more chaser sprites by right clicking the 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 challenging in the add-ons.

arrow_backward Indietro
Avanti arrow_forward
  1. Fai sì che lo sprite Inseguitore indichi la quantità di tempo in cui lo sprite giocatore è sopravvissuto.
  2. Fai sì che lo sprite Inseguitore indichi la quantità di tempo in cui lo sprite giocatore è sopravvissuto se lo sprite Inseguitore tocca lo sprite Giocatore.
  3. Duplica lo sprite Inseguitore per creare più ostacoli da far evitare allo sprite Giocatore.