# btlcode4t/game architecture

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

- Interactive diagram: https://gitdiagram.com/btlcode4t/game
- Repository: https://github.com/btlcode4t/game

## Overview

##### Project type and purpose
- This is a native C++ 2D side-scroller game (“Khủng long chạy”) built with CMake and organized into a lightweight custom game engine (Core), the gameplay logic (GamePlay), utilities (Utils), and external assets (images, sounds, data files).

##### Top-level file-structure analysis
- CMakeLists.txt / .github/workflows/ci.yml: build system and CI.
- / and src/: engine modules under Core (Audio, GameLoop, Input, Renderer, ResourceManager), gameplay subsystems under GamePlay (Avatar, Entity, Gun, Map, Physics, UI), plus common Utils.
- assets/: all runtime media (Images, Sounds, music).
- data/: persistent files (score, settings, JSON).
- Docs/: design mind-maps.

##### Key architectural patterns and modules
- Layered / modular design
- Core layer (engine services)
- Gameplay layer (domain logic)
- Asset & Data layer (resources + persistence)
- GameLoop drives each tick: polls Input, updates Physics & game state, triggers AI/Entity logic, then hands off to Renderer & Audio.
- ResourceManager centralizes loading of textures, sounds and hands handles to subsystems.
- SettingsManager & Scores I/O use plain-text/JSON in data/.

##### Components
a. Core Engine
- GameLoop
- InputManager
- Renderer
- AudioManager (MusicManager)
- ResourceManager
b. Gameplay Subsystems
- PhysicsSystem
- Entity / Avatar / Dinosaur / Gun modules
- MapManager
- UI (Animation, Scores, StateUI)
c. Data & Persistence
- SettingsManager (reads/writes SettingsManager.txt, data.json)
- ScoresManager (reads/writes Scores.txt)
d. Assets
- Images, Sounds, Music folders
e. Build & CI (optional)
- CMake (build graph)
- GitHub Actions (ci.yml)

##### Relationships and data‐flow
- GameLoop → InputManager : “poll events”
- GameLoop → PhysicsSystem : “apply forces, collision”
- GameLoop → Entity & Gameplay modules : “update state”
- GameLoop → UI : “render UI overlays”
- ResourceManager → Renderer/AudioManager : “provide loaded assets”
- InputManager → Gameplay : “user commands → movement/shoot”
- SettingsManager/ScoresManager ↔ GameLoop : “load at startup, save on exit”

##### Important architectural/design principles
- Single-responsibility modules (each folder is one subsystem)
- Decoupling via ResourceManager: no subsystem loads raw files directly
- Event-driven loop: Core.GameLoop is the heartbeat
- Layered calls: Core services → GamePlay → UI → Renderer/Audio

