0% found this document useful (0 votes)
2 views17 pages

OOP Project Report

This project report details the development of a Flappy Bird game using C++ and the SFML library, focusing on object-oriented programming principles. The game features a bird navigating through pipes, with mechanics for scoring and collision detection, and aims to provide an engaging user experience. The report outlines the project's objectives, system design, requirements, and implementation details, demonstrating the practical application of programming concepts in game development.

Uploaded by

230638
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views17 pages

OOP Project Report

This project report details the development of a Flappy Bird game using C++ and the SFML library, focusing on object-oriented programming principles. The game features a bird navigating through pipes, with mechanics for scoring and collision detection, and aims to provide an engaging user experience. The report outlines the project's objectives, system design, requirements, and implementation details, demonstrating the practical application of programming concepts in game development.

Uploaded by

230638
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Flappy Bird Game using Object Oriented Programing (C++)

And SFML Library

A PROJECT REPORT

Submitted by

Muhammad Rehan (230638)


Muhammad Hammad Nadeem (230680)

in partial fulfillment for the award of the degree

of

Bachelor of Computer Engineering 2023-28

SUBMITTED TO:

Dr. Mumajjed UL Mudassir

Department of Electrical and Computer Engineering

AIR UNIVERSITY ISLAMABAD


Project Report: FLAPPY BIRD GAME

TABLE OF CONTENTS

1 INTRODUCTION 3
2 OBJECTIVES 3

3 REQUIREMENTS 5
4 SYSTEM DESIGN 8

5 IMPLEMENTATION 12

6 RESULTS 15

8 CONCLUSION 15

9 REFERENCES 16

1
Project Report: FLAPPY BIRD GAME

ABSTRACT
This project presents the development of a Flappy Bird game using C++ and the SFML (Simple
and Fast Multimedia Library). Flappy Bird is a popular side-scrolling game where the player
controls a bird, navigating it through sets of pipes without hitting them. The goal of this project
was to recreate this game from scratch, focusing on object-oriented programming principles.
The game features essential components such as the bird, pipes, background, and scoring system.
The bird's movement is controlled by spacebar inputs, causing it to flap and ascend, with gravity
pulling it down otherwise. Pipes move horizontally across the screen, presenting obstacles for the
player to avoid. The scoring system increases the player's score each time the bird successfully
passes between pipes.
The development process involved designing classes for each game component, implementing
game mechanics, and ensuring smooth animation and collision detection. SFML was chosen for
its simplicity and efficiency in handling graphics, sound, and input, making it suitable for game
development in C++.
The final product is a fully functional Flappy Bird game that runs efficiently and provides an
enjoyable user experience. This project demonstrates the practical application of object-oriented
programming concepts and the capabilities of the SFML library in game development.

2
Project Report: FLAPPY BIRD GAME

1. INTRODUCTION
1.1 Background Information:

The realm of video game development is both vast and dynamic,


offering countless opportunities for creativity and technical innovation. Among the numerous
genres and game types that have captured the public's imagination, casual games have carved out
a significant niche. These games are designed to be easy to learn and play, often providing quick
and addictive gameplay experiences. One of the most iconic examples in this category is "Flappy
Bird."
"Flappy Bird" created by Vietnamese developer Dong Nguyen and released in 2013, quickly
became a global phenomenon. The game features a simple yet challenging premise: players control
a small bird that flaps its wings to fly between sets of pipes without hitting them. Despite its basic
graphics and straightforward controls, the game is known for its high difficulty level, which has
contributed to its addictive nature. Players are often driven by the desire to achieve higher scores,
which requires precise timing and coordination.
This project aims to recreate the "Flappy Bird" game using the C++ programming language and
the Simple and Fast Multimedia Library (SFML). SFML is a comprehensive and user-friendly
library that facilitates multimedia application development, including game creation. By
leveraging SFML, this project will effectively manage graphics rendering, sound, and user input,
providing a robust framework for developing a high-quality game.

2. OBJECTIVES
The primary objective of this project is to develop a clone of the popular Flappy Bird game using
Object-Oriented Programming (OOP) principles in C++ and the Simple and Fast Multimedia
Library (SFML). This project aims to provide a practical application of OOP concepts while
leveraging the capabilities of SFML for game development. Through this project, we seek to
achieve several key goals:
2.1 Understanding and Applying OOP Principles
Encapsulation:
Encapsulation involves bundling the data and methods that operate on the data within a single unit
or class. This project aims to demonstrate how encapsulation can be used to create modular and
maintainable code. Each game component, such as the bird, pipes, background, and score, will be
encapsulated within its own class. This ensures that each class manages its own state and behavior,
promoting code reusability and ease of maintenance.
Abstraction:
Abstraction involves hiding the complex implementation details and exposing only the necessary
functionalities. This project aims to apply abstraction by designing clear and simple interfaces for
each class. This will help in managing the complexity of the game and making the codebase easier
to understand and modify.

