# bayatgames/redrunner architecture

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

- Interactive diagram: https://gitdiagram.com/bayatgames/redrunner
- Repository: https://github.com/bayatgames/redrunner

## Overview

- Unity Game Engine Core – Represent the overall Unity framework that ties everything together.
- Scenes – Include the two primary scenes (e.g., “Creation” and “Play”) which serve as entry points to the game flow.
- Core Gameplay Systems – This should include central scripts such as the GameManager, character controllers, enemy behavior (see scripts under RedRunner/Enemies), and Terrain Generation (from RedRunner/TerrainGeneration). These components manage the core game logic like player movement, enemy interactions, and environment generation.
- Animation & Visuals – Represent the extensive animation directory (Animations), including character animations, UI animations, and prefab controllers. Mention integration of sprite assets, animation controllers, and shaders.
- UI Subsystem – Include UI elements (screens, buttons, text, share buttons, etc.) as defined under Scripts/RedRunner/UI and the corresponding prefabs and sprites. This portion controls start screens, in-game score display, pause screens, and more.
- Audio Subsystem – Highlight AudioManager and the various sound directories (Character, Enemies, UI, Environment) that manage sound effects and music.
- Save System – Indicate that the project integrates an open source save functionality (SaveGameFree) with its library components (Scripts/SaveGameFree) that support auto-save, web saves, and custom save methods.
- Editor and Utilities – Represent development tools and utilities scripts, such as those under Assets/Editor and Scripts/Utils/Utilities. These can be noted as supporting modules that are not part of the runtime but essential for level/component design.

##### Out Relationships and Interactions
- The GameManager mediates between Scene transitions, input capture (via CameraControl and UI scripts), and gameplay state.
- UI components (buttons, screens, and text) send events to GameManager or AudioManager.
- The Animation subsystem interacts with character controllers and state machines (via prefabs and animation controllers).
- The Save System communicates with game state scripts (like GameManager) to persist player progress.
- That all these systems are running under the umbrella of the Unity engine, leveraging its physics, rendering, and event systems.

##### Architectural Patterns and Design Principles
- Event-Driven Interaction – Many Unity projects handle interactions via events (e.g., UI button clicks triggering methods in GameManager). Indicate these events or messaging flows where applicable.
- Modular Design – The SaveGameFree system is a modular, external integration; show it as an independent module that feeds into and receives data from gameplay systems.
- MVC-like Organization – While not strictly MVC, there is a pattern where UI components (view) interact with controllers (GameManager, UIManager) which in turn coordinate with the domain logic (game character and scene management).

##### Incorporate Relevant Technologies and Frameworks
- Clearly label that the project uses the Unity game engine.
- That C# is the scripting language (as evident from the .cs files).
- External libraries and plugins such as SaveGameFree and possibly third-party assets (like Save Game Pro or platform assets).

##### Detailing Specific Components
- Under “Gameplay Systems,” list subcomponents like:
- Character Controller (RedCharacter, Character)
- Enemy AI (scripts like Enemy, Mace, Saw, Spike, Water)
- Terrain Generation (all scripts under RedRunner/TerrainGeneration including the DefaultTerrainGenerator and settings)
- Under “UI Subsystem,” detail components like:
- UI Screens (StartScreen, PauseScreen, InGameScreen, EndScreen)
- UI Managers (UIManager)
- UI assets (text, images from Sprites/RedRunner/GUI)
- Under “Audio,” ensure the AudioManager and sound events (triggered by character actions, UI clicks, enemy actions) are shown.

