# rodriguezmldo/juego_espacial architecture

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

- Interactive diagram: https://gitdiagram.com/rodriguezmldo/juego_espacial
- Repository: https://github.com/rodriguezmldo/juego_espacial

## Overview

##### Project Type and Purpose
- This is a standalone 2D video-game written in Java (“juego_espacial”).
- It follows a classic game-loop architecture with distinct packages for game objects, rendering, input handling, UI screens, game states, and math utilities.

##### File Structure
- Top-level packages under src:
- main: entry point (main loop)
- interfaz: UI screens (menu, history, background loader)
- input: keyboard handler
- graphics: asset loader and rendering utilities
- states: game state management (e.g., menu state, play state)
- gameObjects: domain entities (asteroid, planet, player, laser, etc.)
- math: vector math utilities
- A parallel bin folder contains compiled classes; resources holds images, sounds, fonts, and data files.
- README confirms it’s a version-controlled Java video game for a programming class.

##### Main Components
a. Entry Point & Window
- Component: main.main → initializes Window and Game Loop
- Window (interfaz.Window) → game canvas and render context
b. Game Loop & State Manager
- Core loop drives update() and render() cycles
- states.GameState (abstract) & concrete state classes → encapsulate logic for menu, gameplay, pause, history screens
c. Input Module
- input.KeyBoard → polls key events and forwards them to current GameState or Player
d. Graphics/Asset Management
- graphics.Loader & graphics.Assets → load textures, sprites, fonts, and store in memory
e. Domain/Game Objects
- gameObjects.* → MovingObject, Player, Asteroid, Laser, Planet, Blackhole
- Constants define game-wide values
f. Math Module
- math.Vector2D → vector operations used by physics and movement
g. Resources
- File system abstraction or Resource Manager → reads from resources/gameData/data.txt and asset folders
h. External Dependencies
- Java runtime (AWT/Swing/Java2D)

##### Relationships and Interactions
- The Entry Point creates the Window and starts the Game Loop.
- On each frame:
- Input Module reads keyboard state → passes events to GameState.
- GameState.update() invokes entity logic in gameObjects using math.Vector2D.
- Graphics Module (Assets & Loader) supplies sprites to the Renderer.
- Renderer draws gameObjects, UI screens, and background onto Window canvas.
- GameState transitions (e.g., menu → play) happen via state manager.

##### Architectural Patterns and Design Principles
- Game Loop pattern for continuous update/render cycle.
- State pattern for menu/play/history screens.
- Separation of Concerns:
- Input handling isolated from game logic.
- Asset loading separated from rendering.
- Domain objects decoupled from UI code.
- Immutable constants and a utility math library for vector operations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Layer
    subgraph "Core"
        direction TB
        Entry["main.main()"]:::module
        Loop["Game Loop\nupdate()/render()"]:::module
    end

    %% UI / Window Layer
    subgraph "UI Layer"
        direction TB
        Window["interfaz.Window"]:::module
        Menu["interfaz.menu"]:::module
        History["interfaz.historyGame"]:::module
        BGLoader["interfaz.loadBackground"]:::module
    end

    %% State Manager
    subgraph "State Manager"
        direction TB
        GameState["states.GameState (abstract)"]:::module
        MenuState["states.MenuState\n(concrete)"]:::module
        PlayState["states.PlayState"]:::module
        PauseState["states.PauseState"]:::module
        HistoryState["states.HistoryState"]:::module
    end

    %% Input Handler
    subgraph "Input Module"
        direction TB
        Keyboard["input.KeyBoard"]:::module
    end

    %% Graphics / Asset Management
    subgraph "Graphics"
        direction TB
        Loader["graphics.Loader"]:::module
        Assets["graphics.Assets"]:::module
        Renderer["Rendering Subsystem"]:::module
    end

    %% Domain Entities
    subgraph "Domain Entities"
        direction TB
        GO["gameObjects.GameObject"]:::module
        MO["gameObjects.MovingObject"]:::module
        Player["gameObjects.Player"]:::module
        Asteroid["gameObjects.Asteroid"]:::module
        Blackhole["gameObjects.Blackhole"]:::module
        Planet["gameObjects.Planet"]:::module
        Laser["gameObjects.Laser"]:::module
        Constants["gameObjects.Constants"]:::module
    end

    %% Math Utilities
    subgraph "Math Utilities"
        direction TB
        Vector["math.Vector2D"]:::util
    end

    %% Resources
    subgraph "Resources"
        direction TB
        DataFile["resources/gameData/data.txt"]:::resource
        AssetsFolder["resources/\nimages/sounds/fonts/..."]:::resource
    end

    %% Initialization Flow
    Entry -->|"init Window"| Window
    Entry -->|"start Loop"| Loop
    Entry -->|"loadAssets()"| Loader
    Loader -->|"populate"| Assets

    %% Per-Frame Data Flow
    Loop -->|"pollKeys()"| Keyboard
    Keyboard -->|"events"| GameState
    Loop -->|"update()"| GameState
    GameState -->|"update Entities"| MO
    MO -->|"inherits"| GO
    MO -->|"uses"| Vector
    GameState -->|"render()"| Renderer
    Renderer -->|"draw()"| Window

    %% State Transitions
    GameState --> MenuState
    GameState --> PlayState
    GameState --> PauseState
    GameState --> HistoryState

    %% Domain Dependency
    GameState --> GO
    GO --> Constants

    %% Resource Access
    Assets --> AssetsFolder
    Loader --> DataFile

    %% External Dependencies
    Renderer ---|"uses AWT/Swing"| externalJava["Java2D/AWT/Swing"]:::external

    %% Click Events
    click Entry "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/main/main.java"
    click Window "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/interfaz/Window.java"
    click Menu "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/interfaz/menu.java"
    click History "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/interfaz/historyGame.java"
    click BGLoader "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/interfaz/loadBackground.java"
    click GameState "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/states/GameState.java"
    click Keyboard "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/input/KeyBoard.java"
    click Loader "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/graphics/Loader.java"
    click Assets "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/graphics/Assets.java"
    click Asteroid "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/gameObjects/Asteroid.java"
    click Blackhole "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/gameObjects/Blackhole.java"
    click Planet "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/gameObjects/Planet.java"
    click Player "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/gameObjects/Player.java"
    click Laser "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/gameObjects/Laser.java"
    click MO "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/gameObjects/MovingObject.java"
    click GO "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/gameObjects/GameObject.java"
    click Constants "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/gameObjects/Constants.java"
    click Vector "https://github.com/rodriguezmldo/juego_espacial/blob/main/src/math/Vector2D.java"
    click DataFile "https://github.com/rodriguezmldo/juego_espacial/blob/main/resources/gameData/data.txt"
    click AssetsFolder "https://github.com/rodriguezmldo/juego_espacial/tree/main/resources/"

    %% Styles
    classDef module fill:#e0f7e9,stroke:#2e7d32,stroke-width:2px
    classDef util fill:#e3f2fd,stroke:#0d47a1,stroke-width:2px
    classDef resource fill:#fff3e0,stroke:#e65100,stroke-width:2px
    classDef external fill:#eceff1,stroke:#607d8b,stroke-width:2px,stroke-dasharray: 5 5
```
