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. Enregistre le score

Transcript

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 Retour
Suivant arrow_forward
Instructions
  1. Fais "dire" au lutin Chasseur la durée de survie du lutin Joueur.
  2. Fais "dire" au lutin Chasseur la durée de survie du lutin Joueur si le lutin Chasseur touche le lutin Joueur.
  3. Duplique le lutin Chasseur pour créer plus d'obstacles à éviter pour le joueur.