3
Project Report: FLAPPY BIRD GAME

2.2 Leveraging SFML for Game Development


Graphics Rendering:
SFML provides powerful tools for rendering graphics in a window. This project will use SFML to
draw the game elements, such as the bird, pipes, and background, onto the screen. By utilizing
SFML's sprite and texture classes, we aim to create smooth and visually appealing graphics that
enhance the gaming experience.
Event Handling:
Handling user input is crucial for an interactive game. SFML offers a robust event handling system
that allows us to capture keyboard and mouse events. This project will use SFML to detect when
the player presses the space bar to make the bird flap its wings. Proper event handling will ensure
that the game responds accurately to user inputs, providing a responsive and enjoyable gameplay
experience.
Game Loop Management:
The game loop is the core of any game, managing the flow of the game by continuously updating
and rendering the game state. SFML facilitates the creation of an efficient game loop. This project
will implement a game loop that handles events, updates the game state, and renders the graphics
in a continuous cycle. A well-designed game loop is essential for maintaining a smooth frame rate
and ensuring that the game runs seamlessly.
Collision Detection:
Collision detection is a critical aspect of game development, determining whether the player
character has collided with obstacles. SFML provides tools to check for collisions between sprites.
This project will implement collision detection to determine when the bird collides with pipes or
the ground, triggering game-over conditions. Accurate collision detection will add to the challenge
and excitement of the game.
Sound Management:
Sound effects play a vital role in enhancing the gaming experience. SFML supports audio
playback, allowing us to add sound effects for actions such as the bird flapping its wings or
colliding with obstacles. This project will integrate sound effects to create a more immersive and
engaging game environment.
2.3 Creating a Modular and Maintainable Codebase
Class Structure:
The project will be structured into several classes, each responsible for a specific aspect of the
game.
The main classes will include:
Game Class: Manages the main game loop, event handling, and state transitions.
Bird Class: Represents the player-controlled bird, handling its movement and rendering.
Pipe Class: Represents the obstacles, managing their positions and rendering.

By organizing the code into these classes, we aim to create a modular and maintainable codebase

4
Project Report: FLAPPY BIRD GAME

that can be easily extended or modified in the future.


Code Reusability:
One of the key objectives is to write reusable code. By adhering to OOP principles, we will create
classes and methods that can be reused across different parts of the game or even in future projects.
For example, the collision detection methods can be reused for any game that involves interacting
objects.
Ease of Maintenance:
A well-structured codebase is easier to maintain and debug. This project aims to demonstrate best
practices in coding, such as clear naming conventions, comments, and separation of concerns. By
following these practices, we ensure that the code remains understandable and maintainable, even
as the project grows in complexity.
2.4 Delivering an Engaging Game Experience
Gameplay Mechanics:
The primary objective is to deliver a game that is fun and engaging. The Flappy Bird game
mechanics are simple yet challenging, providing a rewarding experience for players. This project
will focus on fine-tuning the gameplay mechanics to ensure that the bird's movements feel natural
and the difficulty level is balanced.
User Interface:
A clean and intuitive user interface is essential for a good gaming experience. This project will
design a simple UI that displays the score, game-over messages, and other relevant information.
The UI will be integrated seamlessly with the game, providing a cohesive and enjoyable experience
for players.
By achieving these objectives, this project aims to provide a comprehensive understanding of game
development using OOP in C++ and SFML. It will not only demonstrate the practical application
of programming principles but also deliver an engaging and enjoyable game that showcases the
capabilities of SFML.

3. REQUIREMENTS
1. Development Environment
To develop the Flappy Bird game, you need a suitable development environment that supports
C++ and SFML. This includes:
IDE (Integrated Development Environment):
Recommended: Visual Studio, CLion, Code:: Blocks, or any other C++ IDE with support for
SFML.
Compiler:
A C++ compiler that supports modern C++ standards (C++11 and above). GCC, Clang, or MSVC
are suitable options.
SFML Library:
Download and install SFML (Simple and Fast Multimedia Library) from SFML's official website.

5
Project Report: FLAPPY BIRD GAME

Ensure that the library is correctly linked to your project.


