Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Raspberry Pi Projects for Kids
Raspberry Pi Projects for Kids

Raspberry Pi Projects for Kids: Start your own coding adventure with your kids by creating cool and exciting games and applications on the Raspberry Pi.

eBook
$14.99 $16.99
Paperback
$25.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Raspberry Pi Projects for Kids

Chapter 2. Making Your Own Angry Birds Game

In this chapter, we are going to make our own version of the popular Angry Birds game. What's more, when we're finished, we will be able to add all sorts of new rules and enemies to keep the game fresh. The following screenshot shows a completed version of our game:

If you haven't played Angry Birds before, here's a quick description of how the game works. The player launches a bird through the air using a slingshot and attempts to hit all of the pigs at the other end of the level. In order to make things more challenging, the pigs are often hidden behind hills or inside flimsy buildings that the player must knock down.

By creating our own version of the game, we have the freedom to change whatever we like. We can change the level design, decrease gravity, fire the bird faster (or bee, in our case), change all of the characters, and add new power-ups and prizes. The sky is the limit!

Scratch


In this chapter, we will use Scratch to create our game. Scratch is a programming language that has been specially designed to make animations and games with ease. Scratch Version 1.4 comes as standard with the Raspberry Pi but is also available on other computers. You can download it from http://scratch.mit.edu/ if you ever want to play your game away from your Raspberry Pi. Start up Scratch by double-clicking on its icon on the desktop (it should have the picture of a cartoon cat). The following screenshot shows the Scratch layout:

The following are its main sections:

  • Menu (1): This is where the options are to save and load your projects. If you ever want inspiration to code for projects, take a look at the provided examples by navigating to File | Open | Examples. Remember to save and back up your progress regularly!

  • Sprite controls (2): Every picture in the game is called a sprite. These buttons allow you to copy, remove, grow, and shrink sprites. To use them, click on the button...

Creating a character


To start our game, we will need a character to fling through the air. Angry Birds, of course, used birds as its main characters, but we can use whatever we like.

At the top of the sprite list, you should see the three buttons shown in the previous screenshot. The first lets you draw your own character, the second lets you use an existing image (including a wide range of images included with Scratch), and the third gives you a random image from Scratch's selection.

If you click on the first button, you will be shown the following window; it has plenty of easy-to-use options for creating your own drawings. Hover your mouse cursor over any of the buttons to see what they do.

The second button brings up a fairly standard file explorer with lots of neatly categorized images. This is the option I will use, but feel free to do something different.

Once you have drawn or selected a sprite, click on OK to add it to the game. If you choose not to use the default cat character, right...

Creating a level


Now, let's make the game look a little more interesting by adding some scenery with the following steps:

  1. At the left of the sprite list, you'll see a white rectangle called Stage. Click on it and then select the Backgrounds tab in the script area. Again, you have the option of drawing your own background or using a pre-existing image, but this time, I recommend creating your own so that you can make the level fun to play.

  2. Click on the Edit button. Try to keep your background as simple as possible; it will be easier to add extra objects (for example, the ground, trees, and clouds) as additional sprites later because then you will be able to move them around more easily. It is perhaps easiest to simply fill the background with a solid sky blue color (and maybe some distant mountains).

  3. Now back in the Sprite list, create sprites for all of the scenery you want in your game. At minimum, this will be the ground, but you can add all sorts of little details. With each sprite you create...

Moving the character


Now, let's start adding some code and making the game interactive! In this section, we'll do everything necessary to launch our main character using the slingshot.

Initialization

The first thing we want to do is make sure the position of our main character resets every time we start the game. Click on the main character and create the following script in the script area:

The code snippet states that when the green flag is clicked, the current sprite (the main character) will move to the same position as the slingshot.

Test that your code works by clicking on the green flag. You should see your character jumping to the same position as the slingshot. You may find that the character is behind the slingshot; if you would prefer for it to be in front, simply click on it on the Stage and drag it a short distance. Interacting with any sprite in this way will put it on top of all other sprites.

Moving with the keyboard

Now, let's allow the player to move the character around using...

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 towards 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 the y speed. Add the following code block inside the forever block of your second script:

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 more negative number will give stronger gravity. What happens if the number is positive?

Bouncing

Next...

Scoring


Now that our main character can be launched properly, it's time to give the player something to aim at. In Angry Birds, there are pigs, but we can have anything we like. Draw a new sprite or use an existing one in the same way we created the main character earlier. I am going to use a pre-made shark in this example. Resize the sprite and put it in a good position.

Do you remember how we checked to see when the main character hit the ground? We're going to need to do something very similar here to detect when an enemy is hit by the main character. The following is the main piece of code to detect collisions, and inside it, we're going to put all of the effects we want to happen when the enemy is hit. Make sure the enemy sprite is selected when you create this script—it controls the enemy's behavior and not the main character's. Note that we're using forever if rather than just if as we want to keep checking for collisions. Buzzy is the name of the sprite for my main bee character.

If...

Extensions


So far we have created the bare minimum for a game. There are all sorts of extra features we could add, such as the following:

  • Animation when two sprites collide

  • A special enemy that gives bonus points

  • Barriers that slow the player down

  • Power-ups that increase the player's speed or flip gravity, for example

  • Extra controls so the player can continue to affect the character after it has been launched

