Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Raspberry Pi Projects for Kids (Second Edition)
  • Table Of Contents Toc
Raspberry Pi Projects for Kids (Second Edition)

Raspberry Pi Projects for Kids (Second Edition)

By : Daniel Leonard Bates
4.4 (5)
close
close
Raspberry Pi Projects for Kids (Second Edition)

Raspberry Pi Projects for Kids (Second Edition)

4.4 (5)
By: Daniel Leonard Bates

Overview of this book

This book is for kids who wish to develop games and applications using the Raspberry Pi. No prior experience in programming is necessary; you need only a Raspberry Pi and the required peripherals.
Table of Contents (9 chapters)
close
close

Adding physics

The next thing for us to do is to give our character a more interesting flight path. The game would be too easy (and no fun) if we just flew in a straight line through all the obstacles.

Gravity

First, let's add some gravity. Gravity has the effect of pulling objects down toward the ground. How can we model gravity in our game? The answer lies in the way we split our speed into both x speed and y speed. Gravity will only affect y speed, our speed in the up-down direction, so we can leave x speed as it is. Since the y coordinate increases as we move up but gravity pulls us down, we want gravity to keep subtracting a small amount from y speed. Add the following code block inside the forever block of your second script:

Gravity

Try out the game now. You should arc through the air until you hit one of the edges of the screen. You may tweak the number in this code block if you wish; a higher negative number will give you stronger gravity. What happens if the number is positive?

Bouncing...

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Raspberry Pi Projects for Kids (Second Edition)
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon