Learn to Code via Tutorials on Repl.it!

← Back to all posts
Make flappy bird with Python Play 🐦

Make flappy bird with Python Play

Demo and Code 👨‍💻

Flappy bird is one of the classics - and as you'll see, super easy to create, especially when you use the Python Play library developed at repl.it!

If you haven't played flappy bird before, try it out on flappybird.io!

🎓 So, how exactly does flappy bird work?

There are two objects which matter in the game - the bird and the pipes. In the demo above, the bird is the yellow circle, while the pipes are the blue rectangles.

The bird remains in the same x position for the entire game, but can move up when the player presses a key, and continues to fall due to gravity.

The pipes are two rectangles with a gap between them - the bird needs to get through the pipes without touching them.

🛣️ Get started

Let's begin by forking repl.it/@jajoosam/play-start - Which is just a python environment with the play dependency installed.

Let's start off creating flappy bird by creating a yellow circle to represent the bird:

Running that code will result in a yellow circle, close to the top left corner of the screen with a radius of 30:

🌎 Physics is... easy!

We want our bird to be affected by gravity, and bounce back up when it falls to the bottom of the screen. So let's create a whole physics engine to do that!

lol jk, just add this one line to your code: bird.start_physics()

yep, that's it. really!

If you run your code now, you'd see a yellow circle falling down, and bouncing back up! We want to be able to make our bird flap though - make it jump when we want to.

We can use play.repeat_forever to run a function every frame of our game - and in this case, if the up arrow key is pressed, our bird's y coordinate increases by 7.5

🚬 Let's roll the pipes

We're going to create pipes in sets of two, for blocking our birds - and store all of them in a list.

Near the top of your code, add a new line to create this empty list.

We want the two pipes we generate each time to have different height, and a gap in the middle. We also want to generate the next pair of pipes after a random duration, to make the game more unpredictable.

It'll be very useful for us to use python play's random_number function here.

Add this entire block of code, just before play.start_program()

This code is inside an async function - which is why we can use the await keyword to delay each call by a particular duration, with play.timer - this lets us create new boxes at an interval!

With play.new_box - we create a new pipe and then append it to the boxes list too. Try playing around with the parameters we supply to this function. they should be understandable!

But if you run the code now, you'll notice that everything is the same as before 😕

🖥️ Bring the pipes to the screen

Since all our pipes are in the same boxes list, we can move all of them pretty easily, by looping over the list.

Adding this block to your code, under def do(): makes the boxes move through the screen!

This is what you should see when you hit run!

🤔 But... when do you lose?!

I'm really going to sell you on python play by explaining how we can detect collisions.

bird.is_touching(box) - that's it. No cap 🧢

In our same loop, where we're moving the pipes to the left, just add this condition block:

If the bird ever touches the pipe, it's color shall be red!

Also add this block in the loop:

We're just preventing memory leaks with this - if our pipe is out of the screen, let's just remove it!

🔮 Things to hack on

  • Use pixel art of a bird instead of the yellow circle 👨‍🎨
  • Restart the game when the bird touches the pipe ☠️
  • Add power-ups to the game 💪
  • Add a live score to the screen 💯

Be sure to put down any questions or improvements down in the comments 💬

And here's all the code for you to go over again - I've annotated it for you too 😄


Hey, I really want to learn coding and programming would u guys help me?
or interduce me with a site which teaches you what to do and how to start?


@Emran23 hey me too man, wanna start a multiplayer program and learn together?








Thanks really cool :)


Hi I'm a really big fan of yours! I'm 10 y/o and pretty good with python! I love your programs and it's cool that you're 16 but still make all these cool things! When I'm done with them can you check out my programs? They're not too good but still pretty neat! Also, my InfoBot 1.0 got deleted so I'm remaking it. I used your Weather API tutorial to help me!

Thanks, Tristan



Hey Tristan! Thanks a ton :)
I'd be very happy to check out the programs you've made, and I'm glad my tutorials helped! Please reach out if you ever need help making something!


so great!


This really seems like... even if it isn't



cool I am also working on a Flappybird


Love it, it's definitely important to know how to do this properly and efficiently, clients LOVE these.https://8balls.io