Book Image

Raspberry Pi Projects for Kids (Second Edition)

By : Daniel Leonard Bates
Book Image

Raspberry Pi Projects for Kids (Second Edition)

By: Daniel Leonard Bates

Overview of this book

Table of Contents (14 chapters)

Ending the game


The problem now is that you bounce around forever. We want the bouncing to stop at some point, and a good time to do this is when the character hits the ground. This is easy to do in Scratch with the following code:

Add this inside the forever block, and the script will end when the character sprite hits the ground sprite (you will need to choose the name of the sprite that you used for the ground). Since this script is in control of the character's movement, ending the script ends the movement, which is what we wanted.

Give your physics of the game a final test by playing the game. Your character should fly through the air while being pulled downwards by gravity, bounce off the edges of the screen, and stop when it hits the ground. This is how your second script should now look: