5083+ reviews
Order by 16:00 for same day shipping
14 days return
GB
EN
Individual
Business
In this project I will explain to you step by step how to make a Flappy Bird game in Scratch.
About Flappy Bird:
The inspiration for this project comes from the game Flappy Bird. The game was released in 2013 for the mobile phone.
The game is about a bird that is constantly falling, you can let it fly by tapping on the screen. You have to guide the bird through the obstacles by tapping. It is not allowed to touch the obstacles. In the meantime, the score is kept. The goal of the game is to get the highest score possible.
This game became a huge craze. Since the game was removed from the Playstore, many replicas have been made. This is one of them!
What is Scratch?
Scratch is a programming program on your Raspberry Pi . In this program you work with function blocks. This means that you do not write the programming text yourself. The blocks with the functions have already been made for you. You put these blocks in a diagram yourself. If you have downloaded the Raspbian software on your Raspberry Pi Scratch should be automatically on your Pi. If not, you must download it.
I program in Scratch on the Raspberry Pi 4 with 4GB. You can also program on the Raspberry Pi 3B+. You can also use the 1 GB or 2 GB with the Pi 4.
Are you programming in Scratch 2.0? Then you can still follow this tutorial. Keep in mind that certain functions may be in a different place. The images may also look different than on your screen. You can follow this tutorial because the code is the same.
Because this is a long instruction I have divided the explanation in subheadings. This makes it easier to find where you left off.
Change language.
Your program is probably in English. To follow the steps properly, it is wise to change the language in your program. You can change the language by clicking on the “globe” at the top left of your screen. This icon can be found next to the Scratch logo. Select Dutch.
On the side of the Raspberry Pi 4B are two Micro HDMI ports. Insert the Micro HDMI cable into the left port, and the HDMI end into a monitor or display.
Connect a keyboard & mouse to the USB ports and finally insert the power cable into the USB-C port.
Your setup is now ready to be booted.
When the Raspberry Pi starts up now you will see a desktop on your monitor. When you first start it up you still have to set it up, but that is explained step by step.
1. Program your Sprite
First we are going to create our Sprite. But what is a Sprite? A Sprite is seen in Scratch as a kind of character. An object in the background can also be called a Sprite, like a building for example.
Now we can start with the code. First we are going to program our Sprite. In the game the Sprite falls down at a constant speed (gravity). You can keep the Sprite up by clicking on the screen.
Click on data, then click on create a variable. Name it Gravity. Check: Only for this Sprite. This is important, otherwise it won't work. Then click OK (Figure 1).
Go to movement and grab the “change Y by 10” block. Place it under the repeat block. Go to Data and replace the 10 with variables “Gravity”. Place “change gravity by 1” below it. Set the value to -0.8. The minus determines the direction your Sprite falls, in this case downwards. The number determines the speed. You can adjust these values to your own preference.
Your schematic will look something like this (Figure 2). For now, this is your Sprite code.
2. Create the obstacles
Now we are going to create the code so that you can see both versions of your Sprite on the screen at the same time. Now click on your new Sprite and go to scripts. Now you can create a code that only applies to this Sprite.
If you have used a different name for your Sprites, you should take that over.
3. Position the obstacles
The aim of the game is for the obstacles to move from right to left across the game. Therefore it is wise to start the buildings as far to the right as possible. You can adjust this yourself if you want to make the game a bit more difficult.
4. Move the obstacles
Now let's move the obstacles on the screen
What you have written so far: the bottom and top buildings appear. The Position of these buildings are indicated. If the X value is less than (in my case) -230 the clone is deleted.
Your code will look something like this (Figure 9):
Now we will change the height of the buildings by adjusting the Y position.
Then we create a random y position where the buildings are placed.
Do you find that your Sprite is too still while playing? Then we can add some kind of animation just like with the real flappy bird.
5. Loss of function
Then of course we need to add a loss function. Go to the code of your character.
Go to control and grab the stop all block and put it in the “if then” block. What you have written now means that the entire code stops when the sprite touches the (in my case) buildings.
6. Add background
Next to your created Sprites you will see the Playfield Background. Below the already created background you have the functions to create your own or choose one. Play around with this a bit.
7 Keeping Score
Go to your obstacle code.
If you test now you will see that the score goes up quickly, this is because the program quickly sees that the Sprite has gone through the obstacle. So it counts too long. We are going to make sure that it only adds 1 point.
Now you have created your own Flappy Bird game! Did you enjoy creating it? You can still expand the game. For example, you can add music and sound effects, or create multiple characters. You have already created the basis of the game and now you can completely customize the game to your own wishes. Have fun!