# sergiolneves/mountainshooter architecture

> Architecture diagram of the GitHub repository sergiolneves/mountainshooter, 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/sergiolneves/mountainshooter
- Repository: https://github.com/sergiolneves/mountainshooter

## Overview

##### Project type and purpose
- This is a desktop 2D arcade game (“Mountain Shooter”) written in Python, built on Pygame.
- It comprises a main game loop (main.py → Game), two playable levels, a coop-mode menu, sound assets, and a SQLite3 DB for persisting high scores.

##### File structure
- Top-level:
- asset/  → MP3 files for music and effects
- code/   → all the Python modules for game logic
- DBScore → the SQLite database file holding score data
- main.py → entry point, initializes Pygame and kicks off Game
- requirements.txt → external dependencies (pygame, sqlite3 built-in)
- code/:
- Game.py, Menu.py, Level.py → high-level orchestration of menu flow, levels, and the main loop
- EntityFactory.py → factory that instantiates Player, Enemy, Shots, etc.
- EntityMediator.py → implements the mediator pattern to route events between entities
- Entity.py, Player.py, Enemy.py, PlayerShot.py, EnemyShot.py → core domain objects
- Background.py, Const.py → static resources & constants
- Score.py, DBProxy.py → score model and persistence layer

##### README for additional insights
- Confirms Pygame as rendering & event engine
- Two levels with timeout events
- Coop play for two players
- SQLite3 DB for score storage

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Engine Layer
    subgraph "Engine Layer"
        direction TB
        PGE["Pygame Engine"]:::engine
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        Main["main.py"]:::app
        Game["Game Module"]:::app
        Menu["Menu Module"]:::app
        Level["Level Module"]:::app
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        Factory["EntityFactory"]:::domain
        Mediator["EntityMediator"]:::domain
        Entities["Entities"]:::domain
        EntityBase["Entity (Base)"]:::domain
        Player["Player"]:::domain
        Enemy["Enemy"]:::domain
        PShot["PlayerShot"]:::domain
        EShot["EnemyShot"]:::domain
        Background["Background"]:::domain
        Const["Const"]:::domain
        ScoreM["Score Manager"]:::domain
        DBP["DBProxy"]:::persistence
    end

    %% Persistence & Assets
    subgraph "Persistence & Assets"
        direction TB
        DB["SQLite3 DBScore"]:::persistence
        Assets["Audio Assets (MP3)"]:::assets
    end

    %% Relationships
    Main -->|"init()"| Game
    Game -->|"loadConstants()"| Const
    Game -->|"loadAssets()"| Assets
    Game -->|"startMenu() / startLevel()"| Menu
    Game -->|"startMenu() / startLevel()"| Level

    Game <-->|"draw() / pollEvents() / playSound()"| PGE

    Menu -->|"spawnEntity()"| Factory
    Level -->|"spawnEntity() / timeoutEvent()"| Factory

    Factory -->|"create()"| EntityBase
    EntityBase --> Player
    EntityBase --> Enemy
    EntityBase --> PShot
    EntityBase --> EShot
    EntityBase --> Background

    Player <-->|"events / collisions"| Mediator
    Enemy <-->|"events / collisions"| Mediator
    PShot <-->|"events / collisions"| Mediator
    EShot <-->|"events / collisions"| Mediator
    Background -->|"renderHint()"| Mediator

    Mediator -->|"routeEvents()"| Player
    Mediator -->|"routeEvents()"| Enemy
    Mediator -->|"routeEvents()"| PShot
    Mediator -->|"routeEvents()"| EShot

    PlayerShotEvent["scoringEvent"] -.-> ScoreM
    EnemyShotEvent["scoringEvent"] -.-> ScoreM
    ScoreM -->|"saveScore() / loadScore()"| DBP
    DBP -->|"read/write"| DB

    Assets -->|"audioPlay()"| PGE

    %% Click Events
    click Main "https://github.com/sergiolneves/mountainshooter/blob/main/main.py"
    click Game "https://github.com/sergiolneves/mountainshooter/blob/main/code/Game.py"
    click Menu "https://github.com/sergiolneves/mountainshooter/blob/main/code/Menu.py"
    click Level "https://github.com/sergiolneves/mountainshooter/blob/main/code/Level.py"
    click Factory "https://github.com/sergiolneves/mountainshooter/blob/main/code/EntityFactory.py"
    click Mediator "https://github.com/sergiolneves/mountainshooter/blob/main/code/EntityMediator.py"
    click EntityBase "https://github.com/sergiolneves/mountainshooter/blob/main/code/Entity.py"
    click Player "https://github.com/sergiolneves/mountainshooter/blob/main/code/Player.py"
    click Enemy "https://github.com/sergiolneves/mountainshooter/blob/main/code/Enemy.py"
    click PShot "https://github.com/sergiolneves/mountainshooter/blob/main/code/PlayerShot.py"
    click EShot "https://github.com/sergiolneves/mountainshooter/blob/main/code/EnemyShot.py"
    click Background "https://github.com/sergiolneves/mountainshooter/blob/main/code/Background.py"
    click Const "https://github.com/sergiolneves/mountainshooter/blob/main/code/Const.py"
    click ScoreM "https://github.com/sergiolneves/mountainshooter/blob/main/code/Score.py"
    click DBP "https://github.com/sergiolneves/mountainshooter/blob/main/code/DBProxy.py"
    click DB "https://github.com/sergiolneves/mountainshooter/tree/main/DBScore"
    click Assets "https://github.com/sergiolneves/mountainshooter/blob/main/asset/*.mp3"

    %% Styles
    classDef engine fill:#d0e7ff,stroke:#3399ff,color:#000;
    classDef app fill:#d9f2d9,stroke:#33cc33,color:#000;
    classDef domain fill:#ffe5b4,stroke:#ff9933,color:#000;
    classDef persistence fill:#ffd6d6,stroke:#ff3333,color:#000;
    classDef assets fill:#f2e6ff,stroke:#9933ff,color:#000;
```