##### Final checklist
- All components are clearly labeled.
- Layers or swim-lanes reflect architectural separation.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Core Engine"
        GL["Core::GameLoop"]:::engine
        IM["Core::InputManager"]:::engine
        RM["Core::ResourceManager"]:::engine
        RDR["Core::Renderer"]:::engine
        AM["Core::AudioManager"]:::engine
        SM["Core::SettingsManager"]:::data
    end

    subgraph "Gameplay Layer"
        PHY["Gameplay::PhysicsSystem"]:::gameplay
        AV["Gameplay::Avatar"]:::gameplay
        DINO["Gameplay::Entity (Dinosaur)"]:::gameplay
        GUN["Gameplay::Gun"]:::gameplay
        BUL["Gameplay::Bullet"]:::gameplay
        TRAP["Gameplay::Trap"]:::gameplay
        MAP["Gameplay::MapManager"]:::gameplay
        UI["Gameplay::UI"]:::gameplay
        ANI["Animation"]:::gameplay
        SD["Scores Display"]:::gameplay
        SUI["StateUI"]:::gameplay
    end

    subgraph "Data & Persistence"
        SMS["ScoresManager"]:::data
        SETTINGS_FILE["Settings.txt"]:::data
        SCORES_FILE["Scores.txt"]:::data
        DATA_JSON["data.json"]:::data
    end

    subgraph "Assets"
        IMG["Images"]:::assets
        SND["Sounds"]:::assets
        MUS["Music"]:::assets
    end

    subgraph "Build & CI"
        CMAKE["CMake"]:::build
        CI["GitHub Actions"]:::build
    end

    GL -->|"poll events"| IM
    GL -->|"apply forces, collision"| PHY
    GL -->|"update state"| AV
    GL -->|"update state"| DINO
    GL -->|"update state"| GUN
    GL -->|"render UI overlays"| UI
    GL -->|"render graphics"| RDR
    GL -->|"play audio"| AM

    IM -->|"user commands → movement/shoot"| AV
    IM -->|"user commands → movement/shoot"| GUN

    RM -->|"provide loaded assets"| RDR
    RM -->|"provide loaded assets"| AM

    SM ---|"load at startup, save on exit"| GL
    SMS ---|"load at startup, save on exit"| GL

    CMAKE --> GL
    CI --> CMAKE

    %% Click events
    click GL "https://github.com/btlcode4t/game/blob/main/include/Core/GameLoop/game.h"
    click IM "https://github.com/btlcode4t/game/blob/main/include/Core/Input/Input.h"
    click SM "https://github.com/btlcode4t/game/blob/main/include/Core/Input/SettingsManager.h"
    click RDR "https://github.com/btlcode4t/game/tree/main/include/Core/Renderer/"
    click AM "https://github.com/btlcode4t/game/blob/main/include/Core/Audio/Audio.h"
    click RM "https://github.com/btlcode4t/game/tree/main/include/Core/ResourceManager/"
    click PHY "https://github.com/btlcode4t/game/blob/main/include/GamePlay/Physics/PhysicsSystem.h"
    click AV "https://github.com/btlcode4t/game/blob/main/include/GamePlay/Avatar/player.h"
    click DINO "https://github.com/btlcode4t/game/blob/main/include/GamePlay/Entity/Dinosaur.h"
    click GUN "https://github.com/btlcode4t/game/blob/main/include/GamePlay/Gun/gun.h"
    click BUL "https://github.com/btlcode4t/game/blob/main/include/GamePlay/Gun/bullet.h"
    click TRAP "https://github.com/btlcode4t/game/blob/main/include/GamePlay/Gun/Trap.h"
    click MAP "https://github.com/btlcode4t/game/blob/main/include/GamePlay/Map/map.h"
    click UI "https://github.com/btlcode4t/game/blob/main/include/GamePlay/UI/UI.h"
    click ANI "https://github.com/btlcode4t/game/blob/main/include/GamePlay/UI/Animation.h"
    click SD "https://github.com/btlcode4t/game/blob/main/include/GamePlay/UI/Scores.h"
    click SUI "https://github.com/btlcode4t/game/blob/main/include/GamePlay/UI/StateUI.h"
    click SMS "https://github.com/btlcode4t/game/blob/main/data/Scores.txt"
    click IMG "https://github.com/btlcode4t/game/tree/main/assets/Images/"
    click SND "https://github.com/btlcode4t/game/tree/main/assets/Sounds/"
    click MUS "https://github.com/btlcode4t/game/tree/main/assets/music/"
    click CMAKE "https://github.com/btlcode4t/game/blob/main/CMakeLists.txt"
    click CI "https://github.com/btlcode4t/game/blob/main/.github/workflows/ci.yml"

    classDef engine fill:#AED6F1,stroke:#21618C,stroke-width:1px;
    classDef gameplay fill:#ABEBC6,stroke:#1D8348,stroke-width:1px;
    classDef data fill:#F9E79F,stroke:#B9770E,stroke-width:1px;
    classDef assets fill:#FDEBD0,stroke:#B9770E,stroke-width:1px;
    classDef build fill:#E5E8E8,stroke:#566573,stroke-width:1px;
```
