# unkzer0/bamboo-ping-pong-game architecture

> Architecture diagram of the GitHub repository unkzer0/bamboo-ping-pong-game, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/unkzer0/bamboo-ping-pong-game
- Repository: https://github.com/unkzer0/bamboo-ping-pong-game

## Overview

##### Project Type and Purpose
- This is a Unity 3D WebGL game (“Bamboo Ping Pong”), written in C#.
- It’s a lightweight, single‐scene game flow with menu, mode selection, and play scenes, built for browser deployment via WebGL.

##### File Structure
- Top‐level folders:
- Assets – all game assets (Audio, Image, Physics materials, Prefabs, Scenes, Scripts, TextMesh Pro plugin)
- Packages – Unity manifest and locks for dependencies (TextMesh Pro)
- ProjectSettings – engine/project configuration
- Key subfolders in Assets:
- Scenes: Main Menu.unity, Mode.unity, PlayGround.unity
- Prefabs: Ball, PowerUps
- Script: core game logic (GameManager, GameSettings, PaddleController, AIPaddle, Ball, UI togglers, PowerUpSpawner, etc.)
- Physics: custom physics materials
- Audio: sound effects

##### README Insights
- Tech stack: Unity 2021+, C#, WebGL
- Upcoming features hint at extendable modules (AI, power‐ups, skins)

a. Main Components
1. Unity Engine (Physics & Rendering subsystems)
2. Scenes (Menu, Mode Select, Play)
3. Game Manager (controls scene transitions, game state, scoring)
4. Input Layer (Unity InputManager → PaddleController)
5. AI Module (AIPaddle script)
6. Physics Module (Ball.cs + PhysicsMaterials)
7. PowerUp System (PowerUpSpawner, PowerUp scripts, Prefabs)
8. Audio System (AudioManager via ProjectSettings, triggered by GameManager/ball collisions)
9. UI Layer (TextMesh Pro components, UI togglers)
10. External Services: WebGL host (browser)

b. Relationships and Interactions
- User/browser → WebGL build → Unity Engine
- Engine initializes Scene → GameManager reads GameSettings → loads UI (Menu)
- Input Layer listens for player key events → PaddleController applies transform/physics forces
- AIPaddle component queries GameSettings → moves AI paddle via physics forces
- Ball collisions detected by Physics Engine → Ball.cs notifies GameManager → updates score/UI → may trigger PowerUpSpawner
- PowerUpSpawner instantiates Prefabs → impacts Ball/Paddle behaviors
- AudioManager plays sound events on collisions, scoring, UI toggles

c. Architectural Patterns and Principles
- Scene‐based modularity: each scene encapsulates its own UI and scripts
- Manager pattern: centralized GameManager/GameSettings for global state
- Component pattern: Unity MonoBehaviours on GameObjects (Ball, Paddle, PowerUp)
- Event‐driven interactions: use Unity Events (OnCollisionEnter, UI button callbacks)

