Part 4 - It's not Flappy Bird without a flap #
So far our bird image is very static and the game should probably just be called “Bird”. Let’s fix that now.
If you click on the images button in Mu you will see there are several bird images. So far we’re using “bird1” for the living bird, and “birddead” for the bird ghost. We can also use “bird0” to liven things up a bit!
- Add this code at the end of the update function:
# Animation
if barry_the_bird.alive:
if barry_the_bird.speed > 0:
barry_the_bird.image = "bird1"
else:
barry_the_bird.image = "bird0"
- Pay attention to the indentation here!
Any line that ends in a colon, like a function or an if statement, has indented lines underneath it that belong to it. In our code, the indented lines under if barry_the_bird.alive: only run when Barry is alive. The next indented line under if barry_the_bird.speed > 0: only runs when he is falling.
The else keyword means “do this instead” when the if statement is false. So our new code is using the “bird1” image when flying downwards (remember that we measure from the top of the screen, so a positive speed means going down), and using “bird0” when flying upwards.
If this still feels confusing, ask a mentor now.