Book Image

Raspberry Pi Projects for Kids

By : Daniel Leonard Bates
Book Image

Raspberry Pi Projects for Kids

By: Daniel Leonard Bates

Overview of this book

Table of Contents (11 chapters)

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