# noluca/tower-defence architecture

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

- Interactive diagram: https://gitdiagram.com/noluca/tower-defence
- Repository: https://github.com/noluca/tower-defence

## Overview

##### Project type and purpose
- This is a desktop “Tower Defence” game built entirely in Processing (Java-based).
- Purpose: render a game loop, accept user input to place towers, spawn and move enemy units along a path, track lives, and end the game when lives reach zero.

##### File structure
- Top-level PDE files correspond to key classes/modules:
- Main.pde: application entry point and game loop
- Menu.pde: main menu UI
- Griglia.pde: grid on which you place towers
- Bottone.pde & Cliccabile.pde: button and clickable UI abstractions
- Nemico*.pde: enemy classes (Nemico, NemicoVeloce)
- NemicoManager.pde: enemy spawn and lifecycle management
- Percorso.pde & Punto.pde: path and waypoint management
- sketch.properties and sketch_250123a.pde are Processing configuration files.
- README.md describes gameplay and links to a UML PDF.

##### README for additional insights
- Gameplay loop: spawn red-square enemies → they move along the path → if they reach the goal, decrement player lives → game over at zero lives.
- Right-click places blue-square towers on the grid.

a. Main components
1. Processing Runtime (game engine)
2. Input Handler (mouse events)
3. UI Layer
- Menu Screen
- Grid & Buttons
4. Game State Manager (Main)
5. Entity Layer
- Towers (clickable grid cells)
- Enemies (Nemico, NemicoVeloce)
6. EnemyManager (spawn logic & lifecycle)
7. Pathing Module (Percorso & Punto)
8. Rendering Subsystem
9. Collision/Range Checking
10. Score/Lives Tracker

b. Relationships and Interactions
- Input Handler listens for mouse clicks and forwards “build tower” events to Game State Manager.
- Game State Manager updates EnemyManager, Towers, and LivesTracker.
- EnemyManager references the Pathing Module to move each Nemico along Percorso’s Punto list.
- Rendering Subsystem draws UI Layer, Grid, Towers, and Enemies in each frame.
- Collision/Range Checking: Towers query Enemy positions each update to decide when to shoot (if implemented).

c. Architectural patterns/design principles
- Single-threaded, event-driven architecture
- Manager pattern for grouping dynamic entities (EnemyManager)
- Separation of concerns: UI components vs. game logic vs. pathfinding

d. Key technologies/frameworks
- Processing (Java-based sketch environment)
- PDE file modules serve as classes
- UML for static class relationships

##### Essential details not to omit
- Interaction points: input → UI → game state.
- Entity relationships: EnemyManager holds Nemico instances; Path holds Punto waypoints.
- Rendering is invoked each frame for all active entities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Processing Runtime
    PR["Processing Runtime\n(setup(), draw())"]:::engine

    %% Game Logic / Managers
    GSM["Game State Manager\n(Main)"]:::logic
    EM["EnemyManager"]:::logic
    LT["LivesTracker"]:::logic

    %% Input Handler
    IH["Input Handler\n(Cliccabile & Bottone)"]:::ui

    %% UI Layer
    subgraph "UI Layer"
        MS["Menu Screen"]:::ui
        GR["Grid & Tower Placement"]:::ui
    end

    %% Entity Layer
    subgraph "Entity Layer"
        T["Towers"]:::ui
        NE1["Basic Enemy\n(Nemico)"]:::enemy
        NE2["Fast Enemy\n(NemicoVeloce)"]:::enemy
    end

    %% Pathing Module
    subgraph "Pathing Module"
        PC["Path\n(Percorso)"]:::path
        PT["Waypoint\n(Punto)"]:::path
    end

    %% Rendering
    RS["Rendering Subsystem"]:::logic

    %% Configuration
    CFG["Configuration & Metadata"]:::config

    %% Connections
    PR -->|"calls setup()"| GSM
    PR -->|"calls draw()"| GSM
    PR -->|"calls draw()"| RS

    IH -.->|“mouse click”| GSM

    GSM -->|"spawn()"| EM
    GSM -->|"update towers" | T
    GSM -->|"update lives"| LT

    EM -->|“create Nemico”| NE1
    EM -->|“create NemicoVeloce”| NE2
    EM -->|"update enemies"| NE1
    EM -->|"update enemies"| NE2

    NE1 -->|"moveAlongPath()"| PC
    NE2 -->|"moveAlongPath()"| PC
    PC -->|"waypoints"| PT

    NE1 -->|“reach goal”| LT
    NE2 -->|“reach goal”| LT

    RS -->|"draw Menu"| MS
    RS -->|"draw Grid"| GR
    RS -->|"draw Towers"| T
    RS -->|"draw Enemies"| NE1
    RS -->|"draw Enemies"| NE2

    CFG -.-> PR

    %% Click events
    click PR "https://github.com/noluca/tower-defence/blob/main/Main.pde"
    click GSM "https://github.com/noluca/tower-defence/blob/main/Main.pde"
    click IH "https://github.com/noluca/tower-defence/blob/main/Cliccabile.pde"
    click IH "https://github.com/noluca/tower-defence/blob/main/Bottone.pde"
    click MS "https://github.com/noluca/tower-defence/blob/main/Menu.pde"
    click GR "https://github.com/noluca/tower-defence/blob/main/Griglia.pde"
    click EM "https://github.com/noluca/tower-defence/blob/main/NemicoManager.pde"
    click NE1 "https://github.com/noluca/tower-defence/blob/main/Nemico.pde"
    click NE2 "https://github.com/noluca/tower-defence/blob/main/NemicoVeloce.pde"
    click PC "https://github.com/noluca/tower-defence/blob/main/Percorso.pde"
    click PT "https://github.com/noluca/tower-defence/blob/main/Punto.pde"
    click RS "https://github.com/noluca/tower-defence/blob/main/Main.pde"
    click RS "https://github.com/noluca/tower-defence/blob/main/Menu.pde"
    click RS "https://github.com/noluca/tower-defence/blob/main/Griglia.pde"
    click RS "https://github.com/noluca/tower-defence/blob/main/Bottone.pde"
    click RS "https://github.com/noluca/tower-defence/blob/main/Nemico.pde"
    click RS "https://github.com/noluca/tower-defence/blob/main/NemicoVeloce.pde"
    click CFG "https://github.com/noluca/tower-defence/blob/main/sketch.properties"
    click CFG "https://github.com/noluca/tower-defence/blob/main/sketch_250123a.pde"
    click CFG "https://github.com/noluca/tower-defence/blob/main/README.md"

    %% Styles
    classDef engine fill:#f9f,stroke:#333,stroke-width:1px;
    classDef logic fill:#afa,stroke:#333,stroke-width:1px;
    classDef ui fill:#bbf,stroke:#333,stroke-width:1px;
    classDef enemy fill:#f99,stroke:#333,stroke-width:1px;
    classDef path fill:#f66,stroke:#333,stroke-width:1px;
    classDef config fill:#ddd,stroke:#333,stroke-width:1px;
```
