# rilomilo/flappybird architecture

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

- Interactive diagram: https://gitdiagram.com/rilomilo/flappybird
- Repository: https://github.com/rilomilo/flappybird

## Overview

##### Project type and purpose
- This is a single‐page, front-end game project written in TypeScript and bundled with Webpack.
- It implements a modified Flappy Bird clone using the HTML5 Canvas API.
- Features include a resource loader, game loop (Runtime), input controller, various game elements (bird, land, pipes), audio effects, and a menu UI.

##### File structure
- Top-level files:
– package.json / tsconfig.json / webpack.config.js: build and dependency configuration.
– index.html: game container and canvas element.
- res/: static assets
– res/img/: (any image assets you add)
– res/sound/: MP3 clips for effects (duang, fly, score)
- src/: application code
– src/index.ts: application entry point—bootstraps resource loader and launches the Runtime.
– src/declare.ts: global type declarations.
– src/game/: core game logic
· GameMenu.ts: menu and start/restart UI.
· Runtime.ts: central game loop, update & render calls.
· SpiritController.ts: input handling (mouse/tap) for controlling the bird.
– src/game/elements/: domain models and renderable objects
· Level.ts, Live.ts, Score.ts: game state trackers (level progression, remaining lives, scoring).
· src/game/elements/spirits/: sprites/entities (Bird, Land, Pencil (pipe), BackGround) all extend Spirit.ts.
– src/modules/: cross-cutting services
· Resource.ts: loads images and audio before game start.
· Sound.ts: plays audio clips on game events (flap, collision, score).
– src/style/style.less: styles for canvas container and menu.

##### README for additional insights
- Confirms it’s a “魔改版” (modified) Flappy Bird on Canvas.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Environment
    subgraph "Environment" 
        Browser["Browser Environment"]:::env
        Canvas["HTML5 Canvas API"]:::env
    end

    %% Entry Point
    subgraph "Entry Point"
        HTML["index.html"]:::env
        TS["index.ts"]:::env
    end
    Browser -->|loads| HTML
    HTML -->|includes bundle| TS
    click HTML "https://github.com/rilomilo/flappybird/blob/master/src/index.html"
    click TS "https://github.com/rilomilo/flappybird/blob/master/src/index.ts"

    %% Modules / Services
    subgraph "Services & Modules"
        Resource["Resource Loader"]:::service
        Sound["Audio Manager (Sound)"]:::service
    end
    TS -->|initializes| Resource
    click Resource "https://github.com/rilomilo/flappybird/blob/master/src/modules/Resource.ts"
    TS -->|binds audio| Sound
    click Sound "https://github.com/rilomilo/flappybird/blob/master/src/modules/Sound.ts"

    %% Static Assets
    subgraph "Static Assets"
        Img["Images"]:::asset
        Duang["duang.mp3"]:::asset
        Fly["fly.mp3"]:::asset
        ScoreAudio["score.mp3"]:::asset
    end
    Resource -->|loads| Img
    Resource -->|loads| Duang
    Resource -->|loads| Fly
    Resource -->|loads| ScoreAudio
    click Img "https://github.com/rilomilo/flappybird/tree/master/res/img/"
    click Duang "https://github.com/rilomilo/flappybird/blob/master/res/sound/duang.mp3"
    click Fly "https://github.com/rilomilo/flappybird/blob/master/res/sound/fly.mp3"
    click ScoreAudio "https://github.com/rilomilo/flappybird/blob/master/res/sound/score.mp3"

    %% Core Game
    subgraph "Game Core"
        Runtime["Runtime (Game Loop)"]:::core
        Controller["SpiritController (Input Controller)"]:::controller
        UI["GameMenu (UI/Menu Overlay)"]:::controller
    end
    Resource -->|signals ready| Runtime
    Runtime -->|loop| Controller
    Runtime -->|loop| UI
    Runtime -->|update & render| Canvas
    Controller -->|user input| Runtime
    UI -->|controls state| Runtime
    Runtime -->|events| Sound

    click Runtime "https://github.com/rilomilo/flappybird/blob/master/src/game/Runtime.ts"
    click Controller "https://github.com/rilomilo/flappybird/blob/master/src/game/SpiritController.ts"
    click UI "https://github.com/rilomilo/flappybird/blob/master/src/game/GameMenu.ts"

    %% Domain Models & Sprites
    subgraph "Domain Models & Sprites"
        Element["Element (Base Class)"]:::domain
        SpiritBase["Spirit (Base Class)"]:::domain
        Level["Level Tracker"]:::domain
        Live["Lives Tracker"]:::domain
        Score["Score Tracker"]:::domain
        Bird["Bird"]:::domain
        Land["Land"]:::domain
        Pencil["Pencil (Pipe)"]:::domain
        BackGround["BackGround"]:::domain
    end
    click Element "https://github.com/rilomilo/flappybird/blob/master/src/game/elements/Element.ts"
    click Level "https://github.com/rilomilo/flappybird/blob/master/src/game/elements/Level.ts"
    click Live "https://github.com/rilomilo/flappybird/blob/master/src/game/elements/Live.ts"
    click Score "https://github.com/rilomilo/flappybird/blob/master/src/game/elements/Score.ts"
    click SpiritBase "https://github.com/rilomilo/flappybird/blob/master/src/game/elements/spirits/Spirit.ts"
    click Bird "https://github.com/rilomilo/flappybird/blob/master/src/game/elements/spirits/Bird.ts"
    click Land "https://github.com/rilomilo/flappybird/blob/master/src/game/elements/spirits/Land.ts"
    click Pencil "https://github.com/rilomilo/flappybird/blob/master/src/game/elements/spirits/Pencil.ts"
    click BackGround "https://github.com/rilomilo/flappybird/blob/master/src/game/elements/spirits/BackGround.ts"

    SpiritBase -->|extends| Element
    Bird -->|extends| SpiritBase
    Land -->|extends| SpiritBase
    Pencil -->|extends| SpiritBase
    BackGround -->|extends| SpiritBase
    Level -->|uses| Element
    Live -->|uses| Element
    Score -->|uses| Element
    Runtime -->|manages| Element

    %% Configuration
    subgraph "Build & Config"
        Webpack["webpack.config.js"]:::config
        TSConfig["tsconfig.json"]:::config
        Package["package.json"]:::config
    end
    click Webpack "https://github.com/rilomilo/flappybird/blob/master/webpack.config.js"
    click TSConfig "https://github.com/rilomilo/flappybird/blob/master/tsconfig.json"
    click Package "https://github.com/rilomilo/flappybird/blob/master/package.json"

    %% Legend (Classes)
    classDef env fill:#dddddd,stroke:#888888,color:#333333;
    classDef service fill:#bbdefb,stroke:#0d47a1,color:#0d47a1;
    classDef core fill:#c8e6c9,stroke:#2e7d32,color:#2e7d32;
    classDef controller fill:#ffe0b2,stroke:#ef6c00,color:#e65100;
    classDef domain fill:#dcedc8,stroke:#558b2f,color:#33691e;
    classDef asset fill:#f0f4c3,stroke:#afb42b,color:#827717;
    classDef config fill:#e1bee7,stroke:#6a1b9a,color:#4a148c;
```