##### Final Remarks
- Do not shy away from adding multiple layers if needed. The more granular you break out each component, the better the final design will serve as documentation.
- Lastly, ensure components that have external dependencies (like SaveGameFree or external assets) are clearly marked as such.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Unity Game Engine Core"
        UGE("Unity Game Engine Core"):::core
    end

    subgraph "Scenes"
        SC1("Creation Scene"):::scene
        SC2("Play Scene"):::scene
    end

    subgraph "Core Gameplay Systems"
        CGP1("GameManager"):::module
        subgraph "Character Controllers"
            CC1("Character Controller: Character"):::module
            CC2("Character Controller: RedCharacter"):::module
        end
        subgraph "Enemy Behavior"
            EB1("Enemy"):::module
            EB2("Eye"):::module
            EB3("Mace"):::module
            EB4("Saw"):::module
            EB5("Spike"):::module
            EB6("Water"):::module
        end
        subgraph "Terrain Generation"
            TG1("DefaultTerrainGenerator"):::module
            TG2("TerrainGenerator"):::module
            TG3("Other Terrain Scripts"):::module
        end
    end

    subgraph "Animation & Visuals"
        AVA1("Animations Directory"):::module
        AVA2("Character Animation Controller"):::module
        AVA3("Sprites & GUI Assets"):::module
    end

    subgraph "UI Subsystem"
        UIA1("UI Scripts"):::module
        UIA2("UI Manager"):::module
        UIA3("UI Prefabs & Animations"):::module
    end

    subgraph "Audio Subsystem"
        AUD1("Audio Manager"):::module
        AUD2("Sound Files"):::module
    end

    subgraph "Save System"
        SAV1("SaveGameFree Integration"):::module
    end

    subgraph "Editor & Utilities"
        EDU1("Editor Scripts"):::module
        UT1("In-Game Utilities"):::module
        UT2("General Utilities"):::module
    end

    %% Connections between major components, keeping vertical flow
    UGE -->|"runs"| SC1
    UGE -->|"runs"| SC2

    SC1 -->|"triggers"| CGP1
    SC2 -->|"triggers"| CGP1

    CGP1 -->|"controls"| CC1
    CGP1 -->|"controls"| CC2

    CGP1 -->|"manages"| EB1
    CGP1 -->|"manages"| EB2
    CGP1 -->|"manages"| EB3
    CGP1 -->|"manages"| EB4
    CGP1 -->|"manages"| EB5
    CGP1 -->|"manages"| EB6

    CGP1 -->|"invokes"| TG1
    CGP1 -->|"invokes"| TG2
    CGP1 -->|"invokes"| TG3

    UIA1 -->|"triggers"| CGP1
    UIA1 -->|"controls"| UIA2

    AVA1 -->|"supplies visuals to"| CC1
    AVA1 -->|"supplies visuals to"| CC2
    AVA2 -->|"controls animations for"| CC1
    AVA2 -->|"controls animations for"| CC2
    AVA3 -->|"used in"| UIA1

    AUD1 -->|"plays sound for"| CC1
    AUD1 -->|"plays sound for"| CC2
    AUD1 -->|"plays sound for"| UIA1

    CGP1 -->|"saves game state"| SAV1

    EDU1 -->|"supports"| CGP1
    UT1 -->|"assists"| CGP1
    UT2 -->|"assists"| UIA1

    %% Styles
    classDef core fill:#e8f8f5,stroke:#1abc9c,stroke-width:2px;
    classDef scene fill:#fef9e7,stroke:#f1c40f,stroke-width:2px;
    classDef module fill:#fdebd0,stroke:#e67e22,stroke-width:2px;

    %% Click Events
    click SC1 "https://github.com/bayatgames/redrunner/blob/master/Assets/Scenes/Creation.unity"
    click SC2 "https://github.com/bayatgames/redrunner/blob/master/Assets/Scenes/Play.unity"
    click CGP1 "https://github.com/bayatgames/redrunner/blob/master/Assets/Scripts/RedRunner/GameManager.cs"
    click CC1 "https://github.com/bayatgames/redrunner/blob/master/Assets/Scripts/RedRunner/Characters/Character.cs"
    click CC2 "https://github.com/bayatgames/redrunner/blob/master/Assets/Scripts/RedRunner/Characters/RedCharacter.cs"
    click EB1 "https://github.com/bayatgames/redrunner/tree/master/Assets/Scripts/RedRunner/Enemies"
    click TG1 "https://github.com/bayatgames/redrunner/tree/master/Assets/Scripts/RedRunner/TerrainGeneration"
    click AVA1 "https://github.com/bayatgames/redrunner/tree/master/Assets/Animations"
    click AVA2 "https://github.com/bayatgames/redrunner/blob/master/Assets/Animations/Characters/RedRunner.controller"
    click AVA3 "https://github.com/bayatgames/redrunner/tree/master/Assets/Sprites/RedRunner/GUI"
    click UIA1 "https://github.com/bayatgames/redrunner/tree/master/Assets/Scripts/RedRunner/UI"
    click UIA2 "https://github.com/bayatgames/redrunner/blob/master/Assets/Scripts/RedRunner/UIManager.cs"
    click UIA3 "https://github.com/bayatgames/redrunner/tree/master/Assets/Animations/UI"
    click AUD1 "https://github.com/bayatgames/redrunner/blob/master/Assets/Scripts/RedRunner/AudioManager.cs"
    click AUD2 "https://github.com/bayatgames/redrunner/tree/master/Assets/Sounds"
    click SAV1 "https://github.com/bayatgames/redrunner/tree/master/Assets/SaveGameFree"
    click EDU1 "https://github.com/bayatgames/redrunner/tree/master/Assets/Editor"
    click UT1 "https://github.com/bayatgames/redrunner/tree/master/Assets/Scripts/RedRunner/Utilities"
    click UT2 "https://github.com/bayatgames/redrunner/tree/master/Assets/Scripts/Utils"
```
