6.4. Adding a Score and Timer to the game

View

To add the score and the timer, you must understand the need for pauses between actions within loops. Then you will have to understand the timing of each action and the use of the sensing block to trigger the next action. We are going to use an example of a game to get more understanding of how each component works in the game creation.

We are going to use the same example as we used in the previous section. 

The cat will chase the mouse and when the cat catches the mouse, the game is going to record the score and give a meow sound and say some “Thank you God for this food”. The game will continue recording the number of times the cat will catch the mouse for 10 seconds. During the game, the timer will be set and count to 10 seconds and the game will stop and check the score. The winner is the one with the highest score at the end of the game


Cat                                                                                     Mouse

 

 

Figure 172: Setting a timer

We have created 2 variables. The score variable that is going to record the number of times the cat is going to catch the mouse. And then the timer that is going to contains the specific time in seconds of the duration of the game.

At the beginning of the game, we set the timer to 10 seconds, and then the cat and the mouse are going to run in the scene for 10 seconds and the game will record how many times the mouse was caught. The time will be removed (-1) 1 on the set time every after one second.

 

Figure 173:  The mouse was caught 6 times in 10 seconds

 

This means that the mouse was caught 6 times in 10 seconds. That is how you create a variable and use it in the game creation. There are a lot of options created depending on the nature of the game.

Last modified: Tuesday, 1 March 2022, 1:25 PM