# ansari-1417/centipede-game-programming-fundamentals architecture

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

- Interactive diagram: https://gitdiagram.com/ansari-1417/centipede-game-programming-fundamentals
- Repository: https://github.com/ansari-1417/centipede-game-programming-fundamentals

## Overview

##### Project type and purpose
- This is a standalone desktop game written in C++ using SFML. It recreates Atari’s Centipede, with added themes, textures, sounds, and a state-driven menu system.

##### File structure
- Centipede.cpp: single entry point containing setup and the main game loop.
- Music/, Sound_Effects/, Textures/, Text/: resource folders loaded at runtime.
- README.md: confirms SFML usage, game states (menu, instructions, settings, gameplay), and asset‐driven design.

##### Main components
a. Core Application
- Main/Entry Point (Centipede.cpp) – initializes SFML RenderWindow, Resource Manager, Game State Manager, starts the game loop.
- Game Loop – the heartbeat: handles input, updates game logic, renders frames, plays audio.
b. Resource Manager
- Asset Loader – reads from Music/, Sound_Effects/, Textures/, Text/ → loads SFML textures, sounds, fonts.
- Cache – stores loaded SFML::Texture, SFML::SoundBuffer, etc., to avoid reloading.
c. State Management
- GameState Manager – switches between MenuState, PlayState, PauseState, SettingsState, HighscoreState, ExitState.
- Individual State Modules – encapsulate UI rendering, input handling, and state-specific updates.
d. Game Logic / Entities
- Entities – Centipede segments, player shooter, mushrooms, bullets, enemies (spiders, fleas, scorpions).
- Entity Controller – updates positions, resolves collisions, spawns/despawns.
- Difficulty Manager – increases centipede speed, mushrooms count per level.
e. Rendering Subsystem
- SFML Graphics – draws sprites, UI overlays, text.
- Renderer – invoked each frame by the game loop.
f. Input and Audio
- Input Handler – polls SFML events, dispatches to active GameState.
- Audio Manager – plays background music (Music/…), sound effects (Sound_Effects/…) on game events.

##### Relationships and interactions
- Entry Point → initializes Resource Manager, GameState Manager, Audio Manager.
- Game Loop → iteratively calls Input Handler → GameState Manager (current state’s handleEvent/ update) → Renderer → Audio Manager.
- Resource Manager ↔ all subsystems (states, entities, renderer, audio) to supply assets on demand.
- State Modules rely on Entity Controller and Renderer.
- Difficulty Manager influences Entity Controller parameters each level.

##### Architectural patterns & design principles
- State Pattern for screens/menu/gameplay.
- Singleton or central managers for Resources and Audio.
- Separation of concerns: input, update, render, resource loading.

- Labels: component names, “loads”, “renders”, “updates.”
- Arrowheads: direction of calls or data.
- Detail level: break states into submodules (MenuState vs PlayState) only if needed.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Asset storage
    subgraph "Asset Storage"
        Music["Music/"]:::asset
        SoundEffects["Sound_Effects/"]:::asset
        Textures["Textures/"]:::asset
        TextAssets["Text/"]:::asset
    end

    %% Documentation
    subgraph "Documentation & Config"
        README["README.md"]:::doc
        Screenshots["Screenshots/"]:::doc
    end

    %% Core Modules
    EntryPoint["Centipede.cpp\n(Entry Point)"]:::core
    ResourceManager["Resource Manager"]:::core
    GameLoop["Game Loop"]:::core
    GameStateManager["GameState Manager"]:::core
    InputHandler["Input Handler"]:::core
    Renderer["Renderer"]:::core
    AudioManager["Audio Manager"]:::core
    EntityController["Entity Controller"]:::core
    DifficultyManager["Difficulty Manager"]:::core

    %% External Library
    SFML["SFML Library"]:::external

    %% Control Flow
    EntryPoint -->|initializes| ResourceManager
    EntryPoint -->|initializes| GameStateManager
    EntryPoint -->|initializes| AudioManager
    EntryPoint -->|starts| GameLoop

    GameLoop -->|polls events| InputHandler
    InputHandler -->|dispatches| GameStateManager
    GameLoop -->|updates&renders| Renderer
    GameLoop -->|plays audio| AudioManager

    GameStateManager -->|controls| EntityController
    GameStateManager -->|invokes| Renderer
    GameStateManager -->|triggers| AudioManager

    EntityController -->|adjusts| DifficultyManager

    Renderer -->|draws via| SFML
    AudioManager -->|plays via| SFML
    InputHandler -->|uses| SFML

    %% Data Flow (Assets)
    Music -.->|"asset load"| ResourceManager
    SoundEffects -.->|"asset load"| ResourceManager
    Textures -.->|"asset load"| ResourceManager
    TextAssets -.->|"asset load"| ResourceManager

    ResourceManager -.->|"provides assets"| GameStateManager
    ResourceManager -.->|"provides assets"| EntityController
    ResourceManager -.->|"provides assets"| Renderer
    ResourceManager -.->|"provides assets"| AudioManager

    %% Click Events
    click EntryPoint "https://github.com/ansari-1417/centipede-game-programming-fundamentals/blob/main/Centipede.cpp"
    click Music "https://github.com/ansari-1417/centipede-game-programming-fundamentals/tree/main/Music/"
    click SoundEffects "https://github.com/ansari-1417/centipede-game-programming-fundamentals/tree/main/Sound_Effects/"
    click Textures "https://github.com/ansari-1417/centipede-game-programming-fundamentals/tree/main/Textures/"
    click TextAssets "https://github.com/ansari-1417/centipede-game-programming-fundamentals/tree/main/Text/"
    click README "https://github.com/ansari-1417/centipede-game-programming-fundamentals/blob/main/README.md"
    click Screenshots "https://github.com/ansari-1417/centipede-game-programming-fundamentals/tree/main/Screenshots/"

    %% Styles
    classDef core fill:#D0E8FF,stroke:#03689A,stroke-width:2px
    classDef asset fill:#E0FFE0,stroke:#2E7D32,stroke-width:2px,shape: cylinder
    classDef external fill:#E0E0E0,stroke:#757575,stroke-width:2px
    classDef doc fill:#FFF5E1,stroke:#FFA000,stroke-width:2px,stroke-dasharray: 5 5
```