d. Key Technologies, Frameworks, Libraries
- Unity Engine core modules: Physics2D, Audio, UI
- TextMesh Pro for UI text rendering
- C# scripts as MonoBehaviour components
- WebGL build pipeline for browser delivery

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External
    Browser["WebGL Host / Browser"]:::external

    %% Unity Engine Container
    subgraph "Unity Engine" 
        direction TB
        PhysicsSys["Physics Subsystem"]:::coreSubsyst
        RenderingSys["Rendering Subsystem"]:::coreSubsyst
        AudioSys["Audio Subsystem"]:::coreSubsyst
        InputSys["Input Subsystem"]:::coreSubsyst
        UISys["UI Subsystem"]:::coreSubsyst
    end

    %% Scenes (Assets)
    subgraph "Scenes" 
        direction TB
        MainMenuScene["Main Menu.unity"]:::asset
        ModeScene["Mode.unity"]:::asset
        PlayScene["PlayGround.unity"]:::asset
    end

    %% Game Managers & Settings
    GameManager["GameManager.cs"]:::gameScript
    GameSettings["GameSettings.cs"]:::gameScript

    %% Input Layer
    InputManagerAsset["InputManager.asset"]:::asset
    PaddleController["PaddleController.cs"]:::gameScript

    %% AI Module
    AIPaddle["AIPaddle.cs"]:::gameScript

    %% Physics Module
    BallScript["Ball.cs"]:::gameScript
    PhysicsMat["BouncyMateria.physicsMaterial2D"]:::asset

    %% Power-Up System
    PowerUpSpawner["PowerUpSpawner.cs"]:::gameScript
    PowerUpScript["PowerUp.cs"]:::gameScript
    PowerUpsPrefab["PowerUps.prefab"]:::asset

    %% Audio System
    AudioManagerAsset["AudioManager.asset"]:::asset
    MusicHandler["DontDestroyMusic.cs"]:::gameScript
    AudioAsset1["plastic-ball-bounce-14790.mp3"]:::asset
    AudioAsset2["retro-video-game-coin-pickup-38299.mp3"]:::asset
    AudioAsset3["panda-eating-bamboo-276086.mp3"]:::asset

    %% UI Layer & Plugins
    UIButtonToggler["UIButtonToggler.cs"]:::gameScript
    DifficultySelector["DifficultySelector.cs"]:::gameScript
    TextMeshPro["TextMesh Pro Plugin"]:::plugin

    %% Scene Entry
    PlayScript["Play.cs"]:::gameScript

    %% Connections
    Browser -->|"runs WebGL Build"| UnityEngine
    UnityEngine -->|"initializes"| GameManager
    GameManager -->|"loads scene"| MainMenuScene
    GameManager -->|"loads scene"| ModeScene
    GameManager -->|"loads scene"| PlayScene
    GameManager -->|"reads settings"| GameSettings
    MainMenuScene -->|contains| UIButtonToggler
    ModeScene -->|contains| DifficultySelector
    PlayScene -->|contains| PlayScript

    InputManagerAsset -->|"maps inputs"| InputSys
    InputSys -->|"listens for keys"| PaddleController
    PaddleController -->|"Apply Force"| PhysicsSys

    AIPaddle -->|"queries settings"| GameSettings
    AIPaddle -->|"moves via physics"| PhysicsSys

    PhysicsSys -->|"collision event"| BallScript
    BallScript -->|"Notify OnCollision"| GameManager
    GameManager -->|"Update Score/UI"| UISys
    GameManager -->|"Trigger PowerUp"| PowerUpSpawner

    PowerUpSpawner -->|"Instantiate Prefab"| PowerUpsPrefab
    PowerUpsPrefab -->|"Affects"| BallScript
    PowerUpsPrefab -->|"Affects"| PaddleController

    AudioManagerAsset -->|"configures"| AudioSys
    BallScript -->|"Play Bounce Sound"| AudioSys
    GameManager -->|"Play Score Sound"| AudioSys
    UIButtonToggler -->|"Play UI Sound"| AudioSys

    AudioSys -->|"plays"| AudioAsset1
    AudioSys -->|"plays"| AudioAsset2
    AudioSys -->|"plays"| AudioAsset3
    MusicHandler -->|"Persistent Music"| AudioSys

    TextMeshPro -->|integrates with| UISys

    %% Click Events
    click MainMenuScene "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Scenes/Main Menu.unity"
    click ModeScene "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Scenes/Mode.unity"
    click PlayScene "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Scenes/PlayGround.unity"
    click GameManager "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Script/GameManager.cs"
    click GameSettings "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Script/GameSettings.cs"
    click PaddleController "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Script/PaddleController.cs"
    click InputManagerAsset "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/ProjectSettings/InputManager.asset"
    click AIPaddle "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Script/AIPaddle.cs"
    click BallScript "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Script/Ball.cs"
    click PhysicsMat "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Physics/BouncyMateria.physicsMaterial2D"
    click PowerUpSpawner "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Script/PowerUpSpawner.cs"
    click PowerUpScript "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Script/PowerUp.cs"
    click PowerUpsPrefab "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Prefabs/PowerUps.prefab"
    click AudioAsset1 "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Audio/plastic-ball-bounce-14790.mp3"
    click AudioAsset2 "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Audio/retro-video-game-coin-pickup-38299.mp3"
    click AudioAsset3 "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Audio/panda-eating-bamboo-276086.mp3"
    click AudioManagerAsset "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/ProjectSettings/AudioManager.asset"
    click MusicHandler "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Script/DontDestroyMusic.cs"
    click UIButtonToggler "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Script/UIButtonToggler.cs"
    click DifficultySelector "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Script/DifficultySelector.cs"
    click TextMeshPro "https://github.com/unkzer0/bamboo-ping-pong-game/tree/main/Assets/TextMesh Pro/"
    click PlayScript "https://github.com/unkzer0/bamboo-ping-pong-game/blob/main/Assets/Script/Play.cs"

    %% Styles
    classDef coreSubsyst fill:#d0e6ff,stroke:#003399
    classDef gameScript fill:#d4f5d4,stroke:#009900
    classDef asset fill:#ffe5b4,stroke:#cc7000
    classDef external fill:#e0e0e0,stroke:#888888
    classDef plugin fill:#f2d4ff,stroke:#990099
```
