# liorgonnen/pacman3d architecture

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

- Interactive diagram: https://gitdiagram.com/liorgonnen/pacman3d
- Repository: https://github.com/liorgonnen/pacman3d

## Overview

##### Main Components

a. Core Game Architecture:
- Game Engine Layer
- Rendering Layer
- Audio System
- Input Handler
- Asset Management
- Game Logic Controllers

b. Entity System:
- Entity Management
- Game Objects Hierarchy
- Physics/Collision System

##### Detailed Component Breakdown

Frontend (Browser):

- Web Browser      |

- WebGL Renderer  | |

Core Architecture:

- Game Engine    |     |  Asset Loader    |     |   Sound Player   |
- (Game.kt)        |<--->| (AssetLoader.kt) |<--->| (SoundPlayer.kt) |

- ↑

- Game Controller  |<--->|  Camera System   |
- (GameController.kt)|     |(CameraAnimator.kt|

Entity System Hierarchy:

- AbsGameEntity    |

- ↑

- MovableGameEntity    |

- ↑

- PacMan  | | Ghost  |

##### Key Design Elements to Highlight

- Blue: Core game systems
- Green: Entity components
- Yellow: Rendering components
- Red: Control systems

b. Connection Types:
- Double lines: Data flow

##### Architecture Patterns to Emphasize

- Component-based architecture (entities and renderables)
- MVC-like pattern (separation of logic and rendering)
- Observer pattern (for game state updates)
- Strategy pattern (ghost behaviors)

##### Important Subsystems

**Game Logic:**

- Ghost Behavior   |     |    Game State       |
- Controller     |<--->|    Management       |

**Rendering Pipeline:**

- Three.js Scene  |<--->|  Renderables    |<--->|   WebGL Output  |

##### Implementation Details

- Relationship between the Kotlin/JS code and Three.js bindings
- Asset pipeline (3D models, sounds, textures)
- Game state management flow
- How user input is processed through the system

##### Technical Stack Indicators

- Kotlin/JS     |

- ↓

- Three.js      |

- ↓

- WebGL        |

Remember to emphasize:
- The game loop architecture
- Entity management system
- Rendering pipeline
- Physics/collision detection
- Sound system integration
- Input handling
- Asset management

This will provide a clear understanding of how the different parts of the system interact while maintaining the specific implementation details of a 3D PacMan game.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Browser
        WebGL["WebGL Output"]
        ThreeJS["Three.js"]
        WebGL --> ThreeJS
    end

    subgraph Core["Core Game Systems"]
        GameEngine["Game Engine"]:::core
        AssetLoader["Asset Loader"]:::core
        SoundPlayer["Sound Player"]:::core
        GameController["Game Controller"]:::core
        CameraSystem["Camera System"]:::core

        GameEngine <--> AssetLoader
        GameEngine <--> SoundPlayer
        GameEngine <--> GameController
        GameController <--> CameraSystem
    end

    subgraph Entities["Entity System"]
        AbsGameEntity["Abstract Game Entity"]:::entity
        MovableEntity["Movable Game Entity"]:::entity
        PacMan["PacMan"]:::entity
        Ghost["Ghost"]:::entity

        AbsGameEntity --> MovableEntity
        MovableEntity --> PacMan
        MovableEntity --> Ghost
    end

    subgraph GameLogic["Game Logic"]
        GhostBehavior["Ghost Behavior Controller"]:::logic
        GameState["Game State Management"]:::logic
        GhostStrategy["Ghost Movement Strategies"]:::logic

        GhostBehavior <--> GameState
        GhostBehavior <--> GhostStrategy
    end

    subgraph Rendering["Rendering System"]
        PacManRender["PacMan Renderer"]:::render
        GhostRender["Ghost Renderer"]:::render
        MazeRender["Maze Renderer"]:::render
        ScoreRender["Score Renderer"]:::render
        StateBanner["Game State Banner"]:::render

        PacManRender --> ThreeJS
        GhostRender --> ThreeJS
        MazeRender --> ThreeJS
        ScoreRender --> ThreeJS
        StateBanner --> ThreeJS
    end

    GameEngine --> ThreeJS
    GameController --> GameState
    Ghost --> GhostBehavior
    PacMan --> PacManRender
    Ghost --> GhostRender

    classDef core fill:#3498db
    classDef entity fill:#2ecc71
    classDef logic fill:#e74c3c
    classDef render fill:#f1c40f

    click GameEngine "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/Game.kt"
    click SoundPlayer "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/SoundPlayer.kt"
    click AssetLoader "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/assets/AssetLoader.kt"
    click CameraSystem "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/camera/CameraAnimator.kt"
    click GameController "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/logic/controllers/GameController.kt"
    click AbsGameEntity "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/entities/AbsGameEntity.kt"
    click MovableEntity "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/entities/MovableGameEntity.kt"
    click PacMan "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/entities/PacMan.kt"
    click Ghost "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/entities/Ghost.kt"
    click GhostBehavior "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/logic/controllers/GhostBehaviorController.kt"
    click GhostStrategy "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/logic/behaviors/GhostMovementStrategy.kt"
    click GameState "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/logic/GameData.kt"
    click PacManRender "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/renderables/PacManRenderable.kt"
    click GhostRender "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/renderables/GhostRenderable.kt"
    click MazeRender "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/renderables/MazeRenderable.kt"
    click ScoreRender "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/renderables/ScoreRenderable.kt"
    click StateBanner "https://github.com/liorgonnen/pacman3d/blob/master/src/main/kotlin/pacman3d/renderables/GameStateBannerRenderer.kt"
```
