How imkennyyip/flappy-bird-java works
Project type and purpose
• This is a simple desktop game written in Java using the built‑in AWT/Swing graphics libraries. It implements the Flappy Bird game mechanics (game loop, rendering, input handling, physics, collision detection, scoring).
File structure
• App.java: entry point. Creates window, initializes the game.
• FlappyBird.java: contains the core game classes (game loop, state, rendering, input logic).
• README.md: describes the tutorial, but no additional layers (no frontend/backend split, no database).
Main components
a. Presentation/UI Layer
• JFrame
• GamePanel (extends JPanel; handles paintComponent)
• Swing/AWT Event Dispatcher Thread
b. Core Game Engine
• GameLoop (runs at fixed FPS; calls update() and repaint())
• InputHandler (MouseListener/KeyListener to detect “flap” events)
c. Game Model & Logic
• Bird (position, velocity, jump() method)
• PipeManager (generates/moves pipes)
• CollisionDetector (checks bird vs. pipes/ground)
• ScoreManager (increments on each successful pipe pass)
d. External Libraries
• java.awt (Graphics, Image, event interfaces)
• javax.swing (JFrame, JPanel)
Relationships & Interactions
• The App class initializes the JFrame and adds the GamePanel.
• GamePanel registers InputHandler and starts the GameLoop.
• Each tick of the GameLoop does:
1. InputHandler reads user clicks → invokes Bird.jump().
2. PipeManager updates pipe positions.
3. Bird.update() applies gravity and velocity.
4. CollisionDetector checks for intersections → if collision, ends game.
5. ScoreManager updates score if Bird passes a pipe.
6. GamePanel.repaint() invokes paintComponent(Graphics) → Renderer draws Bird, Pipes, Score.
• Event Dispatcher Thread dispatches mouse events to InputHandler.
Architectural patterns & principles
• Separation of Concerns: UI vs. game logic vs. model components.
• Single Threaded Game Loop pattern.
• MVC‐light: Model (game objects & state), View (GamePanel rendering), Controller (InputHandler, GameLoop).
Elements
• Clear labels: component name + role.
• External dependency note (AWT/Swing libraries).