Tuesday, 17 May 2016

BBC Micro:Bit Flappy Birds

BBC Micro:Bit Flappy Birds
Another game requested by my students, this is possibly getting to the complexity that they will struggle to understand some of the code, but hopefully we might be able to lead them towards the WHAT has to happen rather than the HOW it happens.


The first thing I added was the 'bird' to move up and down the screen...



This is quite a large amount of code to begin with, but the logic is that IF I am pressing button A, I want the bird to move upwards on the screen. IF I am NOT pressing A, I want the Bird to 'drift' downwards.


I have created the bird in the position shown because I want to give the player time to react to the obstacle, but I have not worked out how to delete sprites (YET) so they have to remain in the column of X=0


The second part of the game is the obstacle. I didn't really manage a huge amount of fiddling with this game, so I pretty much created the code as is... apologies to any readers of this who find it a lot at once...

The code above creates the sprite in a random place at the right hand side of the screen. There are different methods to then move the sprite across the screen, I chose to just run a loop to get it to move the right number of spaces.


(I have omitted to show the 'On A+B pressed' option from now on because it is complete.)

This piece of code should get your sprite moving laterally across the screen. It just needs an IF to make the game finish when the Bird is hit.



This game, then, worked fine. Until I decided that I could always just leave the sprite at the bottom, only moving it when an obstacle came across the bottom of the screen. This made it really easy.


I, therefore, added the following piece of code to run 'Forever' alongside everything else which made the game time out If I was on the bottom, or on the top of the screen for too long. This took a lot of fiddling and was a right pain to crack but I got there.



Missing from this all is a timer or some score contraption, maybe every 2000Ms I could add a point.


The complete code looks like this...