Flappy Bird
Flappy Bird
Submitted by:
1| P a g e
Contents
Abstract ........................................................................................................................... 4
Introduction ..................................................................................................................... 5
Project Overview ........................................................................................................... 5
Game Mechanics ........................................................................................................... 5
Project Goals ................................................................................................................. 6
Game Development Process ..............................................................................................7
Planning and Design.......................................................................................................7
Programming ................................................................................................................... 8
Implementing Game Mechanics .................................................................................... 8
Collision Detection ........................................................................................................ 8
Scoring .......................................................................................................................... 8
Game State Management............................................................................................... 9
Testing and Debugging .................................................................................................. 9
Iteration and Refinement .............................................................................................. 9
Technical Implementation ............................................................................................... 10
Programming Language and Tools ............................................................................... 10
Game Architecture ....................................................................................................... 11
Data Flow Diagrams (DFDs) ......................................................................................... 11
Types of DFDs ........................................................................................................... 11
Basic Notations Used in DFDs ................................................................................... 12
Key Features and Implementation................................................................................ 16
Challenges and Solutions ............................................................................................. 18
Collision Detection .................................................................................................... 18
Game Performance .................................................................................................... 19
Level Design .............................................................................................................. 19
2| P a g e
User Interface .......................................................................................................... 20
Game Design and Aesthetics ........................................................................................22
Visual Design ...............................................................................................................22
User Interface ..............................................................................................................23
Evaluation ...................................................................................................................... 24
User Testing and Feedback.......................................................................................... 24
Achievements and Limitations .................................................................................... 24
Technical Implementation Details .................................................................................. 26
Code Snippets ............................................................................................................. 26
FlappyBird.java ...................................................................................................... 27
Screenshots .................................................................................................................. 35
Future Updates for Flappy Bird ...................................................................................... 38
Gameplay Enhancements ......................................................................................... 38
Visual and Audio Enhancements .............................................................................. 38
Social Features ......................................................................................................... 39
Technical Improvements .......................................................................................... 39
Conclusion ..................................................................................................................... 40
References .................................................................................................................. 42
3| P a g e
Abstract
This project presents the development of a Flappy Bird game using
Java programming language. The game's objective is to guide a bird
through gaps between pipes, avoiding obstacles to achieve a high
score. The project involved planning, designing, programming,
testing, and iterating on the game's mechanics, visuals, and sound.
Key aspects of the development process include implementing
collision detection, scoring, and game state management. The game
was designed with a focus on simplicity and addictive gameplay,
utilizing basic graphics and sound effects. The project successfully
achieved its goal of creating a playable and engaging Flappy Bird
game, providing valuable experience in Java programming and
game development principles.
4| P a g e
Introduction
Project Overview
The Flappy Bird game is a popular mobile game that has gained
widespread recognition for its simple yet addictive gameplay. The
player controls a bird by tapping the screen to flap its wings,
navigating it through gaps between pipes while avoiding collisions.
The game's success can be attributed to its intuitive controls,
visually appealing design, and the challenge of achieving high
scores.
Game Mechanics
The core gameplay of Flappy Bird revolves around the following
mechanics:
• Bird Control: The player controls the bird's flight path by
tapping the screen. Each tap causes the bird to flap its wings,
propelling it upwards. The player must carefully time their
taps to avoid colliding with pipes or the ground.
• Pipes: Pipes are randomly generated and appear on the screen
in pairs. The gaps between the pipes vary in size, increasing
the difficulty as the game progresses. The player must
accurately manoeuvre the bird through these gaps to continue
playing.
5| P a g e
• Scoring: The player earns points for successfully passing
through each pair of pipes. The higher the score, the more
challenging the game becomes.
• Game Over: The game ends if the bird collides with a pipe, the
ground, or the top of the screen.
Project Goals
The primary objectives of this project were to:
• Reinforce Java Programming Skills: Apply and solidify
understanding of Java programming concepts, including
object-oriented programming, data structures, and algorithms.
• Develop Game Development Expertise: Gain practical
experience in game development, encompassing game design,
programming, and testing.
• Create a Functional Flappy Bird Clone: Replicate the core
gameplay mechanics and features of the original Flappy Bird
game.
• Explore Game Design Principles: Apply game design
principles such as level design, difficulty balancing, and user
experience to create a satisfying and engaging game.
• Enhance Problem-Solving Abilities: Overcome technical
challenges and develop problem-solving skills through the
iterative process of game development.
6| P a g e
Game Development Process
Planning and Design
The initial phase of game development involves careful planning
and design to establish the foundation for the game.
• Brainstorming Ideas
This stage involves exploring various game concepts and ideas.
Consider factors such as the target audience, desired gameplay
experience, and available resources. For Flappy Bird, the concept of
a simple yet addictive game involving a bird navigating pipes was
chosen.
• Creating Game Concepts
Once a promising idea is identified, it is essential to refine it into a
concrete game concept. This includes defining the core gameplay
mechanics, the player's objective, and the overall game flow. For
Flappy Bird, the concept involved a bird controlled by tapping,
navigating through pipes, and earning points based on successful
passages.
• Designing Visual Elements
Visual elements play a crucial role in creating an immersive and
enjoyable gaming experience. This includes designing characters,
backgrounds, and other visual assets. For Flappy Bird, the visual
7| P a g e
design focused on simplicity, featuring a minimalistic style with
contrasting colours to enhance visibility.
Programming
8| P a g e
Game State Management
Game state management involves keeping track of the game's status,
including the player's score, the position of the bird and pipes, and
whether the game is ongoing or over.
9| P a g e
Technical Implementation
Programming Language and Tools
Java:
• Object-Oriented Programming (OOP): Java's OOP paradigm
allows for modular and reusable code, making it well-suited
for game development.
• Platform Independence: Java's "Write Once, Run Anywhere"
(WORA) principle enables games to run on various platforms
(Windows, macOS, Linux) without recompilation.
• Strong Type System: Enforces type safety, reducing the
likelihood of runtime errors.
• Extensive Standard Library: Provides a rich set of classes
and interfaces for common programming tasks, including
input/output, networking, and data structures.
Java Development Kit (JDK):
• Java Compiler: Converts Java source code into bytecode,
which can be executed by the JVM.
• Java Virtual Machine (JVM): Interprets and executes
bytecode, making Java platform-independent.
• Java Runtime Environment (JRE): Includes the JVM and
necessary libraries for running Java applications.
Integrated Development Environment (IDE):
• Code Editing: Provides features like syntax highlighting, code
completion, and error checking.
10| P a g e
• Debugging: Allows developers to step through code, inspect
variables, and identify errors.
• Build Automation: Automates tasks like compiling, testing,
and packaging.
• Version Control Integration: Supports integration with
version control systems like Git.
Game Architecture
The Flappy Bird game is structured using a modular approach,
dividing the code into well-defined components:
Data Flow Diagrams (DFDs) are visual representations of the flow of data
within a system. They are used to model the system's processes, data stores, and
external entities. DFDs are particularly useful in the early stages of system
analysis and design.
Types of DFDs
1. Physical DFD:
o Focuses on the physical implementation of the system.
11| P a g e
2. Logical DFD:
o Focuses on the logical functions of the system.
12| P a g e
Data Flow Diagram
Game Loop
The game loop is the heart of a game, continuously running to
update the game state and render the scene. It typically follows
these steps:
1. Input Handling: Processes user input (keyboard, mouse,
gamepad) to control game objects.
2. Game Logic Update: Updates the state of game objects, such
as the bird's position, velocity, and pipe movement.
13| P a g e
3. Physics Simulation: Applies physics principles (gravity,
collision detection) to the game objects.
4. Rendering: Renders the current game state to the screen,
updating the positions of objects and drawing graphics.
5. Timing: Controls the game's frame rate and ensures smooth
gameplay.
Game Objects
Game objects represent the entities in the game world. In Flappy
Bird, the primary objects are:
• Bird:
o Manages the bird's position, velocity, and acceleration.
o Handles input to control the bird's flight.
o Detects collisions with pipes and the ground.
• Pipe:
o Represents a pair of pipes.
o Manages the pipe's position, movement, and visibility.
o Handles collision detection with the bird.
• Background:
o Represents the game's background.
o Manages scrolling the background as the bird moves.
Physics Engine
14| P a g e
The physics engine simulates the physical laws of the game world.
For Flappy Bird, a simple physics engine can be implemented to
handle:
• Gravity: Applies a downward force to the bird, causing it to
fall.
• Bird Movement: Calculates the bird's new position and
velocity based on user input and gravity.
• Collision Detection: Determines if the bird collides with pipes
or the ground.
Rendering Engine
15| P a g e
Input Handling
16| P a g e
• Randomization: Pipes are generated randomly, with varying
gaps between them.
• Movement: Pipes move from right to left at a constant speed.
• Recycling: To optimize performance, pipes can be recycled
once they move off-screen.
Collision Detection
• Bounding Box Collision: A simple and efficient method for
detecting collisions between rectangular objects.
• Pixel-Perfect Collision: A more accurate but computationally
expensive method, especially for complex shapes.
• Collision Handling: When a collision is detected, the game
ends, and a game over screen is displayed.
Scoring System
• Point Accumulation: The player earns points for each pair of
pipes passed successfully.
• Score Display: The current score is displayed on the screen.
• High Score: The highest score achieved is recorded and
displayed.
Game Over
• Collision Detection: The game ends when the bird collides
with a pipe or the ground.
• Game Over Screen: A game over screen is displayed, showing
the final score and a "Play Again" button.
17| P a g e
• Restart: The game can be restarted by clicking the "Play
Again" button or pressing a specific key.
Collision Detection
Challenges:
Solutions:
18| P a g e
hierarchical tree structure, reducing the number of collision
checks.
Game Performance
Challenges:
Solutions:
• Optimization Techniques:
o Object Pooling: Reusing objects to reduce memory
Level Design
Challenges:
User Interface
Challenges:
Solutions:
20| P a g e
• User Testing: Gathering feedback from users to identify
usability issues and make necessary improvements.
21| P a g e
Game Design and Aesthetics
Visual Design
A well-designed visual aesthetic can significantly enhance the
player experience. Here are some key considerations:
• Colour Palette:
o Choose a limited colour palette that complements the
game's theme.
o Use contrasting colours to make important elements like
the bird and pipes easily distinguishable.
o Consider using a soothing colour palette to reduce eye
strain during long play sessions.
• Character Design:
o Design a simple yet iconic bird character.
o Use animation techniques to bring the bird to life and
make it more appealing.
• Background Design:
o Create a simple, repeating background that adds depth
and atmosphere to the game.
o Consider using parallax scrolling to create a sense of
motion and depth.
• Font Selection:
22| P a g e
o Choose a clear and legible font for the score display and
other text elements.
o Use a font that complements the game's overall aesthetic.
User Interface
A well-designed user interface is crucial for a positive gaming
experience. Here are some key considerations:
• Menu Screen:
o A simple and intuitive menu screen with clear options for
starting a new game, viewing high scores, and adjusting
settings.
o Use visually appealing buttons and icons.
• In-Game UI:
o A minimal and unobtrusive UI that displays essential
information like the player's score and high score.
o Use a clear and concise font for the score display.
• Game Over Screen:
o A clear and concise game over screen that displays the
final score and a "Play Again" button.
o Consider adding a leaderboard or social sharing features
to encourage player engagement.
23| P a g e
Evaluation
quantitative data.
• Analyzing Feedback:
o Identify common pain points and areas of improvement.
experience.
24| P a g e
• Cross-Platform Compatibility: The game can be played on
various platforms (desktop, mobile) without significant
modifications.
Limitations:
25| P a g e
Technical Implementation Details
Code Snippets
The project utilizes two principal Java classes within the main
application package named FLAPPYBIRD: app.java and
FlappyBird.java.
app.java
import javax.swing.*;
FlappyBird.java
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.*;
27| P a g e
//images
Image backgroundImg;
Image birdImg;
Image topPipeImg;
Image bottomPipeImg;
//bird class
int birdX = boardWidth/8;
int birdY = boardWidth/2;
int birdWidth = 34;
int birdHeight = 24;
class Bird {
int x = birdX;
int y = birdY;
int width = birdWidth;
int height = birdHeight;
Image img;
Bird(Image img) {
this.img = img;
}
}
//pipe class
int pipeX = boardWidth;
int pipeY = 0;
int pipeWidth = 64; //scaled by 1/6
int pipeHeight = 512;
class Pipe {
int x = pipeX;
int y = pipeY;
int width = pipeWidth;
28| P a g e
int height = pipeHeight;
Image img;
boolean passed = false;
Pipe(Image img) {
this.img = img;
}
}
//game logic
Bird bird;
int velocityX = -4; //move pipes to the left speed (simulates bird moving right)
int velocityY = 0; //move bird up/down speed.
int gravity = 1;
ArrayList<Pipe> pipes;
Random random = new Random();
Timer gameLoop;
Timer placePipeTimer;
boolean gameOver = false;
double score = 0;
FlappyBird() {
setPreferredSize(new Dimension(boardWidth, boardHeight));
// setBackground(Color.blue);
setFocusable(true);
addKeyListener(this);
//load images
backgroundImg = new
ImageIcon(getClass().getResource("./flappybirdbg.png")).getImage();
birdImg = new
ImageIcon(getClass().getResource("./flappybird.png")).getImage();
29| P a g e
topPipeImg = new
ImageIcon(getClass().getResource("./toppipe.png")).getImage();
bottomPipeImg = new
ImageIcon(getClass().getResource("./bottompipe.png")).getImage();
//bird
bird = new Bird(birdImg);
pipes = new ArrayList<Pipe>();
//game timer
gameLoop = new Timer(1000/60, this); //how long it takes to
start timer, milliseconds gone between frames
gameLoop.start();
}
void placePipes() {
//(0-1) * pipeHeight/2.
// 0 -> -128 (pipeHeight/4)
// 1 -> -128 - 256 (pipeHeight/4 - pipeHeight/2) = -3/4 pipeHeight
int randomPipeY = (int) (pipeY - pipeHeight/4 -
Math.random()*(pipeHeight/2));
int openingSpace = boardHeight/4;
30| P a g e
Pipe topPipe = new Pipe(topPipeImg);
topPipe.y = randomPipeY;
pipes.add(topPipe);
//bird
g.drawImage(birdImg, bird.x, bird.y, bird.width, bird.height, null);
//pipes
for (int i = 0; i < pipes.size(); i++) {
Pipe = pipes.get(i);
g.drawImage(pipe.img, pipe.x, pipe.y, pipe.width, pipe.height, null);
}
//score
g.setColor(Color.black);
31| P a g e
g.drawString("Game Over: " + String.valueOf((int) score), 10, 35);
}
else {
g.drawString(String.valueOf((int) score), 10, 35);
}
//pipes
for (int i = 0; i < pipes.size(); i++) {
Pipe = pipes.get(i);
pipe.x += velocityX;
if (collision(bird, pipe)) {
gameOver = true;
}
}
32| P a g e
gameOver = true;
}
}
@Override
public void actionPerformed(ActionEvent e) { //called every x
milliseconds by gameLoop timer
move();
repaint();
if (gameOver) {
placePipeTimer.stop();
gameLoop.stop();
}
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
// System.out.println("JUMP!");
velocityY = -9;
if (gameOver) {
//restart game by resetting conditions
bird.y = birdY;
velocityY = 0;
33| P a g e
pipes.clear();
gameOver = false;
score = 0;
gameLoop.start();
placePipeTimer.start();
}
}
}
//not needed
@Override
public void keyTyped(KeyEvent e) {}
@Override
public void keyReleased(KeyEvent e) {}
}
34| P a g e
Screenshots
These screenshots provide a visual representation of the game's
user interface, graphics, and overall aesthetic. They help to convey
the game's atmosphere and the player experience.
35| P a g e
2.) Game Progress
36| P a g e
3.) Game Over
37| P a g e
Future Updates for Flappy Bird
Here are some potential updates that could enhance the Flappy Bird game:
Gameplay Enhancements
38| P a g e
Social Features
Technical Improvements
39| P a g e
Conclusion
The Flappy Bird project successfully replicated the core mechanics
of the popular mobile game, providing a hands-on experience in
Java game development. Key aspects of the development process
included:
Game Design and Mechanics:
• Defining the core gameplay loop, involving bird control, pipe
generation, and collision detection.
• Implementing a scoring system to incentivize player
performance.
• Balancing game difficulty to provide a challenging yet
enjoyable experience.
Technical Implementation:
• Leveraging Java's object-oriented programming paradigm to
model game entities like the bird and pipes.
• Utilizing appropriate data structures and algorithms for
efficient game logic and rendering.
• Implementing collision detection techniques to accurately
determine when the bird collides with pipes or the ground.
• Employing a game loop to handle input, update game objects,
and render the game.
User Interface and Experience:
• Designing a visually appealing and intuitive user interface.
40| P a g e
• Implementing responsive controls to ensure precise bird
movement.
• Incorporating sound effects and background music to enhance
the overall gaming experience.
Through iterative development and testing, the project addressed
challenges such as optimizing game performance, fine-tuning
collision detection, and balancing game difficulty. The final
implementation provides a functional and engaging Flappy Bird
game that adheres to the core principles of the original.
While the project has achieved its primary objectives, there are
opportunities for future improvements. Potential
enhancements include:
• Advanced Game Mechanics: Implementing power-ups,
obstacles, or different game modes to increase complexity and
replayability.
• Enhanced Visuals and Sound: Improving the game's visual
and audio aesthetics through detailed graphics and immersive
sound effects.
• Performance Optimization: Optimizing the game's code to
improve performance, especially on lower-end devices.
• Opponents: Incorporating AI-controlled opponents to
compete against the player.
• Multiplayer Mode: Enabling players to compete against each
other or cooperate in a cooperative mode.
41| P a g e
References
42| P a g e