This project is a recreation of the iconic Flappy Bird Game using the SFML and C++.
This project utilizes a simplified version of the state pattern.
Each state of the game is implemented as a septate class regarding the logic declared in the GameState interface. Each of the states implements following methods:
init: initializes and creates a new statehandle_input: handles the users input in regard to the current stateupdate: updates all of the objects of the state, that can be seen on the screen, based on the previous user interactions and a point in timerender: renders all of the drawable objects
The Game class servers the role of the context in this project. It holds all of the "global" variables, that are relevant for all of the game states (for instance game_over indicates if the current game has been lost or is still in progress). Moreover, the Game class holds of all of the textures and fonts used by the different states. Therefore, all of the textures and sprites are loaded only once and not on every state change. Additionally, the Game class provides the functionality to switch and interact with the states. Lastly, the Game class contains the main game loop.
The states are stored on a stack. This allows an easy switch between them by using the pop and push functionality. Moreover, this enables to "pause" the game by pushing a new state to the top of the stack without loosing the progress in the game itself. Most of the state transitions logic is contained inside of the states making it more flexible for the future development.
The Physics class includes some simple logic to model the behavior of a physical object inside of the 2D world. The implementation relies on the basic Newtonian Laws of motion. Using the functionality of this class an object of a certain mass can be created. Afterwards a force can be applied to it, that will make it gain acceleration and velocity and, therefore, change its position.
In order to prevent the object from gaining the velocity indecently it was clipped to some fixed value.
The functionality of this class has been used in the Bird class in order to model a realistically looking falling of the bird. On the other hand, the Pipe class does not used the functionally of the Physics class, as the pipes do only need a constant speed to be managed by the program in order to be rendered correctly. Consequently, the used of the Physics class would be an overkill in this case.
Even thought, the full potential of the Physics class has been used in the rest of the project, it was still a generate exercise in modelling the real life physics.
The collision detection has been implemented on top of the functionality provided by the SFML-Library, as it makes it possible to check, whether two rectangles overlap. Any collision of the bird with the frame of the window or with any of the pipes will cause the game over.
In this game following actions can be performed by a player:
SPACE- makes the bird flap onceESC- toggles the menuRESUME BUTTON- resumes the game after the menu was triggeredRESTART BUTTON- restarts the game (the current score is lost)
Please install the SFML-Library before building and running the project. The installation guide can be found on the SFML-Website. For instance, mac users can install it easily with brew by running:
brew install sfml
This project includes the 'Makefile' containing a set of instructions for building and running the game. In order to build and run one can just use:
make
The executable will be placed in the ./build/bin/main.
In order to build the project please run the following commands:
cmake -B build
cmake --build build
cp -r assets ~
After building the project it can be run using the following command:
./build/bin/main
For wiping the assets please use the following:
rm -rf ~/assets
This project has been documented using the Doxygen. For generating the documentation from code please use the following command:
doxygen Doxyfile
After the generation is completed, the documentation can be found in the ./docs/generated/html/index.html.
Only the header files have been documented using Doxygen. The code of this project also includes comments in the *.cpp for clarity.
This project has been built on top of the SFML-Template. Please see instruction presented in the templates repository if any further questions arise.
This project uses the assets kindly provided by by Kenney Vleugels (www.kenney.nl). Licenses can for all of the used assets packs can be found in the assets folder of this project.
Some parts of this project were inspired by AI-Systems such as ChatGPT and Copilot. Those systems were also used during the debugging.