2. Project Setup
Project Structure:
Organize your project into directories for source files (src), header files (include), and assets
(assets).
Ensure the project is configured to include the SFML headers and link the SFML libraries.
3. Core Game Components
The game requires several core components to be implemented as classes using OOP principles:
Game Class:
Manages the main game loop, event handling, and game state.
Initializes and maintains game objects such as the bird, pipes, background, and ground.
Handles the rendering of all game objects and updates the game logic.
Bird Class:
Represents the player's bird character.
Handles bird movement, including flapping and falling due to gravity.
Manages the bird's position, velocity, and collision detection.
Pipe Class:
Represents the obstacles in the game.
Manages the creation, movement, and rendering of pipes.
Handles collision detection with the bird.
4. Game Assets
The game requires various graphical and textual assets:
Textures:
Background image (bg.png)
Ground image (ground.png)
Bird image (bird.png)
Pipe images (pipe_up.png and pipe_down.png)
Fonts:
A font file (arial.ttf) for displaying text such as the score and game instructions.
5. Game Logic and Mechanics
The game must implement several key mechanics to ensure a functional and engaging experience:
Game Loop:
A continuous loop that processes user input, updates the game state, and renders the game frame
by frame.
User Input:
Keyboard input to control the bird's flapping (space bar) and restart the game ( mouse click).
Physics:
Gravity effect that causes the bird to fall.
Bird flapping to move upwards.
Collision detection to determine game over conditions when the bird hits a pipe or the ground.

6
Project Report: FLAPPY BIRD GAME

Scoring System:
A system to track and display the player's score based on the number of pipes successfully passed.
6. Collision Detection
Implement collision detection to determine when the bird hits a pipe or the ground:
Bounding Box Collision:
Check for intersections between the bird's bounding box and the bounding boxes of pipes and
ground.
7. User Interface
Design a simple and intuitive user interface:
Score Display:
Display the current score on the screen using the loaded font.
Restart Prompt:
Display a "RESTART GAME!!" prompt when the game is over.
8. Resource Management
Efficiently manage game resources to ensure optimal performance:
Loading Assets:
Load all textures and fonts at the start of the game to avoid loading delays during gameplay.
Memory Management:
Properly manage memory for dynamic objects such as pipes to prevent memory leaks.
9. Error Handling and Debugging
Implement basic error handling and debugging:
Error Messages:
Display error messages for failed asset loading.
Debugging Tools:
Use debugging tools provided by the IDE to step through the code and identify issues.
10. Documentation
Provide thorough documentation for the project:
Code Comments:
Comment the code to explain the functionality of classes, methods, and key sections.
Example Code Overview
Here's an example structure of the main components implemented in the provided code:

7
Project Report: FLAPPY BIRD GAME

4.SYSTEM DESIGN
The Flappy Bird game will be developed using Object-Oriented Programming (OOP) principles
in C++ and the SFML (Simple and Fast Multimedia Library) for multimedia handling. The system
design includes defining the core components, their interactions, and the overall architecture of the
game. This design will ensure that the game is modular, maintainable, and extendable.

Core Components:
1. Game Class
2. Bird Class
3. Pipe Class
4. Resource Management
5. Collision Detection
6. User Interface

8
Project Report: FLAPPY BIRD GAME

UML Classes Diagram:

Detailed Class Explanations:


1. Game Class:
Attributes:
win: The main game window where everything is rendered.
is_entered_press: A boolean flag to track if the game has started.
run_game: A boolean flag to track if the game is running.
pipe_counter: Counter to track when to spawn new pipes.
pipe_spawn_time: Time interval to spawn new pipes.
score: The current game score.
monitering: A boolean flag to track scoring conditions.
bg_texture: Texture for the background image.
bg_sprite: Sprite for the background image.
ground_texture: Texture for the ground image.

9
Project Report: FLAPPY BIRD GAME

ground_sprite1, ground_sprite2: Sprites for the ground image.


font: Font used for displaying text.
restart_text: Text displayed for restarting the game.
score_text: Text displayed for the score.
bird: Instance of the Bird class.
pipes: Vector of Pipe objects.
Methods:
Game(sf::RenderWindow& window): Constructor to initialize the game.
StartGameLoop(): Main game loop to handle events, update game state, and render.
check_collision(): Checks for collisions between the bird and pipes or ground.
do_processing(sf::Time& dt): Processes game logic, including bird movement and pipe spawning.
Draw(): Renders the game objects to the window.
moveground(sf::Time& dt): Moves the ground for a scrolling effect.
restart_game(): Restarts the game by resetting game state.
check_scorce(): Checks and updates the score.
tostring(int num): Converts an integer to a string.
Here a Game. cpp screenshot is added for more detail

2. Bird Class:
Attributes:
bird_sprite: Sprite for the bird.
bird_texture: Texture for the bird.

