Leçon 1, Chapitre 1
En cours

Jeu Tire la chauve souris – Etape 5 : Paramétrer le jeu

Yann KIDSHAKER 18 mars 2026

Timer Script

Till now we’ve written the script for the bat and the aim sprite. Now it’s time to introduce the element for testing your ability to score as much as possible within a specified amount of time, i.e. the timer. To be honest, writing the script for the timer is no big deal, and is self-explanatory. So, let’s get onto it.

  1. The first step is… you know what it is: drag and drop the when () key pressed block and select the same key as before.
  2. The next step is to create a variable to keep track of the time. Therefore, go to the Variables palette and create a variable; name it Timer.
  3. Next, we must set the Timer to a certain value; let’s keep the time short and set the value to 60s. drag and drop the set () to () block and set the Timer variable to 60.
  4. We want the game to stop as soon as the timer reaches 0. For that, instead of using the forever block we’re going to use the repeat until () block. In the space of this block, drag and drop the () < () In the first space of this block drag and drop the Timer variable block and in the second space write 1.
  5. Next, inside the repeat until () block, drag and drop the wait () secs blocks and write 1. This makes sure that the value of timer is reduced every second.
  6. Below the wait () secs block drag and drop the change () by () block; in the first space drag and drop the Timer variable block and in the second space write -1. This makes sure that the value of timer is reduced by 1 second every second.
  7. Lastly, go to the Control palette and drag and drop the stop () block below the repeat until () block. select all from the drop-down menu of this block; this block will stop the game as soon as the timer’s value goes below 1.

Below is the complete script:

Script for Tracking the Score

Now comes the time to write the script for the fourth and the final element that makes a game a game: The Score. It is as important as timing of the game. So, let’s go ahead and write the script. Don’t forget to select the bat sprite this time. The score script must be written for the bat sprite because it concerns the bat.

  1. …You know what to do.
  2. Create a variable named Score for storing, well, the score.
  3. Next, go to the Control palette and drag and drop our dear old forever block; we don’t need a repeat block anymore because the timer has already taken care of it. The rest of the scripts must run for as long as the timer script is running.
  4. Now, drag and drop the if block inside the forever block. The if block if for checking whether the Aim sprite touches the bat or not. Drag and drop the touching () ? block inside the diamond-shaped space in the if block; the touching () ? block is in the Sensing palette. Select the Aim sprite (or whatever name you gave to that sprite) from the drop-down menu.
  5. Once the Aim sprite touches the bat, the bat must disappear. To implement this in the script, go to the Looks palette and drag and drop the hide block inside the if block. If you want, you can add a sound as well that will play every time the bat disappears. For that, go to the Sound palette and drag and drop the start sound () block above the hide block, and select any sound of your choice. Placing this block above the hide block would ensure that the sound is played when the Aim sprite touches the bat and not after it disappears.
  6. The score must increase every time the Aim sprite touches the bat. Therefore, drag and drop the change () by () block below the hide block; in the first space of the change () by () block drag and drop the Score variable block and in the second space write 1.

Below is the complete script: