This is a faithful recreation of the classic Flappy Bird game built entirely in Java using Swing. The project demonstrates core Java programming concepts including GUI development, event handling, collision detection, and audio integration.
- Classic Flappy Bird gameplay with smooth animations
- Background music that plays during the game
- Real-time score tracking displayed on screen
- Collision detection between bird and pipes
- Game over screen with restart functionality
- Responsive controls using spacebar input
- Automatic pipe generation at timed intervals
- Press
SPACEBARto make the bird jump - Avoid the pipes by navigating through the gaps
- Score points by successfully passing through pipes
- Game over when the bird hits a pipe or the ground
- Click "Restart" button to play again
- Java JDK 8 or higher
- Any Java IDE (IntelliJ IDEA, Eclipse, VS Code, etc.)
-
Clone or download this repository
-
Create a
resourcesfolder in your project directory -
Add the following files to the
resourcesfolder:bg.png- Background imagebird.png- Bird spritetop.png- Top pipe imagebottom.png- Bottom pipe imagebg_music.wav- Background music file
-
Choose your preferred method:
- Easy: Download the
.exefile from releases - JAR: Download and run the
.jarfile - Source: Compile and run from source code
- Easy: Download the
flappy-bird-java/
โโโ MainGame.java # Main entry point
โโโ flappyBird.java # Game logic and rendering
โโโ Bird.java # Bird object class
โโโ pipe.java # Pipe object class
โโโ MANIFEST.MF # JAR manifest file
โโโ FlappyBird.jar # Compiled JAR file
โโโ FlappyBird.exe # Windows executable
โโโ resources/
โโโ bg.png # Background image
โโโ bird.png # Bird sprite
โโโ top.png # Top pipe sprite
โโโ bottom.png # Bottom pipe sprite
โโโ bg_music.wav # Background music
| Class | Description |
|---|---|
MainGame |
Entry point that creates the JFrame window |
flappyBird |
Main game panel with all game logic |
Bird |
Bird object with position and image properties |
pipe |
Pipe object with collision detection |
- JFrame & JPanel - Window and game area
- ArrayList - Dynamic pipe storage
- Timer - Game loop and pipe spawning
- KeyListener - Keyboard input handling
- Graphics2D - Custom drawing and rendering
- Java Sound API - Background music playback
- Rectangle - Collision detection
- ActionListener - Button and timer events
- Gravity: Bird falls continuously
- Jump: Spacebar applies upward velocity
- Collision: Game ends when bird touches pipes or ground
- +1 point for each pipe successfully passed
- Score displayed in real-time at top-left corner
- New pipes spawn every 1.5 seconds
- Random height variation for difficulty
- 160-pixel gap between top and bottom pipes
- Size: 360x640 pixels
- Fixed size (not resizable)
- Centered on screen
- 60 FPS refresh rate
- Continuous movement and collision checking
- Automatic pipe cleanup when off-screen
- Background music loops continuously
- Stops when game ends
- Restarts with new game
๐ฎ Ready to play immediately!
- One-click download - No Java installation required
- Portable - Run directly without installation
- Windows compatible - Works on Windows 7, 8, 10, 11
# Download the JAR file from releases
java -jar FlappyBird.jar# Compile
javac *.java
# Run
java MainGameThis project helped me learn:
- Java Swing GUI development
- Game loop implementation
- Event handling and user input
- Object-oriented programming principles
- Audio integration in Java
- Collision detection algorithms
- Resource management
- JAR file creation and packaging
- Executable creation using Launch4j Wrapper
- Application deployment and distribution
Feel free to fork this project and submit pull requests for improvements!
This project is open source and available under the MIT License.
If you like this project, don't forget to โญ star the repo!



