# bachlv/supermariodx architecture

> Architecture diagram of the GitHub repository bachlv/supermariodx, 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/bachlv/supermariodx
- Repository: https://github.com/bachlv/supermariodx

## Overview

##### Main Components
- Game Engine Core – Represented by the Game class along with the main loop (in Game.cpp/Game.h), it coordinates updates, rendering, and game state transitions.
- Renderer/Graphics Layer – Components such as Textures, Sprites, Animations, and TileMap handling (found in Textures.cpp, Sprites.cpp, Animations.cpp, TileMap.cpp) are responsible for drawing scenes using the DirectX API.
- Scene/Level Management – The “scenes” folder contains configurations, map files, sprite definitions, and object placements for different levels (e.g., world-1-1, world-1-4, menu). The Scene classes (Scene.cpp, SceneMenu.cpp, ScenePlayer.cpp) control scene transitions and initialization.
- Input Manager – The Input class (Input.cpp, Input.h) captures user commands (keyboard controls) for basic movement, running, jumping, etc.
- Game Objects & Entities – Individual game elements (Mario, Goomba, Koopa, Brick, Coin, etc.) each have their own source files (e.g., Mario.cpp/Mario.h, Goomba.cpp/Goomba.h) that define behavior and attributes. They are managed and updated within the game’s main loop.
- Collision/Physics Module – The Collision components (Collision.cpp, Collision.h) and related object logic engage to detect interactions between game objects.

##### Relationship and Interactions
- The Game Engine Core sits at the center, initiating the game loop where it consistently updates the Scene Manager.
- The Scene Manager loads a specific level or menu scene (using configuration files from the “scenes” directory) and instantiates game objects specific to that scene.
- The Input Manager collects player commands and sends them to the Game Engine Core, which in turn updates game objects or triggers scene transitions.
- Collision and physics logic process the game objects’ interactions during each update cycle.
- The Camera component adjusts the viewport based on player movement to follow the protagonist.

##### Architectural Patterns & Technologies
- Layered/Modular Architecture: The separation into modules (input, rendering, scene management, game objects) ensures a clean division of responsibilities.
- Component-Based Game Objects: The uniform handling of different game entities (like Mario, Koopa, etc.) hints at object-oriented, component-driven design.
- Resource and Asset Management: The structure of the “assets” folder and scene configurations clearly delineate external resources from code.
- Use of DirectX API for rendering (as mentioned in the README) strongly influences the design of the graphics layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        Player("Player"):::input
        InputManager("Input Manager"):::input
    end

    %% Game Logic Layer
    subgraph "Game Logic"
        GameEngine("Game Engine Core"):::core
        SceneMgr("Scene Manager"):::core
        GameObjects("Game Objects & Entities"):::gameobj
        Collision("Collision/Physics Module"):::core
    end

    %% Rendering Layer
    subgraph "Rendering"
        Renderer("Renderer/Graphics Layer"):::renderer
        AssetManager("Asset/Resource Manager"):::asset
    end

    %% Auxiliary Systems Layer
    subgraph "Auxiliary Systems"
        CameraSys("Camera System"):::aux
        HUD("HUD"):::aux
        DebugUtil("Debug Utilities"):::aux
    end

    %% Connections
    Player -->|"input"| InputManager
    InputManager -->|"sendsCommand"| GameEngine
    GameEngine -->|"updates"| SceneMgr
    GameEngine -->|"updates"| GameObjects
    SceneMgr -->|"loadsObjects"| GameObjects
    GameEngine -->|"collisionCheck"| Collision
    GameEngine -->|"renderCall"| Renderer
    Renderer -->|"fetchAssets"| AssetManager
    GameEngine -->|"setView"| CameraSys
    GameEngine -->|"displayInfo"| HUD
    GameEngine -->|"logStatus"| DebugUtil

    %% Click Events
    click GameEngine "https://github.com/bachlv/supermariodx/blob/main/src/Game.cpp"
    click Renderer "https://github.com/bachlv/supermariodx/blob/main/src/Textures.cpp"
    click SceneMgr "https://github.com/bachlv/supermariodx/tree/main/scenes/"
    click InputManager "https://github.com/bachlv/supermariodx/blob/main/src/Input.cpp"
    click GameObjects "https://github.com/bachlv/supermariodx/blob/main/src/Mario.cpp"
    click Collision "https://github.com/bachlv/supermariodx/blob/main/src/Collision.cpp"
    click CameraSys "https://github.com/bachlv/supermariodx/blob/main/src/Camera.cpp"
    click HUD "https://github.com/bachlv/supermariodx/blob/main/src/HUD.cpp"
    click DebugUtil "https://github.com/bachlv/supermariodx/blob/main/src/Debug.cpp"
    click AssetManager "https://github.com/bachlv/supermariodx/tree/main/assets/"

    %% Styles
    classDef core fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef input fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef renderer fill:#e2d6f3,stroke:#6f42c1,stroke-width:2px;
    classDef gameobj fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef aux fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef asset fill:#d4edda,stroke:#155724,stroke-width:2px;
```
