Skip to content

jlocala1/FlappyBox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

FlappyBox

A Java implementation of a Flappy Bird-style game featuring physics-based gameplay and collision detection.

Description

FlappyBox is a side-scrolling arcade game where players control a falling box that must navigate through randomly-generated pipe obstacles. The game demonstrates object-oriented programming principles and physics simulation in Java.

Features

  • Physics-based movement with gravity and acceleration
  • Randomly generated pipe obstacles with varying gap positions
  • Real-time collision detection
  • Score tracking system
  • Smooth animations using double buffering
  • Customizable game constants (colors, speeds, difficulty)

How to Play

  • SPACE: Make the box jump
  • Avoid hitting the pipes or going off-screen
  • Navigate through the gaps to increase your score
  • The game ends on collision or boundary violation

Requirements

  • Java Development Kit (JDK) 8 or higher
  • No external dependencies required

Running the Game

Quick Start (Java 11+)

# Navigate to the project directory
cd FlappyBox

# Run directly without compiling first
java src/main/java/flappybox/Game.java

Traditional Compile and Run

# Compile the source files (creates out/ directory)
javac -d out src/main/java/flappybox/*.java

# Run the game
java -cp out flappybox.Game

Running from an IDE

Simply open the project in IntelliJ IDEA, Eclipse, or VS Code and run Game.java - the IDE will handle compilation automatically.

Running Tests

# Compile and run tests
javac -cp src/main/java:src/test/java src/test/java/flappybox/*.java
java -cp src/main/java:src/test/java org.junit.runner.JUnitCore flappybox.GameTest

Project Structure

FlappyBox/
├── src/
│   ├── main/
│   │   └── java/
│   │       └── flappybox/
│   │           ├── Block.java          # Abstract base class for rectangular objects
│   │           ├── Sprite.java         # Movable objects with velocity/acceleration
│   │           ├── Box.java            # Square sprite with fixed dimensions
│   │           ├── FallingBox.java     # Box affected by gravity
│   │           ├── FlappyBox.java      # Player-controlled box with jump ability
│   │           ├── Pipe.java           # Obstacle composed of boxes with gaps
│   │           ├── Game.java           # Main game loop and logic
│   │           ├── GameConstant.java   # Configuration constants
│   │           ├── GameObject.java     # Interface for drawable objects
│   │           └── StdDraw.java        # Graphics library
│   └── test/
│       └── java/
│           └── flappybox/              # Unit tests
└── README.md

Game Mechanics

Physics System

  • Gravity constantly pulls the box downward
  • Jumping applies an upward velocity
  • Velocity increases over time due to acceleration
  • Movement calculations update every frame

Collision Detection

  • Axis-aligned bounding box (AABB) collision detection
  • Checks for intersections between the player box and pipe obstacles
  • Game ends immediately upon collision

Obstacle Generation

  • Pipes move from right to left across the screen
  • Each pipe has a randomly-positioned gap (2 boxes tall)
  • Old pipes are recycled when they leave the screen
  • New pipes spawn at regular intervals

Configuration

Game parameters can be adjusted in GameConstant.java:

  • Canvas dimensions
  • Box size and spacing
  • Movement speeds
  • Jump velocity
  • Gravity strength
  • Colors and visual settings
  • Frame delay (FPS)

Architecture

The project demonstrates several OOP concepts:

  • Inheritance: FlappyBoxFallingBoxBoxSpriteBlock
  • Encapsulation: Private fields with public getter/setter methods
  • Polymorphism: Method overriding for specialized behavior
  • Abstraction: Abstract classes and interfaces
  • Composition: Pipe contains multiple Box objects

Acknowledgments

  • Graphics rendering powered by StdDraw library
  • Inspired by the original Flappy Bird game

About

A Java implementation of a Flappy-Bird style game using 2D boxes and StdDraw

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages