# m-dudash/perfidia architecture

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

- Interactive diagram: https://gitdiagram.com/m-dudash/perfidia
- Repository: https://github.com/m-dudash/perfidia

## Overview

- Game Engine / Main Loop:
– Represented by main.py and the central “Game” class.
– This module controls the game cycle, state transitions (from start screen to levels to cutscenes) and orchestrates other subsystems.
- Level Manager:
– The Level class (in level.py) is responsible for loading TMX map files from the assets/map folder, managing tiles, enemy spawn points, backgrounds, and the parallax effect.
- UI & Screen Components:
– Include StartScreen (start_screen.py), HellScreen (hell_screen.py), and Cutscene (cutscene.py) modules.
– These components manage menus, introductory screens, cutscenes (like the final sequence at the ninth circle), and debug transitions (e.g., switching levels with TAB).
- Game Entities:
– Player (player.py), Enemy (enemy.py), and Fire (fire.py) classes are central to the gameplay.
– Additionally, CorruptionBar (corruption_bar.py) and HealthBar (health_bar.py) represent the in-game status displays.
- Asset Manager:
– Although not explicitly a class, the assets folder (with subfolders for audio, backgrounds, enemy sprites, etc.) indicates the resource management piece.
- Audio Manager:
– Conceptually group the audio assets (both music and sound effects) and note that sound management logic (likely integrated within the Game or individual modules) loads audio files (from assets/audio) based upon context (level beginnings, actions, transitions).

##### Relationships & Data Flow
- The Game Engine calls the Level Manager to load a level, which in turn loads the appropriate map (TMX files) and associated assets (backgrounds, enemy spawn points).
- The Player, Enemy, and Fire modules interact with the Level object for collisions, physics, and triggering game logic (damage, movement, etc.).
- UI components (StartScreen, HellScreen) communicate with the Game Engine to trigger state changes and update on-screen elements.
- The Asset Manager supplies visual and audio resources to entities, levels, and UI components.
- The Audio Manager receives triggers from state changes or events (e.g., player attack, enemy death) and plays the corresponding sounds from the assets.

##### Architectural Patterns & Design Principles
- Modularity: The project is subdivided by functionality (each game entity and system has its own module) making it easier to maintain and update.
- Separation of Concerns: There’s a clear division between game logic (Player, Enemy, Level), UI management (Start/Cut/Hell screens, bars), and resource management (assets for graphics and audio).
- Event-Driven & Update Loop: The main game loop continuously updates entities and listens for input, which is a common pattern in game development using Pygame.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Engine
    subgraph "Core Engine"
        GE["Game Engine/Main Loop"]:::module
        LM["Level Manager"]:::module
        GE -->|"triggers_load"| LM
    end

    %% UI Components
    subgraph "UI Components"
        Start["StartScreen"]:::ui
        Hell["HellScreen"]:::ui
        Cut["Cutscene"]:::ui
        GE -->|"state_transition"| Start
        GE -->|"state_transition"| Hell
        GE -->|"state_transition"| Cut
    end

    %% Game Entities
    subgraph "Game Entities"
        P["Player"]:::entity
        E["Enemy"]:::entity
        F["Fire"]:::entity
        HB["HealthBar"]:::entity
        CB["CorruptionBar"]:::entity
        LM -->|"collision_check"| P
        LM -->|"collision_check"| E
        LM -->|"collision_check"| F
    end

    %% Assets and Audio
    subgraph "Assets & Audio"
        AM["Assets Manager (resources)"]:::assets
        AUD["Audio Manager"]:::audio
        AM -->|"supplies"| P
        AM -->|"supplies"| E
        AM -->|"supplies"| F
        AM -->|"supplies"| Start
        AM -->|"supplies"| Hell
        AM -->|"supplies"| Cut
        AUD -->|"plays"| GE
    end

    %% User Input fed to Game Engine
    UI["User_Input"]:::module
    UI -->|"handles_input"| GE

    %% Click Events
    click GE "https://github.com/m-dudash/perfidia/blob/main/main.py"
    click LM "https://github.com/m-dudash/perfidia/blob/main/level.py"
    click Start "https://github.com/m-dudash/perfidia/blob/main/start_screen.py"
    click Hell "https://github.com/m-dudash/perfidia/blob/main/hell_screen.py"
    click Cut "https://github.com/m-dudash/perfidia/blob/main/cutscene.py"
    click P "https://github.com/m-dudash/perfidia/blob/main/player.py"
    click E "https://github.com/m-dudash/perfidia/blob/main/enemy.py"
    click F "https://github.com/m-dudash/perfidia/blob/main/fire.py"
    click HB "https://github.com/m-dudash/perfidia/blob/main/health_bar.py"
    click CB "https://github.com/m-dudash/perfidia/blob/main/corruption_bar.py"
    click AM "https://github.com/m-dudash/perfidia/tree/main/assets"
    click AUD "https://github.com/m-dudash/perfidia/tree/main/assets/audio"

    %% Styles
    classDef module fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef ui fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef entity fill:#ccccff,stroke:#0000cc,stroke-width:2px;
    classDef assets fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef audio fill:#ffebcc,stroke:#cc6600,stroke-width:2px;
```
