7. Catch bugs¶
In this practice we are going to program a game that consists of catching all the beetles that appear on the screen. Once trapped, we win the game and a character tells us about it.
We start the Scratch editor.
Press the language button in the top bar and choose English.
We delete the cat object by clicking on the trash can icon.
Now we choose a suitable backdrop for our game. Changed the backdrop to a street wall.
Press the button choose a backdrop .
We look in the Exteriors section.
and select the backdrop Wall 1.
Next we add a new character, a beetle.
Press the button choose an object .
We look in the Animals section.
and select the Ladybug2 object.
Now we will create the variable clones that will count the number of beetles on the screen. When this variable is equal to zero, the program will end.
We change the name of the variable to clones
Finally, click on the OK button.
We make a program that hides the beetle, reduces its size, resets the number of clones to zero, and places ten clones of the beetle on the screen.
At this point we add the instructions to have each clone of the beetle appear in a random place on the screen and increase the number of beetles by one.
When the mouse pointer touches the beetle, one is subtracted from the beetle counter and the beetle disappears.
Press the green flag to test the operation of the program.
Ten beetles should appear on the screen. The beetles should disappear when the mouse pointer touches them, without clicking.
In order for the game to work normally, we programmed the function that will spawn new beetles from time to time. When the number of beetles on the screen is zero, the game ends and the program stops.
Finally we are going to program a character that warns of the end of the game. In this case we can choose Casey.
Press the button choose an object .
We look in the People section.
and select the Casey object.
We select the new character
and add the following instructions.
Press the green flag to test the operation of the program.
Now, at the end of the program, Casey will appear dancing to congratulate us on winning.
Challenges¶
- Add a new rule to the game. If the number of beetles is greater than 25, then we lose the game. The program stops and a new character tells us that we have lost.
- Add more costumes to the beetle character, so that a different costume appears with each clone, using the "next costume" command in the appropriate place.