Scratch exercise 26


Health/lives countdown

In this exercise we will give the cat 9 lives. The Cat will be chased by a bee. Every-time he's stung by it the Cat will lose a life. When all his lives are lost the game will end.


Complete these steps ..


1. Open Scratch, OR create a new game (from the top menu choose "File>New").



2. Re-name sprite1 "Cat", then click the "only face left-right" button to stop the Cat turning upside down ..



3. Click the "Paint new sprite" button under the stage and paint a new sprite of a bee (or other animal or object that might attack the cat). Re-name it "bee".



4. Add the first script to the Bee to give it its starting position and size ..

Notice how we are using "b" for begin to start the script.


Now add the script to make the Bee chase the Cat and pause for 2 seconds when it touches the Cat ..



5. Select File>Save as to save your game. Name it "Health countdown" ..



6. Select the Cat sprite again, then select "Variables" and then create a new variable for all sprites. Name it "Cat lives" ..



7. We need to add the scripts to allow the player to control the Cat.

First add the script to allow us to end the game using the "e" key, and the script to set the Cats starting position and size ..


Now add the script to control the movement with the arrow keys on your keyboard ..


Finally, add the script that takes away lives when the Bee touches the Cat ..



8. Add this scripts to the Bee to set it's start position and size ..


Add these scripts to the Bee to make it chase the Cat ..



9. Press the "B" key to test your game. Use the arrow keys to move the Cat.

When you are ready press "E" to end your game.



10. Use "File>Save" to re-save your game.


Well done, you're finished!

If you want to create a health bar to show health you will find instructions here.