C++ Flappy Bird Clone

C++ Flappy Bird Clone

2018, Dec 01    

My Fundamentals of Computing course had an open ended final project as an assignment, and I chose to make a (simple) clone of the infamous Flappy Bird mobile game. The game itself is very simple, and similar to the classic Helicopter game. The user controls a bird by pressing space bar to jump. The bird is constantly falling due to gravity. The user must move the bird through an endless series of pipes. Passing through a pair of pipes increases the user’s score by one. The losing conditions are hitting a pipe or falling to the ground.

For this project, I created my a class for the objects of the game and used a provided graphics library. Within my class are two structs: one for a pipe and one for the bird. A difficult part of this project was generating pipes of random height and generating these pipes endlessly. To create a pair of pipes, I first generate a random height for the bottom pipe. The class contains a constant integer for the distance between pipes, so I just do a bit of math based on the screen size to calculate the height of the top pipe. There are a maximum of three pairs of pipes (6 pipe objects) on screen at a time. To endlessly loop the pipes, I check if a pipe has reached the leftmost part of the screen. If it has, I simply change the x-position of the pair of pipes to be a certain distance behind the current rightmost pair of pipes and generate a new, random height for the pipes. This way, the pipes endlessly cycle to the “back of the line”. The graphics are being run using XQuartz, which more or less mimics Apple’s old X11 features using an X server. The clone can also be run on any Linux machine using X graphics (rip Wayland users.)


This gif didn’t come out very smooth - try playing on your own machine! Here’s a link to the GitLab Repo.