# tvquyet05/gamesdl2 architecture

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

- Interactive diagram: https://gitdiagram.com/tvquyet05/gamesdl2
- Repository: https://github.com/tvquyet05/gamesdl2

## Overview

##### Project type and purpose
- This is a C++ real-time 2D game built on SDL2 (with SDL2_image, SDL2_mixer, SDL2_ttf).
- It implements a “Dynamic Tank” shooter: player-controlled tank, multiple enemy tank types, pickups, health, scoring.
- The game runs in a single executable, driven by a classic game loop (input → update → render → audio).

##### File structure
- Top-level “ProjectGameSDL2” folder: all source (*.cpp/.h), assets (image, sound, map, font), project files (.vcxproj, .sln).
- “LibSdl2” folder: bundled SDL2 libraries (DLLs, headers, .lib) and support libraries (SDL2_image, SDL2_mixer, SDL2_ttf).
- “Debug” and “x64/Debug”: build outputs and PDBs.
- Source classes:
– BaseObject, BulletObject, ExplosionObject, TextObject etc.: encapsulate renderable/movable entities.
– ImpTimer: time management.
– CommonFunc: utility routines (collision detection, asset loading).
– game_map: tile/map loader.
– MainObject: player tank controller.
– ThreatToHouse/ThreatToMain: AI enemy behaviors.
- Assets:
– /image (sprite sheets, textures)
– /sound (effects, soundtrack)
– /map (map data)
– /font (TTF files)

##### README insights
- Confirms SDL2 usage, sound, animation, timing, vector/pointer, collision, simple AI.
- Game features: player controls, 2 enemy behaviors, pickups (“red jar”, “green jar”), scoring, health bars.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main flow
    Input["Input Manager"]:::internal
    Timing["Game Loop\n(ImpTimer)"]:::internal
    Physics["Update & Physics\n(CommonFunc)"]:::internal
    Render["Render Manager"]:::internal
    Audio["Audio Manager\n(CommonFunc)"]:::internal

    %% Shared services
    Resource["Resource Manager\n(CommonFunc)"]:::internal
    MapLoader["Map Loader\n(game_map)"]:::internal

    %% Subsystems
    subgraph "Entity System"
        BaseObj["BaseObject"]:::internal
        Bullet["BulletObject"]:::internal
        Explosion["ExplosionObject"]:::internal
        MainObj["MainObject"]:::internal
    end

    subgraph "AI Controller"
        AIHouse["ThreatToHouse"]:::internal
        AIMain["ThreatToMain"]:::internal
    end

    UI["UI/Text System\n(TextObject)"]:::internal

    %% External Libraries
    subgraph "External SDL2 Libraries"
        SDL2["SDL2 Core"]:::external
        IMG["SDL2_image"]:::external
        MIX["SDL2_mixer"]:::external
        TTF["SDL2_ttf"]:::external
    end

    %% Assets
    subgraph "Assets"
        Sprites["Sprites & Textures"]:::asset
        Sounds["Sound Assets"]:::asset
        Maps["Map Data"]:::asset
        Fonts["Font Assets"]:::asset
    end

    %% Data/control flow
    Input -->|"events"| Timing
    Timing -->|"delta time"| Physics
    Timing -->|"frame tick"| Render
    Timing -->|"audio cue"| Audio

    Physics -->|"update entities"| BaseObj
    Physics -->|"collision checks"| MapLoader
    Physics -->|"AI decision"| AIHouse
    Physics -->|"AI decision"| AIMain
    Physics -->|"spawn/despawn"| Resource
    Physics -->|"play SFX"| Audio

    Render -->|"draw sprites"| BaseObj
    Render -->|"draw sprites"| Bullet
    Render -->|"draw sprites"| Explosion
    Render -->|"draw sprites"| MainObj
    Render -->|"render map"| MapLoader
    Render -->|"render UI"| UI
    Render -->|"use textures"| Resource

    Audio -->|"play sound"| Resource

    UI -->|"load fonts"| Resource

    %% Resource and assets
    Sprites --> Resource
    Sounds --> Resource
    Maps --> Resource
    Fonts --> Resource

    Resource --> Physics
    Resource --> Render
    Resource --> Audio

    MapLoader --> Render
    MapLoader --> Physics

    %% External dependencies
    SDL2 --> Input
    SDL2 --> Render
    SDL2 --> Audio
    IMG --> Resource
    MIX --> Audio
    TTF --> Resource

    %% Click Events
    click Timing "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/ImpTimer.cpp"
    click Input "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/main.cpp"
    click Physics "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/CommonFunc.cpp"
    click Resource "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/CommonFunc.cpp"
    click BaseObj "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/BaseObject.cpp"
    click Bullet "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/BulletObject.cpp"
    click Explosion "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/ExplosionObject.cpp"
    click MainObj "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/MainObject.cpp"
    click AIHouse "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/ThreatToHouse.cpp"
    click AIMain "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/ThreatToMain.cpp"
    click UI "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/TextObject.cpp"
    click MapLoader "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/game_map.cpp"
    click SDL2 "https://github.com/tvquyet05/gamesdl2/blob/master/LibSdl2/SDL2-2.0.8"
    click IMG "https://github.com/tvquyet05/gamesdl2/blob/master/LibSdl2/SDL2_image-2.0.3"
    click MIX "https://github.com/tvquyet05/gamesdl2/blob/master/LibSdl2/SDL2_mixer-2.0.2"
    click TTF "https://github.com/tvquyet05/gamesdl2/blob/master/LibSdl2/SDL2_ttf-2.0.14"
    click Sprites "https://github.com/tvquyet05/gamesdl2/tree/master/ProjectGameSDL2/image/"
    click Sounds "https://github.com/tvquyet05/gamesdl2/tree/master/ProjectGameSDL2/sound/"
    click Maps "https://github.com/tvquyet05/gamesdl2/blob/master/ProjectGameSDL2/map/map01.dat"
    click Fonts "https://github.com/tvquyet05/gamesdl2/tree/master/ProjectGameSDL2/font/"

    %% Styles
    classDef internal fill:#ccffcc,stroke:#333,stroke-width:1px;
    classDef external fill:#aaeaff,stroke:#333,stroke-width:1px;
    classDef asset fill:#ffd699,stroke:#cc8400,stroke-width:1px;
```
