 Have you been wondering how to make Flappy Bird a microbit? Well stick around because in this Scratch Flappy Bird game tutorial for microbit, we'll use inspiration from the original to create a Letty Bird in this multi-part series coming your way. Hello world, Surfing Scratcher here to help you surf a programmer bringing you the goodness of learning to code through video tutorials. If that sounds like something that you're into, consider hitting that subscribe button. Hit the show more button down below to check out a bunch of links that relate to this video. If you don't yet have a microbit, you can support this channel by getting yours through using the link in the description below. But hey, let's go make this game. Welcome to the Letty Bird tutorial. Just a couple of things to kick us off before we get underway. This tutorial is based on the game Flappy Bird that you can find on Scratch and Flappy Bird.io. Give full credit to the creator Don Newn and this is just an adaptation for the microbit. So here's a version of Letty Bird on the microbit simulator. I'm just going to get it underway and this dot here represents our Letty Bird. Our Letty Bird needs to find the gap between all these obstacles. We can press the A button and the B button to go down and through. If we collide with an obstacle, it's game over. Each obstacle that we pass through gives us a point. I'm assuming you already know how to connect your microbit and it is currently connected to your project. I'm working in a starter project that you can find in the description below, but you can just use an empty project as well. I've just got a few little bits here that will help illustrate some ideas. I've just got a couple of empty sprites here in the spray pane and I've got one called Plan. And that is essentially everything that we're going to need to do to build this game. Feel free to pause this video and have a crack at that now. Otherwise, strap yourself in. We'll be doing all of our code inside the empty game sprite. The first thing that we're going to create is a list called LEDs. And what that will be is a list of 25 values that will control the switches of the LEDs here. So the first five slots here refer to the top row. So I turn them all on using the simulator. You can see that the first five slots have been highlighted. So this is five to 10. This is 11 to 15 and so on. Back over in our project in the game sprite, make a list, call it LEDs. Our leds list is empty. So let's go ahead and populate it. To do that, I'm going to create a custom block and it's going to be called reset leds. I'm going to be using custom blocks quite a bit in this project. There's a card in the top corner, a few bit fuzzy on them. First, you want to delete all items of the leds. Then repeat for 25 times, adding the off switch. Let's go do that. You can see here, we've now got 25 items that are switched off. To display these leds on the micro bit, we need to go get the display stack block from the micro bits category. Then get your leds, report a block and stick it inside. Click that and it would work. I've just turned on the first five positions of our leds list. If I press this now, the micro bit should illuminate. Now if I reset the LEDs and I display that now, it should clear the display. I'm not a fan of sprinkling this stack block throughout our code. So I'm going to make a custom block here called render leds. We want to run it without screen refresh. And we're going to stick that stack block inside of it. So now we can call render leds whenever we want to force the display of the micro bit. The next thing that we want to be able to do is illuminate a specific column here. So what I'm talking about is when one full column is illuminated, we can say like, hey, column five, turn on all those switches. And we know that each position has an index, so we can refer to those. Let's go code it. Let's make a custom block. We're going to call it illuminate column and have the label here column number. Then we're going to add an input here and that will tell us the exact column. Press OK. Let's drag it over. Give yourself some space. We're going to need a variable for this. We're going to call it counter. It can be for this right only. We want to set counter to zero as soon as we call this function. And we want to repeat this five times once for each row. What we want to do next is multiply counter by the number five. So right now it should be zero times five. And we know that is equal to zero on a zone zero. Isn't that useful? But all you can do is add this value to the current column. So if the current column is one, it would be one plus zero. And that would refer to our very first slot here. Drag out an addition operator, slot in the counter times five. And then we're going to add the column to it. This piece of code here is going to refer to each index in the column that we want to refer to. Because we want to switch all these to one. Let's go do that now. Drag out a replace item block. And the item number that we want to replace is what we have just created. And what we want to replace it with is the number one so that we can turn it on. And let's put that now in there. And lastly, what we want to do is we want to increment that counter value by one. Okay, let's go test out what we've done. I've just got a little code stack block here where we're going to reset the LEDs. We're going to illuminate the first column, which is this one here. And then we're going to render those columns. So I'm going to click this blocks and watch what happens with the microbit. Boom, that first column illuminates. Let's illuminate that second column. Let's illuminate that third column. Let's illuminate that fourth column. And now the fifth column. So we've got our column illuminated now, but that's no good because in our game, we've got obstacles and obstacles have a gap for us to get through. The best way to do that is to refer to the row number. So for this obstacle, we can have the gap through row four of our array. Let's go code it. We're going to be using our counter variable because our counter variable essentially refers to each row of our microbit. Now our counter starts off at zero and we don't have zero row here. So we're just going to add one to counter. We need to be able to specify a row number in the function here. So let's right click and edit it and we can add a label. And that label is going to be called row gap or whatever you want to call it. Then we need to add an input and that's going to be the row number. So I'm just going to call that row num. Cool. Now if that counter plus one value is equal to the row number, we don't want to turn that switch to one. So what we can do is go counter plus one is equal to that row number is when we don't want to add it. So that is when it's not equal. Okay, drag out an if block and we're going to sandwich in the replace item, but not the change counter. We want to get that Boolean block that we just created and slot that inside the if statement. So what this will say now is if the counter plus one is not equal to the specified row number, then we're not going to eliminate it. All right, I've just got our little stack box here to test this out. So we're going to specify the fifth column and the fourth row of that. And there should be a gap as an obstacle now. And there is. All right, I think we're about ready to get our bird onto the micro bit. Bird can be in any position in the first column. So it can be on one, six, 11, 16 and 21, but it can't be on more and it can't go forward. So let's go ahead and code that. I've just dragged out our two half blocks here from the micro bit category when the A button is pressed and when the B button is pressed. When the A button is pressed, we want Ladybird to go up and when we press the B button, we want Ladybird to go down. Going to be using a variable for our Ladybird and it's going to be called bird position. And it's just going to be a number of the specific index where our bird is at. Just for now on a green flag click on going to set bird position to 11, which is the middle spot of our first column. So when we press the A button, we want to take away five from our bird position. Let's do that. When we press our B button, we want to add five. So let's just duplicate that and change it to five. Okay, I'm going to press the A button. Watch the bird position variable on the stage. It goes to six. Now it's one. Oh, now it's negative four. So we need to handle for that. I'm going to press the B button now and we've got our index updating beautifully, but we need to handle for a limit. So we don't exceed the number that it can go. All right, so the way we'll do this is we're going to get our bird position. And we're going to see if our bird position is not equal to the specific limit, then we can change the value of bird position. So what does that actually mean? So if we're going up, we know that the limit is one. So if the bird position is equal to one, then we no longer want to change the position by negative five. So if the bird position is not equal to one, then allow it to continue. Let's wrap that change block inside an if block and let's stick that boolean block inside the if block just like that. Let's duplicate and change it for our B press. Got some duplication going on here and this is a great opportunity to create another custom block. Click make a block. It's going to be called move bird by amount. And then we're going to give it a value of the amount. You're going to add a label and it's going to be called limit. And then we'll just give it a parameter of limit number. Cool. So what we can do is duplicate that code. And where we've got the amount value, we can just stick the amount in there. And where we've got the limit number, we can just feed it the limit. Now we can just get this one block here and move it by the amount that is in our code and specify the limit. We can do the same thing for a B button press. So we want to move it by five and the limit for our B is 21. And we can just get rid of those box of code. The neat thing about doing it this way is we can also set it up for keyboard testing because I'm a bit lazy and I can't always be bothered pressing the micro bit. So when the up arrow is pressed, let's just do the exact same thing. And then when the down arrow is pressed, let's just change the move amounts. Boom. So I'm just going to use the keyboard keys now to demonstrate this. As I press up, we've hit our limit of one and now I can't exceed it and go all the way down to 21 and we can't exceed it. At the moment, we're only changing an index value here, a number. What we need to go ahead and do is find that index position 21 and change it so it's one and then feed that back to our micro bit so we can update the led display. Just going to create a custom block and this one's going to be called draw leds. Click OK. We'll use this custom block to illuminate any of the columns as well as the position of our leddie bird. Let's first focus on leddie bird. Grab out the replace item block from the list category. We want to replace the item at the bird position with the number one. Recall earlier in the tutorial when I was using this little stack block sequence to force a display on the micro bit. Well, we're going to be using this and instead of calling render alerts at the end of it and instead of illuminating the column number, we're going to draw the leds after resetting them. Then we want to take these two blocks and find that render leds function and stick it inside. First, we want to reset the leds and then we need to draw the leds and then we can display them and that will be our render function. Lastly, we want to go ahead and render after we've moved the bird. Okay, I've got the micro bit in my hands now. I'm just going to press the A button and the B button. You can see our bird is moving up and down the first column. We might park it there for part one of our Laddie Bird tutorial. Here's what we've coded so far at a glance. In the next tutorial, we're going to be adding some animating obstacles. We need to detect some collisions and we also need to add some gameplay, such as starting and finishing the game as well as adding some score. It's time for a scratchy question and I want to know, did you find it helpful to have a plan set out in the project editor? Share your answer in the comment section below. Hey, thanks for checking out this Buffy Bird tutorial. Like, subscribe, ring the bell for me around here and have a scab of some of my other content on your screen right now. You can show your support for this channel by checking out exclusive content on my Patreon page, my funky red bubble tea, or by joining the mailing list. All links below in the description. But until then, I'm off to go find a way. I'll catch in the next one.