# rcmagic/zigfightinggame architecture

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

- Interactive diagram: https://gitdiagram.com/rcmagic/zigfightinggame
- Repository: https://github.com/rcmagic/zigfightinggame

## Overview

##### Project Type and Purpose
- The project is a fighting game implemented in the Zig programming language.
- It is structured as a game engine or game simulation with dedicated modules for character actions, state management, collision handling, input processing, and rendering (using raygui).
- The game leverages a state machine to control character action states and uses assets (animations, JSON-defined actions) to drive in-game character behavior.

##### Analysis of the File Structure
- Top-level directories include:
- assets: Holds game assets (action definitions, animations, test character data) that the game loads dynamically.
- src: The heart of the application with modules like:
▪ ActionStates – containing common state definitions and the state machine logic.
▪ GameState, GameSimulation – central to driving the core game loop and simulation logic.
▪ collision_system, reaction_system – for handling physical interactions and reaction animations.
▪ input – for processing player input.
▪ asset, character_data – for managing game resources.
▪ editor and raygui – likely used for in-game debugging, editing or GUI rendering.
▪ utils – holding common mathematical/utility functions.
- tests: Contains test prototypes to verify functionality.
- vendor: Suggests third-party libraries, possibly including dependencies for raygui or other game-related functionalities.
- Build and configuration files (build.zig, build.zig.zon) indicate that the project uses Zig’s build system.

##### Key Components
a. Main Game Loop & Simulation (src/main.zig, src/game.zig, src/game_simulation.zig) – This is the core that coordinates game updates.
b. Input System (src/input.zig) – Captures and processes player input.
c. State Machine & Action States (src/ActionStates, src/ActionStates/StateMachine.zig, src/ActionStates/CommonStates.zig) – Manages different character states (attacking, jumping, etc.) and transitions.
d. Asset and Data Management (src/asset.zig, src/character_data.zig, assets directory) – Loads and parses JSON data and animations that drive character behavior.
e. Collision and Reaction Systems (src/collision_system.zig, src/reaction_system.zig) – Detect collisions and trigger reactions based on game events.
f. Rendering/GUI (src/raygui.zig, possibly integrated with editor.zig) – Displays the game visuals (using raygui for interface elements).
g. Utility Functions (src/utils) – Provides supporting math and general-purpose functions used across modules.
h. External/Third-Party Dependencies (vendor) – Additional libraries possibly used to augment functionality.

##### Relationships and Interactions
- The central Game Loop (main simulation) calls the Input module to capture player commands.
- Input data is processed and potentially triggers transitions within the State Machine (ActionStates).
- The Asset Manager loads character animations and JSON action definitions from the assets folder into the appropriate modules.
- Based on game state and player commands, the Collision System and Reaction System are invoked:
- The Collision System detects interactions (e.g., character attacks connecting), which then trigger state changes or reactions.
- The Reaction System handles the response animations and physics for collisions.
- The GUI/Rendering module uses raygui to display game status, debug interfaces, or editor elements.

##### Architectural Patterns and Design Principles
- Use of the Game Loop pattern for continuous update/render cycles.
- A State Machine pattern drives the varied character actions and transitions.
- Modular design: Separation of concerns between input, simulation, asset management, and collision handling.
- The file structure hints at a potential lightweight entity-component design (via src/component.zig) to manage game objects.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core Systems"
        A["Game Loop & Simulation"]:::engine
        B["Input System"]:::input
        C["State Machine & Action States"]:::state
        D["Asset & Data Management"]:::asset
        E["Collision & Reaction Systems"]:::collision
        F["Rendering/GUI"]:::render
        G["Utility Functions"]:::utils
    end

    subgraph "Support Systems"
        H["Third-Party Dependencies"]:::thirdparty
        I["Documentation/Design"]:::docs
    end

    B -->|"triggers"| A
    A -->|"updates"| C
    D -->|"supplies assets to"| C
    A -->|"checks collisions"| E
    E -->|"affects state"| C
    A -->|"renders"| F
    G -.->|"supports"| A
    G -.->|"supports"| C
    G -.->|"supports"| D
    F -->|"integrates with"| H

    I ---|"documents"| A
    I ---|"documents"| B
    I ---|"documents"| C
    I ---|"documents"| D
    I ---|"documents"| E
    I ---|"documents"| F
    I ---|"documents"| G

    classDef engine fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef input fill:#aaffaa,stroke:#333,stroke-width:2px;
    classDef state fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef asset fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef collision fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef render fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef utils fill:#ffff99,stroke:#333,stroke-width:2px;
    classDef thirdparty fill:#d9d9d9,stroke:#333,stroke-width:2px;
    classDef docs fill:#b3d9ff,stroke:#333,stroke-width:2px;

    click A "https://github.com/rcmagic/zigfightinggame/blob/main/src/main.zig"
    click A "https://github.com/rcmagic/zigfightinggame/blob/main/src/game.zig"
    click A "https://github.com/rcmagic/zigfightinggame/blob/main/src/game_simulation.zig"

    click B "https://github.com/rcmagic/zigfightinggame/blob/main/src/input.zig"

    click C "https://github.com/rcmagic/zigfightinggame/tree/main/src/ActionStates"
    click C "https://github.com/rcmagic/zigfightinggame/blob/main/src/ActionStates/StateMachine.zig"
    click C "https://github.com/rcmagic/zigfightinggame/blob/main/src/ActionStates/CommonStates.zig"

    click D "https://github.com/rcmagic/zigfightinggame/blob/main/src/asset.zig"
    click D "https://github.com/rcmagic/zigfightinggame/blob/main/src/character_data.zig"
    click D "https://github.com/rcmagic/zigfightinggame/tree/main/assets"

    click E "https://github.com/rcmagic/zigfightinggame/blob/main/src/collision_system.zig"
    click E "https://github.com/rcmagic/zigfightinggame/blob/main/src/reaction_system.zig"

    click F "https://github.com/rcmagic/zigfightinggame/blob/main/src/raygui.zig"
    click F "https://github.com/rcmagic/zigfightinggame/blob/main/src/editor.zig"

    click G "https://github.com/rcmagic/zigfightinggame/tree/main/src/utils"

    click H "https://github.com/rcmagic/zigfightinggame/tree/main/vendor"

    click I "https://github.com/rcmagic/zigfightinggame/tree/main/Docs"
```
