Reader small image

You're reading from  Raspberry Pi Projects for Kids (Second Edition)

Product typeBook
Published inApr 2015
Reading LevelBeginner
Publisher
ISBN-139781785281525
Edition1st Edition
Languages
Right arrow
Author (1)
Daniel Leonard Bates
Daniel Leonard Bates
author image
Daniel Leonard Bates

Daniel Bates is a computer science researcher at the University of Cambridge. His day job involves inventing designs for future mobile phone processors and when he gets home, he likes playing games or working on one of his coding projects (or both!). Daniel has been a volunteer for the Raspberry Pi Foundation since 2011 and is enthusiastic about introducing new people to computing. He has previously written Instant Minecraft: Pi Edition Coding How-to and Raspberry Pi Projects for Kids (First Edition), both published by Packt Publishing.
Read more about Daniel Leonard Bates

Right arrow

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 premade 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 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 everything...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Raspberry Pi Projects for Kids (Second Edition)
Published in: Apr 2015Publisher: ISBN-13: 9781785281525

Author (1)

author image
Daniel Leonard Bates

Daniel Bates is a computer science researcher at the University of Cambridge. His day job involves inventing designs for future mobile phone processors and when he gets home, he likes playing games or working on one of his coding projects (or both!). Daniel has been a volunteer for the Raspberry Pi Foundation since 2011 and is enthusiastic about introducing new people to computing. He has previously written Instant Minecraft: Pi Edition Coding How-to and Raspberry Pi Projects for Kids (First Edition), both published by Packt Publishing.
Read more about Daniel Leonard Bates