10
Project Report: FLAPPY BIRD GAME

should_fly: Boolean to check if the bird should fly.


velocity: Current velocity of the bird.
Methods:
Bird(): Constructor to initialize the bird.
flap_bird(sf::Time& dt): Handles the bird's flapping motion.
update(sf::Time& dt): Updates the bird's position based on physics.
setshould_fly(bool): Sets the flying state of the bird.
getright_position(): Returns the rightmost position of the bird.
resetbird_position(): Resets the bird's position to the start.

Here a screen shot is added of Bird Class for more detail.

Pipe Class
Attributes:
sprite_up: Sprite for the upper pipe.
sprite_down: Sprite for the lower pipe.
pipe_texture_up: Texture for the upper pipe.
pipe_texture_down: Texture for the lower pipe.
move_speed: Speed at which the pipes move.
Methods:
Pipe(float position): Constructor to initialize the pipes.
update(sf::Time& dt): Updates the position of the pipes.
getright_bound(): Gets the rightmost bound of the pipes.
load_texture(): Loads the textures for the pipes.
The Game class is instantiated and initializes all necessary game objects (bird, pipes, background,
ground) and loads resources (textures, fonts).

11
Project Report: FLAPPY BIRD GAME

Game Loop:
The StartGameLoop method runs continuously while the window is open.
Event Handling: The game processes user inputs (keyboard and mouse events) to control the bird
and handle game restart.
Game Logic: The do_processing method updates the game state, including bird movement, pipe
spawning, and collision detection.
Rendering: The Draw method renders all game objects to the window.
Collision Detection:
The check_collision method checks for collisions between the bird and pipes or ground to
determine game over conditions.
Score Management:
The check_scorce method updates the score based on the bird's position relative to the pipes..
Game Restart:
The restart_game method resets the game state, including the bird's position, pipe positions, and
score, allowing the game to restart.

5. IMPLEMENTATION
This section details the implementation of the Flappy Bird game using C++ and SFML, following
the system design discussed above. We will implement the core components: Game, Bird, Pipe
classes, and then integrate them into the main game logic.
1. Project Structure:
Here a screenshot added to understand the project structure

2. Implementation Details:
1.1 Game Class:

12
Project Report: FLAPPY BIRD GAME

Here the screenshots are added to understand the physics and environment of class:

2.2. Bird Class:


Handles the bird's behavior and physics.

13
Project Report: FLAPPY BIRD GAME

2.3. Pipe Class:


Handles the Pipes's
behavior and
physics.

14
Project Report: FLAPPY BIRD GAME

6. RESULTS
After doing all the steps one after the other our Project is ready. Here some screenshots that show
our project result that is it work properly or not.

7. CONCLUSION
In conclusion, the development of the Flappy Bird game using C++ OOP principles and the SFML
library has been successfully executed, resulting in a fully functional and engaging gaming
experience. This project report has outlined the comprehensive design and implementation process
undertaken to realize the game's key features, including its core components, mechanics, and user
interface.
The main objective of this project was to create a Flappy Bird game using Object-Oriented
Programming and SFML. This objective has been achieved by implementing the following key
components:
• Developed a robust game loop to handle user input, update game state, and render graphics
using SFML.
• Utilized OOP principles to create modular and reusable classes for the bird, pipes,
background, and game management.
• Integrated SFML for multimedia handling, including graphics rendering, window

15
Project Report: FLAPPY BIRD GAME

management, and event handling.


• Implemented user input mechanisms for controlling the bird's flight and restarting the
game.
• Incorporated graphical assets for the game's visuals and used SFML's audio capabilities for
sound effects (not detailed in this report).
The project included the implementation of essential game components, such as the Bird, Pipe,
and Game classes, each fulfilling specific roles in the game's operation. The Bird class managed
the player's character, while the Pipe class handled the creation and movement of obstacles. The
Game class orchestrated the overall game flow, managing game states, scoring, and collision
detection.
Technical aspects, including resource management, collision detection, and game physics, were
meticulously addressed throughout the implementation process.
While the current implementation meets the project's requirements, there are opportunities for
further enhancements and refinements. Future iterations of the game could include additional
features.
In conclusion, the development of the Flappy Bird game has been a valuable learning experience,
demonstrating the application of OOP principles and SFML in game development. The project has
provided insights into game design, implementation, and optimization, laying the groundwork for
future projects and endeavors in the field of software development and game design.

8. REFERENCES
All the following resources are used both making project and project report.
▪ SFML Documentation
▪ Visual Studio
▪ ChatGPT
▪ Visual Studio Community
▪ SFML Library

16

You might also like