# psalant726/pac-man architecture

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

- Interactive diagram: https://gitdiagram.com/psalant726/pac-man
- Repository: https://github.com/psalant726/pac-man

## Overview

##### Component Details

a) Presentation Layer:
- Main.css styling component
- This to the Game Logic Layer

b) Game Logic Layer (Core):
- Surrounding core components:
- Maze Generator (maze.js)
- Pac-Man Entity (pacman.js)
- Villain/Ghost Entities (villain.js)
- Utility Functions (util.js)
- Play Game Controller (play_game.js)

c) Audio System Layer:
- Custom Audio Controller (audio.js)
- Audio Asset Pool
- Connection to the /assets/audio directory
- Support for both .mp3 and .ogg formats

##### Interaction Flows

- User Input → Game Controller
- Game Controller → Entity Updates
- Entity Updates → Canvas Rendering
- Game Events → Audio Controller
- Audio Controller → Audio Assets

##### The maze generation system's component

Technical notes showing:
- HTML5 Canvas as the primary rendering technology
- Vanilla JavaScript implementation
- Object-Oriented Programming structure
- Audio format support (.mp3/.ogg)

- Component types
- Special symbols used

Keep the abstraction level focused on the main architectural components while showing the unique aspects of this implementation, particularly the maze generation system and custom audio handling.

##### Canvas Rendering

Remember to highlight the asynchronous nature of the audio system and how it handles the continuous background music loop while managing intermittent sound effects.

This structure will give other developers a clear understanding of how the different components interact while maintaining the game's performance and responsiveness.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef presentation fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef audio fill:#FFD700,stroke:#333,stroke-width:2px
    classDef assets fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef dataflow fill:none,stroke:#FF0000,stroke-width:2px

    %% Presentation Layer
    subgraph Presentation
        Canvas["HTML5 Canvas Interface"]
        CSS["CSS Styling"]
    end
    
    %% Game Logic Layer
    subgraph GameLogic
        GameController["Game Controller"]
        MazeGen["Maze Generator"]
        PacMan["Pac-Man Entity"]
        Villain["Villain/Ghost Entities"]
        Util["Utility Functions"]
        PlayGame["Play Game Controller"]
    end
    
    %% Audio System Layer
    subgraph AudioSystem
        AudioCtrl["Audio Controller"]
        subgraph AudioAssets["Audio Asset Pool"]
            Death["Death Sound"]
            GhostEat["Ghost Eating"]
            PacEat["Pac-Man Eating"]
            PillEat["Pill Eating"]
            BGM["Background Music"]
            Opening["Opening Theme"]
        end
    end

    %% Relationships
    Canvas --> GameController
    CSS --> Canvas
    GameController --> MazeGen
    GameController --> PacMan
    GameController --> Villain
    GameController --> PlayGame
    GameController --> Util
    GameController --> AudioCtrl
    AudioCtrl --> AudioAssets
    GameController --> Canvas

    %% Click Events
    click Canvas "https://github.com/PSalant726/Pac-Man/blob/master/index.html"
    click CSS "https://github.com/PSalant726/Pac-Man/blob/master/assets/main.css"
    click GameController "https://github.com/PSalant726/Pac-Man/blob/master/lib/game.js"
    click MazeGen "https://github.com/PSalant726/Pac-Man/blob/master/lib/maze.js"
    click PacMan "https://github.com/PSalant726/Pac-Man/blob/master/lib/pacman.js"
    click Villain "https://github.com/PSalant726/Pac-Man/blob/master/lib/villain.js"
    click Util "https://github.com/PSalant726/Pac-Man/blob/master/lib/util.js"
    click PlayGame "https://github.com/PSalant726/Pac-Man/blob/master/lib/play_game.js"
    click AudioCtrl "https://github.com/PSalant726/Pac-Man/blob/master/lib/audio.js"
    click AudioAssets "https://github.com/PSalant726/Pac-Man/tree/master/assets/audio"
    click Death "https://github.com/PSalant726/Pac-Man/blob/master/assets/audio/die.mp3"
    click GhostEat "https://github.com/PSalant726/Pac-Man/blob/master/assets/audio/eatghost.mp3"
    click PacEat "https://github.com/PSalant726/Pac-Man/blob/master/assets/audio/eating.mp3"
    click PillEat "https://github.com/PSalant726/Pac-Man/blob/master/assets/audio/eatpill.mp3"
    click BGM "https://github.com/PSalant726/Pac-Man/blob/master/assets/audio/siren.mp3"
    click Opening "https://github.com/PSalant726/Pac-Man/blob/master/assets/audio/opening_song.mp3"

    %% Style Applications
    class Canvas,CSS presentation
    class GameController,MazeGen,PacMan,Villain,Util,PlayGame core
    class AudioCtrl audio
    class AudioAssets,Death,GhostEat,PacEat,PillEat,BGM,Opening assets

    %% Legend
    subgraph Legend
        P1["Presentation Components"]:::presentation
        C1["Core Game Logic"]:::core
        A1["Audio System"]:::audio
        AS1["Assets"]:::assets
    end
```