I will leave the rest of your game up to you, but here are some example scripts to give you some ideas. Try to work out what they do and where they might go, or just try them out! Some scripts may require minor modifications elsewhere to fit in properly.

Summary


In this chapter, we got to grips with the Scratch programming language. We learned that it can be easy to create animations, and we went as far as creating an entire game.

In the next chapter, we'll take our knowledge of Scratch and see how we can apply it to a different programming language called Python. There, we'll make another game and our own game controller to go with it.

Left arrow icon Right arrow icon

What you will learn

  • Learn how to set up your own Raspberry Pi device
  • Explore the world of programming by learning about Scratch and Python
  • Program with Scratch to develop your own version of Angry Birds
  • Get handson with some electronics to build your own reaction game
  • Develop with Python in order to build your own version of Google Maps
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 25, 2014
Length: 96 pages
Edition :
Language : English
ISBN-13 : 9781783982226
Vendor :
Raspberry Pi
Category :

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : Mar 25, 2014
Length: 96 pages
Edition :
Language : English
ISBN-13 : 9781783982226
Vendor :
Raspberry Pi
Category :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 113.97
Raspberry Pi 3 Home Automation Projects
$38.99
Raspberry Pi cookbook for Python programmers
$48.99
Raspberry Pi Projects for Kids
$25.99
Total $ 113.97 Stars icon

Table of Contents

4 Chapters
Getting Started with the Raspberry Pi Chevron down icon Chevron up icon
Making Your Own Angry Birds Game Chevron down icon Chevron up icon
Testing Your Speed Chevron down icon Chevron up icon
Making an Interactive Map of Your City Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(10 Ratings)
5 star 60%
4 star 20%
3 star 10%
2 star 10%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Norbert Varga Jun 04, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I’ve read this book on the weekend, and liked it very much. The author knows how to keep the attention of the reader (who is possibly a kid) through the book.The introduction section is pretty straightforward and well illustrated with photos, so anyone can understand how to power a Raspberry Pi up and install the operating system. The book’s structure is good, it’s nice that the introduction starts with using Scratch which I think is a very good tool to show kids how programming works. Building a simple Angry Birds clone with it is quite simple yet entertaining, and shows a lot of the capabilities of Scratch.The next chapter is about building a simple controller device and wiring it to the Pi. The author should have included some actual photos of the building process, not just schematic images, but at least those are fine and a crafted kid would be able to build it by reading the book. The Python examples are easily understandable and explain GPIO pin usage clearly. The interactive map chapter shows how to use GUI elements with a nice example using Google Maps API to download map images and displaying it in a self made application window. The chapter also explains how to interact with the window.I think Raspberry Pi Projects for Kids is a very cool book for a child who is interested in how programming works, and wants to try it out quickly and easily without being bored reading other science books about programming. If you have a child who might be interested, go buy this book (and a Pi)! :)
Amazon Verified review Amazon
Sam May 28, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As an Enterprise Architect focusing on Smart Building and sensors, I want my kids (7 year old John and 5 year old Emma) to have fun with electronics and computers, but I also want to keep it fun and also make sure they learn the basics of computing.This books is fantastic as it covers just enough details for setting up Raspberry Pi - it is very nice for a 7 year old to have a good instruction/steps to follow. The Scratch game projects are so much fun, having worked with Android and iOS game programming, I never thought gravity, physics, sprites can be so much fun !!!Also I am using my Samsung Galaxy Note 10.1 2014 editon tablet PACKT mobile application to read the ebook - it is a great reading experience.
Amazon Verified review Amazon
Randy May 26, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Nice book of projects to work on for the Raspberry Pi.
Amazon Verified review Amazon
bluelotus Jan 31, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I think this helped me more than my son. Perfectly explains each project and we're learning together!
Amazon Verified review Amazon
Romin K. Irani May 07, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book is compact, around 100 pages long and I believe aims to introduce kids to programming via the Raspberry Pi.The chapters are as follows :Setting up your Pi: This chapter is essential so that you get introduced to the Pi and also make sure that all is well with setting it up.Introduction to Scratch : This chapter is a nice introduction to Scratch. And I particularly loved the example project “Making Your Own Angry Birds Game” , which most kids will relate to (I mean even us Adults !)Testing Your Speed : I thought this chapter was the best. It combined the Raspberry Pi with a little project to build your own Hardware controller out of the most simple pieces of stationery and wire. The hardware controller was then used to write a game in Python, the code working with the GPIO pins on the Raspberry Pi. If the kids get this chapter, I think they will have a riot of ideas and will be able to adapt this application to several other scenarios from daily lives.Google Maps : The last chapter was an introduction to writing a program that integrates with Google Maps for your local area.To use the projects in the book, it is important that you do have a Raspberry Pi with you, setup with an internet connection. I do not believe that the kids need to have a programming background to pick up stuff, though some of the Python code does require an experienced programmer to explain things to them. In my opinion, the ideal age for kids in this book is around the 10-14 age group.Overall, this is a great book to introduce kids to Raspberry Pi and software/programming languages like Scratch and Python. I believe by mixing both hardware, graphical programming language and a text based programming language, it provides a flavor for everything to the budding programmer of tomorrow and is bound to help kids start thinking in multiple directions.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela