Skip to content

zak-off-zak/flappy-plus-plus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

106 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flappy-Plus-Plus

This project is a recreation of the iconic Flappy Bird Game using the SFML and C++.

greetings_screen

Overview

State Pattern

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 state
  • handle_input: handles the users input in regard to the current state
  • update: 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 time
  • render: 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.

Simple Newtonian Physics

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.

Collision Detection

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.

Game Mechanics

In this game following actions can be performed by a player:

  • SPACE - makes the bird flap once
  • ESC - toggles the menu
  • RESUME BUTTON - resumes the game after the menu was triggered
  • RESTART BUTTON - restarts the game (the current score is lost)

Running the project

Requirements

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

Building and Running using make

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.

Building and running using Cmake

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

Code Documentation

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.

References

SFML-Template

This project has been built on top of the SFML-Template. Please see instruction presented in the templates repository if any further questions arise.

Asset pack by Kenney Vleugels

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.

Inspiration

Some parts of this project were inspired by AI-Systems such as ChatGPT and Copilot. Those systems were also used during the debugging.

About

A simple SFML project recreating the iconic Flappy Bird in C++

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors