# kenth356/flappy-bird-clone architecture

> Architecture diagram of the GitHub repository kenth356/flappy-bird-clone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kenth356/flappy-bird-clone
- Repository: https://github.com/kenth356/flappy-bird-clone

## Overview

##### Project type and purpose
- This is a standalone 2D game (a Flappy Bird clone) written in C++ with an assets folder for audio, backgrounds, fonts, and skins.
- There is no client–server split or database; it’s a desktop/mobile game engine with resource loading, game logic, rendering, and audio subsystems.

##### File structure
- Top-level source files
- Flop.cpp – likely contains main() and the game loop
- BIRD.cpp / BIRD.h – the player‐controlled bird entity
- PIPES.cpp / PIPES.h – the obstacle entities
- VARS.cpp / VARS.h – global constants or configuration
- ASSETS directory
- AUDIO – sound effects & music
- BACKGROUNDS / SKINS – graphical textures for backgrounds, birds, pipes

##### README
- Only contains the title "Flappy-Bird-Clone"
- No architectural hints, so we infer the standard game-engine structure.

##### Main components
a. Game Loop
– Central orchestrator: calls input handling, game logic update, rendering, and audio updates each frame.
b. Input Handler
– Captures key/touch events (spacebar or tap).
c. Game State Manager
– Maintains states: Start, Playing, Game Over, Winner.
– Holds references to Bird, Pipes, Score, and triggers transitions.
d. Entities
– Bird: position, velocity, sprite, flap logic.
e. Collision Detector
– Checks Bird vs. Pipes and Bird vs. ground/top bounds.
f. Asset Manager
– Loads textures (backgrounds, sprites), fonts, and audio files at startup.
g. Rendering Engine
– Draws background, pipes, bird, score overlays every frame.
h. Audio Engine
– Plays flap, point, collision, game over, and background music.
i. Configuration/Globals
– VARS: gravity, flap force, pipe gap/distance, screen dimensions.

##### Relationships and interactions
- Game Loop → Input Handler → Game State Manager → Entity Update Logic (Bird, Pipes)
- Game Loop → Collision Detector → Game State Manager
- Game Loop → Rendering Engine (reads Entities, Assets)
- Game Loop → Audio Engine (triggers sounds/events)
- Asset Manager feeds textures/sounds into Rendering/Audio Engines at initialization.

##### Architectural patterns & design principles
- Single-threaded, frame‐based loop (common in simple games)
- Separation of concerns:
- Input vs. Logic vs. Rendering vs. Audio
- Entity classes (Bird, Pipes) encapsulate their own data & behavior
- Resource management centralized in Asset Manager
- State pattern (or simple enum-driven switch) for game states

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Initialization"
        AssetMgr["Asset Manager"]:::resource
        RenderingEngineInit["Rendering Engine"]:::subsys
        AudioEngineInit["Audio Engine"]:::subsys
        AssetMgr --> RenderingEngineInit
        AssetMgr --> AudioEngineInit
    end

    subgraph "Frame Loop"
        GameLoop["Game Loop"]:::logic
        InputHandler["Input Handler"]:::subsys
        UpdatePhase["Update Phase"]:::logic
        CollisionDetector["Collision Detector"]:::logic
        GameStateMgr["Game State Manager"]:::logic
        EntitiesGroup["Entities"]:::data
        RenderingEngine["Rendering Engine"]:::subsys
        AudioEngine["Audio Engine"]:::subsys
        Bird["Bird"]:::data
        Pipes["Pipes"]:::data
        Vars["Configuration/Globals"]:::data

        GameLoop --> InputHandler
        InputHandler --> GameStateMgr
        GameLoop --> UpdatePhase
        UpdatePhase --> GameStateMgr
        GameStateMgr --> Bird
        GameStateMgr --> Pipes
        GameLoop --> CollisionDetector
        CollisionDetector --> GameStateMgr
        GameLoop --> RenderingEngine
        RenderingEngine --> Bird
        RenderingEngine --> Pipes
        RenderingEngine --> Vars
        GameLoop --> AudioEngine
    end

    %% Click Events
    click GameLoop "https://github.com/kenth356/flappy-bird-clone/blob/main/Flop.cpp"
    click InputHandler "https://github.com/kenth356/flappy-bird-clone/blob/main/Flop.cpp"
    click GameStateMgr "https://github.com/kenth356/flappy-bird-clone/blob/main/Flop.cpp"
    click CollisionDetector "https://github.com/kenth356/flappy-bird-clone/blob/main/Flop.cpp"
    click RenderingEngine "https://github.com/kenth356/flappy-bird-clone/blob/main/Flop.cpp"
    click RenderingEngineInit "https://github.com/kenth356/flappy-bird-clone/blob/main/Flop.cpp"
    click Bird "https://github.com/kenth356/flappy-bird-clone/blob/main/BIRD.cpp"
    click Bird "https://github.com/kenth356/flappy-bird-clone/blob/main/BIRD.h"
    click Pipes "https://github.com/kenth356/flappy-bird-clone/blob/main/PIPES.cpp"
    click Pipes "https://github.com/kenth356/flappy-bird-clone/blob/main/PIPES.h"
    click AssetMgr "https://github.com/kenth356/flappy-bird-clone/tree/main/ASSETS/"
    click AudioEngineInit "https://github.com/kenth356/flappy-bird-clone/tree/main/ASSETS/AUDIO/"
    click AudioEngine "https://github.com/kenth356/flappy-bird-clone/tree/main/ASSETS/AUDIO/"
    click Vars "https://github.com/kenth356/flappy-bird-clone/blob/main/VARS.cpp"
    click Vars "https://github.com/kenth356/flappy-bird-clone/blob/main/VARS.h"

    %% Styles
    classDef logic fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef subsys fill:#90EE90,stroke:#333,stroke-width:1px
    classDef resource fill:#FFA500,stroke:#333,stroke-width:1px
    classDef data fill:#FFFFE0,stroke:#333,stroke-width:1px
```
