# pyflat/plant-the-bomb architecture

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

- Interactive diagram: https://gitdiagram.com/pyflat/plant-the-bomb
- Repository: https://github.com/pyflat/plant-the-bomb

## Overview

##### Project Type and Purpose
- It’s a 2D game with multiple levels (provided as map files) where the player places bombs, avoids hazards, and takes on enemies.
- The README describes user controls, game mechanics (e.g., bomb types, inventory management), and support for custom maps via an external map builder.

##### Breaking Down the File Structure
- Main Entry Point: The top-level main.py is the game’s starting script which likely handles the game loop, initialization, and overall flow.
- Maps Folder: Contains multiple .ptb files which define game levels. This folder represents the level or stage configuration component.
- Resources Folder: Contains modules like compressor.py and crypto.py. These likely handle auxiliary functions (e.g., data compression or encryption) used either for asset management or level data handling.
- Textures Folder: Holds image assets for the game’s visuals.
- Other files (.gitignore, LICENSE, README) indicate this is an organized, open-source project.

##### Key Components
a. Game Application (Core Engine)
- Block: Main Game Loop (from main.py)
- Responsibilities: Initialize game, manage game state, handle events, and update/render graphics.

b. Input/Control Module
- Represents user keyboard input (W, A, S, D for movement; Space, T, Y, M for various bomb placements).
- This feeds input events into the game loop.

c. Level/Map Manager
- Loads and parses map files from the "maps" folder.
- Handles level transitions and map-specific game logic.
- Integrates with the custom map builder tool (PTB-Map-Builder) as mentioned in the README.

d. Resource/Asset Manager
- Loads textures from the "textures" folder.
- Uses the resources modules (like compressor.py and crypto.py) to manage any additional data handling needs (for example, asset compression or encrypted level data).

e. Game Mechanics Module
- Contains logic for bomb placement, explosions, enemy behavior, inventory management, and power-ups (e.g., +Bomb, +Fire, Ghost, Shield).
- May be part of the core engine or broken into submodules.

f. UI/Inventory Display Module
- Handles the display of player inventory and in-game feedback (e.g., showing current bomb count, power-up statuses).

##### Relationships & Data Flow
- The Game Application (main loop) sits at the center, coordinating interactions between Input/Control, Level Manager, and Resource Manager.
- Input Module sends user commands to the core engine, which then updates the game state.
- The Level Manager loads the correct .ptb file and sends map data to the core engine.
- The Resource Manager supplies textures and any processed resource data to the rendering logic.
- Game Mechanics update enemy movements, bomb explosions, and handle collision detections, communicating state changes back into the main loop.
- UI/Inventory Display shows current statuses based on the state maintained by the Game Mechanics.

##### Architectural Patterns & Technologies
- MVC-like Separation: Even if not explicitly using a framework, there’s a natural separation between:
- Model: Game state (levels, player stats, enemy positions).
- View: Rendering using textures and visual assets.
- Controller: Handling input events and game logic.
- Modular Design: Each folder (maps, resources, textures) represents a distinct aspect that contributes to the overall architecture.
- Custom Maps and Extensibility: The design should make clear how external map data is loaded, which leaves room for future expansion (e.g., additional bomb types or power-ups).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Inputs"
        InputModule["Input/Control Module"]:::interface
        LevelManager["Level/Map Manager (maps/)"]:::external
    end

    subgraph "Asset Management"
        Resources["Resources (resources/)"]:::external
        Textures["Textures (textures/)"]:::external
    end

    subgraph "Core Engine"
        Engine["Game Application (main.py)"]:::core
        GameMech["Game Mechanics Module"]:::core
        UIDisplay["UI/Inventory Display Module"]:::ui
    end

    InputModule -->|"input"| Engine
    LevelManager -->|"mapData"| Engine
    Resources -->|"assetData"| Engine
    Textures -->|"visualAssets"| Engine
    Engine -->|"executesLogic"| GameMech
    GameMech -->|"stateUpdates"| Engine
    Engine -->|"updatesUI"| UIDisplay

    click Engine "https://github.com/pyflat/plant-the-bomb/blob/main/main.py"
    click LevelManager "https://github.com/pyflat/plant-the-bomb/tree/main/maps/"
    click Resources "https://github.com/pyflat/plant-the-bomb/tree/main/resources/"
    click Textures "https://github.com/pyflat/plant-the-bomb/tree/main/textures/"

    classDef core fill:#f9e79f,stroke:#b7950b,stroke-width:2px;
    classDef external fill:#aed6f1,stroke:#3498db,stroke-width:2px;
    classDef interface fill:#d5f5e3,stroke:#28b463,stroke-width:2px;
    classDef ui fill:#f5cba7,stroke:#d35400,stroke-width:2px;
```
