# Crashy Bird

25

## Introduction: Crashy Bird

You will need: A computer
A micro-bit A miro USB cable That is all you will need, but preferably you should have the whole Micro-bit kit to do this. To do the coding you also need to go to the website makecode. If you are not familiar with this website you should try it out.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Make the Bird

To make the bird you should first make a variable "bird" then you got to the category "variables" and scroll down and you will find "set sprite to "blank" " then go to "game" and you will find "create sprite at x blank, y blank". Set x at 0 and y at 2. Now you should have a dot there but we want to make it blink so it is more interesting. So we go back to the variable category and there you should find " blank set blank to" on the blank you go back to variables and put "bird" at the first blank and in the second block choose blink. The code should look like the image up top.

## Step 2: Make the Bird Move

So we want the bird to go up and we want the bird to go down. To do that is simple, you go to "input", there you will find "on button A pressed" you should put that in your code. Then go to the category called "game" there you will find "sprite change x by 1" take that and put it inside "on button A pressed" then change the x to y and the 1 to -1. Do the same but change the A in "on button A pressed" to B and change the -1 to 1. That should let you move your bird. The picture of the code will be on the images above.

## Step 3: Make the Obstacles

Ok, this will be a long and very complicated step. So let's get started. To start with this we need all the obstacles in one array or a line. So we are going to make a variable called "obstacles" after that you should scroll down to find the button "set (choose the variable) to (blank)" you should choose the variable as "obstacles" and then you should go to the category "arrays" there you should scroll down to find "empty array" you should take that and put that into the blank space. Then you want the obstacles to be random, and also want a hole in the obstacles for the bird to go through. To do that we are going to make the hole first. We are first going to make a variable called "emptyobstacle". Then we are going to use the same "set (choose the variable) to (blank)" in the variable we are going to use the variable "emptyobstacles" in the blank we are going to go to the category "math" there you should have "pick random from 0 to 10" take that and put it in the blank. Then change the 10 to a 4. Now, this allows the hole to be random. We are now going to make the "for" loop to make an obstacle for every open space in the array. To do that we go to the category loops and there we have a "for index from 0 to 4 do" we need this one so, we put it under "on start" then we go to logic and take the "if true then" and put it in the "for index from 0 to 4" then we go back to the logic category and take the "blank=blank" and we replace true with it. On the first blank we put "index" and on the second blank we put "emptyobstacles". and we change the "=" to the not equal" sign. After that, we go to the "array" category and then take "add a variable add value blank to end" we choose the variable as "obstacles" then we go to the "game" category and there we take "create sprite at x: blank, y: blank" then we put that in the blank. After that, we replace the blank in the game category, we replace the x blank with 4 and the other one with index. Now you should have a bird and obstacles. The code will be up in the images and check if you did this correctly.

## Step 4: Make the Obstacles Move

Now we need the obstacles to move because then the game can go on. So now to do that first, we need to need to create another variable "obstacles". Then we go to the loop category and there we take the "for element blank of choose a variable do" then we put that in "forever" and then we go to the game category and we take "choose a variable change x by blank" we choose the variable as "obstacle" and we put -1 in blank. Then we go to the category "basic" and there we put " pause ms blank" and we replace the blank with 200. There is the 4th step. The image of the code will be up top.

## Step 5: Make the Obstacles Disappear

We now need to make the passed obstacles disappear. To do that we need to first need to go to the "loop" category and there take the "while blank do" and put it in the "forever" then we need to go to logic and put the "blank and blank" in the blank. Then we need to go back and put the "blank = to blank" in both blank of the logic block. Then we need to go to the "array" category and there we take the "length of array blank" and we replace the blank with the variable "obstacles" and we change the equal sign to greater than and we write 0 in the blank. Then we go to "game" and take "blank x", then go to logic and get the same block as before, then we go to "array" and take "get value at blank" we put 0 at the blank. then we put = and replace the blank with 0. Then go back to the "game" and get "delete blank". Then we go to the "array" category and find "blank remove value at 0" and put that into the blank. Now this will make the obstacles disappear at x=0 and the game will not be limited with the number of obstacles. The picture of the code will be on the top.

## Step 6: Generate More Obstacles

We now have to generate more obstacles, so to do that we need to put all the code that is related to obstacles in the forever block. Now we need to have space in between the obstacles and to do that we just need to add ticks. We can do that by going to the "variables" category and putting in "change ticks by 1" and we also put that in the forever block and then we should have spaces between the obstacles. The forever block is going to be in the image up top.

## Step 7: Game Over

We now need the game to end if the bird touches the obstacles. To do that we need to now fo to "loop" category and there we need to take "for element blank of blank do" Then we need to put the variable "obstacle" in the first blank and then in the next blank we need to put the variable "obstacles". Now we need to go to the category "logic" and take " if true then do" and put that in do. Then we go back to the "logic" and get "blank and blank" and we replace it with true. Then we take "blank = blank" from the logic category and put it in both blanks. Then we go to "game" and take "sprite x" and put that into the first blank of the "blank = blank" and we take it again and put that into the other blank too. Then we change the first sprite with the variable bird and the other sprite with the variable obstacle. Then in the other blank of the "blank and blank" we do the same but we change the x to y for both the variables. After that, we go to the game category again and take the game over block and put it in the block "if then" under "then". Now your game ends when the bird touches the obstacles. This code should also be in the forever block. The picture of this code will be on the image at the top.

## Step 8: The Fall of the Bird

Now we also need the bird to fall so it is harder for the player. You can do that by going to the game category and taking the "sprite change x by 1" and change "sprite" with the variable bird and x to y and put that in forever. The final Code will be in pictures. Some changes you can make is having a song in the background or having a score counter.

## Recommendations

236
29 5.7K
36 4.9K
TIG Welding Class

340 Enrolled