Skip to content

gangsarrz/java-flappy-bird

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฆ Java Flappy Bird

A simple Flappy Bird clone built using Java and Java Swing. This project was created to practice Object-Oriented Programming (OOP), Java GUI development, game loops, collision detection, and event handling.


๐Ÿ“ธ Preview

Add screenshots or GIF here

Main Menu Gameplay

Or

Gameplay Demo


๐Ÿ“– Table of Contents

  • Overview
  • Features
  • Technologies Used
  • Project Structure
  • How It Works
  • Installation
  • Running the Project
  • Controls
  • Game Mechanics
  • OOP Concepts Used
  • Future Improvements
  • Learning Outcomes
  • Known Issues
  • Contributing
  • License
  • Author

๐Ÿ“Œ Overview

Java Flappy Bird is a desktop game inspired by the classic Flappy Bird.

The objective is simple:

  • Control the bird
  • Avoid hitting pipes
  • Try to achieve the highest score possible

This project focuses on implementing game development fundamentals using pure Java without external game engines.


โœจ Features

  • Bird movement with gravity
  • Jump mechanics
  • Random pipe generation
  • Collision detection
  • Score system
  • Game Over screen
  • Restart game
  • Smooth animation using game loop
  • Keyboard controls
  • Simple pixel-style gameplay

๐Ÿ›  Technologies Used

  • Java
  • Java Swing
  • Java AWT
  • OOP (Object-Oriented Programming)

No external libraries are required.


๐Ÿ“‚ Project Structure

Example:

java-flappy-bird
โ”‚
โ”œโ”€โ”€ src
โ”‚   โ”œโ”€โ”€ Main.java
โ”‚   โ”œโ”€โ”€ GamePanel.java
โ”‚   โ”œโ”€โ”€ Bird.java
โ”‚   โ”œโ”€โ”€ Pipe.java
โ”‚   โ”œโ”€โ”€ Game.java
โ”‚   โ””โ”€โ”€ assets
โ”‚       โ”œโ”€โ”€ bird.png
โ”‚       โ”œโ”€โ”€ pipe.png
โ”‚       โ””โ”€โ”€ background.png
โ”‚
โ”œโ”€โ”€ images
โ”‚
โ”œโ”€โ”€ README.md
โ”‚
โ””โ”€โ”€ LICENSE

Your structure may be different depending on your project.


โš™ How It Works

The game continuously performs these steps:

Start Game

โ†“

Initialize Bird

โ†“

Generate Pipes

โ†“

Game Loop

โ†“

Update Bird Position

โ†“

Move Pipes

โ†“

Check Collision

โ†“

Increase Score

โ†“

Render Graphics

โ†“

Repeat Until Game Over

The game loop is responsible for:

  • Updating object positions
  • Detecting collisions
  • Redrawing the screen
  • Maintaining FPS

๐Ÿš€ Installation

1 Clone Repository

git clone https://github.com/gangsarrz/java-flappy-bird.git

2 Open Project

Open using

  • IntelliJ IDEA
  • Eclipse
  • NetBeans
  • VS Code (Java Extension Pack)

3 Compile

javac *.java

or using your IDE.


โ–ถ Running the Project

Run:

java Main

or simply click Run inside your IDE.


๐ŸŽฎ Controls

Key Action
Space Jump
R Restart Game (optional)
ESC Exit (optional)

๐ŸŽฏ Game Mechanics

Gravity

The bird constantly falls due to gravity.

velocity += gravity
position += velocity

Jump

When the player presses Space:

velocity = jumpForce

The bird moves upward.


Pipe Generation

Pipes are generated at random heights with a fixed gap between the top and bottom pipes.

Example:

Pipe

โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ

Gap

โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ

Collision Detection

The game checks collision between:

  • Bird vs Top Pipe
  • Bird vs Bottom Pipe
  • Bird vs Ground
  • Bird vs Ceiling

If a collision occurs:

Game Over

Score System

The score increases every time the bird successfully passes a pipe.

Example:

Bird

โ†“

Pipe

โœ” Score +1

๐Ÿง  Object-Oriented Programming Concepts

This project demonstrates several OOP principles.

Encapsulation

Each game object manages its own data.

Example:

  • Bird
  • Pipe

Abstraction

Game logic is separated into different classes.


Inheritance (if implemented)

Can be extended for future entities.


Polymorphism (optional)

Useful when adding enemies or collectibles.


๐Ÿ“š Learning Outcomes

Through this project, I learned about:

  • Java Swing
  • Java Graphics
  • Event Handling
  • Keyboard Listener
  • Timers
  • Animation
  • Collision Detection
  • Random Generation
  • Object-Oriented Programming
  • Game Development Basics
  • Code Organization
  • Debugging Java Applications

๐Ÿ“ˆ Future Improvements

Planned features:

  • Sound effects
  • Background music
  • High score saving
  • Difficulty levels
  • Pause menu
  • Animated bird
  • Better graphics
  • Mobile version
  • Power-ups
  • Multiple bird skins

๐Ÿž Known Issues

  • Window resizing is not supported.
  • Score resets after restarting.
  • No save/load system.
  • Basic collision detection.

๐Ÿค Contributing

Contributions are welcome.

If you'd like to improve this project:

  1. Fork the repository

  2. Create a new branch

git checkout -b feature/new-feature
  1. Commit changes
git commit -m "Add new feature"
  1. Push
git push origin feature/new-feature
  1. Open a Pull Request

โญ Support

If you found this project helpful, consider giving it a โญ on GitHub.

It motivates me to build more open-source projects and continue learning.

About

A Flappy Bird clone built with Java and Java Swing to practice object-oriented programming, game loops, collision detection, keyboard input, and GUI development.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages