# mohsenbg/2d-platformer architecture

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

- Interactive diagram: https://gitdiagram.com/mohsenbg/2d-platformer
- Repository: https://github.com/mohsenbg/2d-platformer

## Overview

Based on our analysis of both the file tree and the README file, this project is a 2D platformer game developed in Unity. The project follows the typical Unity structure with assets (including scenes, animations, sprites, prefabs, and scripts), plugins (such as SuperTiled2Unity and DOTween), and dedicated directories for game-specific files (_App). The purpose of the game – controlling a character through multiple levels while avoiding enemies and collecting coins – helps us identify the critical components and relationships.

##### Main Components
- Unity Engine as the underlying framework.
- Game Scenes: Include separate scenes for levels (in _App/Scenes) with different difficulty progressions and a main menu (Menu.unity).
- Game Manager and Controllers: Central scripts located in _App/Scripts/Manager (e.g., GameManager, SceneController, AudioManager, DBManager) that coordinate game flow, state, and level transitions.
- Player Component: Represented by the player prefab and associated scripts (PlayerMovement, PlayerAnimation, etc.) from _App/Scripts/Player and Sprites.
- Enemies and Obstacles: Components such as _App/Scripts/Enemies for enemy AI and animations, as well as prefab definitions for various enemy types and obstacles.
- UI and Menu Systems: UI-related assets (in _App/UI) that cover the pause menu, score, level menu, and other interactive elements.
- Audio System: Managed via _App/Audio assets and scripts handling sound effects and background audio.
- Database/Scoring System: The Assets/DB folder and SQLite plugin assets indicate that local storage is used to manage scores or game state persistence.
- External Plugins/Tooling: Plugins like SuperTiled2Unity (and its extensive plugin directory) support level importing and tile mapping, and DOTween for animations and tweening.

##### Relationships and Interactions
- Game Manager orchestrates scene transitions, game state (pause, resume, end game) and communicates with UI elements.
- The Player component interacts with Enemies, Obstacles, and Collectibles. For example, input from keyboard (left, right, jump controls) is fed into the player movement logic.
- The UI and Menu system receives updates from the Game Manager and player score components.
- External plugins supply additional functionality (for example, level layout by SuperTiled2Unity, animations with DOTween) that plugs into the main game flow.
- The Database subsystem is used by dedicated scripts to record and retrieve high scores or game data.

##### Architectural Patterns & Design Principles
- Modular separation: The project is logically separated by functionality – gameplay logic in _App, third-party integrations in Assets/Plugin, level/prefab assets in directories dedicated to scenes, animations, and UI.
- MVC or Controller-driven design: Although Unity’s component-based design is used, the Manager scripts effectively act as controllers coordinating between models (data in DB/ScriptableObjects) and views (UI, scenes).
- Event-driven interactions: Many systems (e.g., Game Manager, UI updates and pause controls) may use event-based communication.
- Dependency on external libraries/plugins: Notable reliance on SuperTiled2Unity for tile mapping and DOTween for animations/tweens.

##### Relevant Technologies & Frameworks
- Unity Engine (with its ProjectSettings configuration and Asset pipeline).
- SuperTiled2Unity (for tile-based level design).
- DOTween (for animation tweening within the game).
- SQLite integration (as seen in Assets/Plugin/SQLite) for saving scores or game state.
- Additional tools like Spriter2UnityDX for sprite animation support and the Unity UI Toolkit for UI systems.

## Diagram (Mermaid)

```mermaid
graph TD
    UnityEngine["Unity Engine"]:::engine

    subgraph "Game Scenes"
        Scenes["Game Scenes"]:::scene
    end

    subgraph "Core Game"
        subgraph "Managers"
            GM["GameManager"]:::manager
            SC["SceneController"]:::manager
            AM["AudioManager"]:::manager
            DM["DBManager"]:::manager
        end

        subgraph "Player Component"
            PP["Player Prefab"]:::player
            PS["Player Scripts"]:::player
        end

        subgraph "Enemies & Obstacles"
            ES["Enemy Scripts"]:::enemy
            EP["Enemy Prefabs"]:::enemy
            OS["Obstacle Scripts/Prefabs"]:::obstacle
        end

        subgraph "UI System"
            UIA["UI Assets"]:::ui
            UIS["UI Scripts"]:::ui
        end

        subgraph "Database/Scoring"
            DBF["Database Files"]:::database
            DBS["Database Scripts"]:::database
        end

        AA["Audio System"]:::audio
    end

    subgraph "External Plugins"
        SuperTiled["SuperTiled2Unity"]:::plugin
        DOTween["DOTween"]:::plugin
        Spriter["Spriter2UnityDX"]:::plugin
    end

    UnityEngine --> Scenes
    GM -->|"sceneTransition"| Scenes
    GM -->|"UIUpdate"| UIA
    GM -->|"audioControl"| AA
    GM -->|"dbSave"| DBF

    PP -->|"collidesWith"| ES
    PP -->|"triggers"| OS
    PS -->|"scoreUpdate"| UIS

    DOTween -->|"animates"| PS
    DOTween -->|"animates"| ES
    Spriter -->|"spriteAnimation"| PS
    SuperTiled -->|"levelImport"| Scenes

    classDef engine fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef scene fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef manager fill:#F4A460,stroke:#000,stroke-width:2px;
    classDef player fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef enemy fill:#FFC0CB,stroke:#000,stroke-width:2px;
    classDef obstacle fill:#FFDEAD,stroke:#000,stroke-width:2px;
    classDef ui fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef audio fill:#87CEFA,stroke:#000,stroke-width:2px;
    classDef database fill:#FFFACD,stroke:#000,stroke-width:2px;
    classDef plugin fill:#E6E6FA,stroke:#000,stroke-width:2px;

    click Scenes "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/_App/Scenes"
    click GM "https://github.com/mohsenbg/2d-platformer/blob/main/Assets/_App/Scripts/Manager/GameManager.cs"
    click SC "https://github.com/mohsenbg/2d-platformer/blob/main/Assets/_App/Scripts/Manager/SceneController.cs"
    click AM "https://github.com/mohsenbg/2d-platformer/blob/main/Assets/_App/Scripts/Manager/AudioManager.cs"
    click DM "https://github.com/mohsenbg/2d-platformer/blob/main/Assets/_App/Scripts/Manager/DBManager.cs"
    click PP "https://github.com/mohsenbg/2d-platformer/blob/main/Assets/_App/Prefab/Player.prefab"
    click PS "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/_App/Scripts/Player"
    click ES "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/_App/Scripts/Enemies"
    click EP "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/_App/Prefab"
    click OS "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/_App/Scripts/Obstacle"
    click UIA "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/_App/UI"
    click UIS "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/_App/Scripts/UI"
    click AA "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/_App/Audio"
    click DBF "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/DB"
    click DBS "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/_App/Scripts/DB"
    click SuperTiled "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/Plugin/SuperTiled2Unity"
    click DOTween "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/Plugins/Demigiant/DOTween"
    click Spriter "https://github.com/mohsenbg/2d-platformer/tree/main/Assets/Spriter2UnityDX"
```
