# vietthang5605/gameproject architecture

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

- Interactive diagram: https://gitdiagram.com/vietthang5605/gameproject
- Repository: https://github.com/vietthang5605/gameproject

## Overview

##### Main Components
- Game Core – This is where the primary logic resides (e.g., Game.cpp, main.cpp). It represents the game loop and overall coordination.
- Entities – Components such as Player, Bullet, Polygon, PlayerArrow, Button, and Entity are declared in headers and implemented in src. They form the building blocks for in-game objects.
- Physics & Collision – The Maths.cpp and associated headers (like Maths.h, Polygon.h) encapsulate the logic for movement and collision handling using techniques such as SAT.
- AI Module – Embedded in the game logic (likely within the Game or Player classes), this module uses Minimax, Alpha-Beta pruning, and Heuristic evaluations to control AI players.
- Resource Management – This encompasses loading and managing external resources like images, audio, fonts (from the “res” directory). Resources are used in rendering the visual components and playing sounds.
- SDL2 Integration – SDL2 components (headers under include/SDL2, the linked libraries under lib, and the corresponding pkgconfig files) form the backbone for handling graphics, events, audio, input, and more.
- Platform/Build Layer – There’s support for both desktop and web targets. On the desktop, compilation is via g++ (see the provided command) while for the web the project uses Emscripten, with an output of .html, .js, .wasm, and associated files under the “web” directory.
- Build & Deployment – The Makefile, various configuration files (e.g., cmake files in lib/cmake) and compile instructions (emccCompile.txt) form the build system that orchestrates how source files and libraries are combined.

- Game Core to the Physics & Collision module (Maths and Polygon interactions) showing that entity positions and collision checks are performed each frame.
- AI module feeding decisions into Player/Entity objects – showing a directional flow from the AI logic to modify game state.
- Integration with SDL2 by showing that multiple subsystems (Rendering, Input, Audio) are wrappers around SDL2 libraries.
- Resource Management should be shown as a subsystem that feeds data (images, sounds, fonts) into both the Audio and Rendering subsystems.
- Incorporate a branch that distinguishes the platform/build layer for Desktop versus Web:
– For Desktop, show that the classical C++ build (using g++ and linking against SDL2 libraries) leads to the main.exe.
– For Web, indicate that Emscripten compiles the same source into WebAssembly (with supporting HTML/JavaScript files), making use of preloaded “res” files.

##### Architectural Patterns and Design Principles
- Modular design – Each game component (entity, physics, AI, etc.) is organized into separate files/modules.
- Clear separation of concerns – The project distinguishes between game logic, rendering, input handling, and system interfacing.
- Use of Object-Oriented Programming – Classes such as Player, Button, etc., encapsulate their own behavior and interact through well-defined interfaces.
- Layered architecture – There is a clear layering from low-level SDL2 operations and platform concerns to higher-level game logic and AI.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Game Core Layer
    subgraph "Game Core Layer"
        GC["Game Core (Game Loop)"]:::core
        PE["Physics & Collision (SAT)"]:::physics
        AI["AI Module (Minimax)"]:::ai
    end

    %% Entity Management
    subgraph "Entity Management"
        P["Player"]:::entity
        B["Bullet"]:::entity
        Poly["Polygon"]:::entity
        PA["PlayerArrow"]:::entity
        Btn["Button"]:::entity
        Ent["Entity"]:::entity
    end

    %% External Systems
    subgraph "External Systems"
        SDL["SDL2 Integration"]:::sdl
        RM["Resource Management"]:::resources
    end

    %% Deployment
    subgraph "Deployment"
        DS["Desktop Build (g++)"]:::build
        WEB["Web Build (Emscripten)"]:::build
        BD["Build System"]:::build
    end

    %% Connections between Game Core and Entities/Subsystems
    GC -->|"updates"| P
    GC -->|"updates"| B
    GC -->|"updates"| Poly
    GC -->|"updates"| PA
    GC -->|"updates"| Btn
    GC -->|"updates"| Ent

    GC -->|"collision_check"| PE
    AI -->|"decision"| P
    P -->|"collides"| PE

    SDL -->|"input/render"| GC
    RM -->|"load_resource"| GC

    BD -->|"orchestrates"| DS
    BD -->|"orchestrates"| WEB
    DS -->|"produces_executable"| GC
    WEB -->|"produces_wasm"| GC

    %% Styles
    classDef core fill:#ffcccc,stroke:#660000,stroke-width:2px;
    classDef entity fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef physics fill:#ccccff,stroke:#000066,stroke-width:2px;
    classDef ai fill:#ffffcc,stroke:#666600,stroke-width:2px;
    classDef sdl fill:#d9d9d9,stroke:#333333,stroke-width:2px;
    classDef resources fill:#ffedcc,stroke:#996633,stroke-width:2px;
    classDef build fill:#e6ccff,stroke:#663399,stroke-width:2px;

    %% Click Events for Game Core
    click GC "https://github.com/vietthang5605/gameproject/blob/main/src/Game.cpp"
    
    %% Click Events for Entities
    click P "https://github.com/vietthang5605/gameproject/blob/main/src/Player.cpp"
    click B "https://github.com/vietthang5605/gameproject/blob/main/src/Bullet.cpp"
    click Poly "https://github.com/vietthang5605/gameproject/blob/main/src/Polygon.cpp"
    click PA "https://github.com/vietthang5605/gameproject/blob/main/src/PlayerArrow.cpp"
    click Btn "https://github.com/vietthang5605/gameproject/blob/main/src/Button.cpp"
    click Ent "https://github.com/vietthang5605/gameproject/blob/main/src/Entity.cpp"

    %% Click Event for Physics & Collision
    click PE "https://github.com/vietthang5605/gameproject/blob/main/src/Maths.cpp"

    %% Click Event for AI Module
    click AI "https://github.com/vietthang5605/gameproject/blob/main/src/Game.cpp"

    %% Click Event for SDL2 Integration
    click SDL "https://github.com/vietthang5605/gameproject/tree/main/include/SDL2"

    %% Click Events for Resource Management
    click RM "https://github.com/vietthang5605/gameproject/tree/main/res/images"

    %% Click Events for Deployment
    click DS "https://github.com/vietthang5605/gameproject/tree/main/Makefile"
    click WEB "https://github.com/vietthang5605/gameproject/tree/main/web"
    click BD "https://github.com/vietthang5605/gameproject/blob/main/emccCompile.txt"
```
