# petar812/space-invaders architecture

> Architecture diagram of the GitHub repository petar812/space-invaders, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/petar812/space-invaders
- Repository: https://github.com/petar812/space-invaders

## Overview

This is a C++ Space Invaders game. The principal workflow runs through the main loop: read input, update game state, check collisions, and render the current screen. Gameplay covers player movement and lives, alien movement and deaths, bullets, scoring, and menu/game-over states; sprite animation and font rendering support presentation. The excerpts show the loop and game logic, but omit some main-loop code, so unverified connections are left out.

Main entry points: [`src/main.cpp`](https://github.com/petar812/space-invaders/blob/main/src/main.cpp) (Game loop), [`src/game.cpp`](https://github.com/petar812/space-invaders/blob/main/src/game.cpp) (Game state), [`src/renderer.cpp`](https://github.com/petar812/space-invaders/blob/main/src/renderer.cpp) (Framebuffer renderer), [`src/input.cpp`](https://github.com/petar812/space-invaders/blob/main/src/input.cpp) (Keyboard input)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Game loop"]
  node_main["Game loop<br/>[main.cpp]"]
end

subgraph group_gameplay["Gameplay"]
  node_game["Game state<br/>[game.cpp]"]
end

subgraph group_entities["Game entities"]
  node_player["Player<br/>[player.cpp]"]
  node_alien["Alien<br/>[alien.cpp]"]
  node_bullet["Bullet<br/>[bullet.cpp]"]
end

subgraph group_presentation["Rendering"]
  node_renderer["Framebuffer renderer<br/>[renderer.cpp]"]
  node_sprite["Sprites and animation<br/>[sprite.cpp]"]
  node_font["Bitmap font<br/>[font.cpp]"]
end

subgraph group_input["Input"]
  node_input["Keyboard input<br/>[input.cpp]"]
end

node_user(("Player"))
node_glfw["GLFW window"]

node_main -->|"controls states"| node_game
node_main -->|"reads controls"| node_input
node_main -->|"draws screens"| node_renderer
node_main -->|"creates animations"| node_sprite
node_main -->|"draws text"| node_font
node_input -->|"registers callbacks"| node_glfw
node_user -.->|"presses keys"| node_input
node_main -->|"moves player"| node_player
node_game -->|"tracks player"| node_player
node_game -->|"creates and updates"| node_alien
node_game -->|"creates and updates"| node_bullet
node_renderer -->|"draws sprites"| node_sprite
node_renderer -->|"draws text"| node_font

click node_player "https://github.com/petar812/space-invaders/blob/main/src/player.cpp"
click node_alien "https://github.com/petar812/space-invaders/blob/main/src/alien.cpp"
click node_bullet "https://github.com/petar812/space-invaders/blob/main/src/bullet.cpp"
click node_game "https://github.com/petar812/space-invaders/blob/main/src/game.cpp"
click node_main "https://github.com/petar812/space-invaders/blob/main/src/main.cpp"
click node_input "https://github.com/petar812/space-invaders/blob/main/src/input.cpp"
click node_renderer "https://github.com/petar812/space-invaders/blob/main/src/renderer.cpp"
click node_sprite "https://github.com/petar812/space-invaders/blob/main/src/sprite.cpp"
click node_font "https://github.com/petar812/space-invaders/blob/main/src/font.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main toneBlue
class node_game toneAmber
class node_player,node_alien,node_bullet toneMint
class node_renderer,node_sprite,node_font toneRose
class node_input,node_user,node_glfw toneIndigo
```

## Components

### Game loop

- [Game loop](https://github.com/petar812/space-invaders/blob/main/src/main.cpp): `src/main.cpp`

### Gameplay

- [Game state](https://github.com/petar812/space-invaders/blob/main/src/game.cpp): `src/game.cpp`

### Game entities

- [Player](https://github.com/petar812/space-invaders/blob/main/src/player.cpp): `src/player.cpp`
- [Alien](https://github.com/petar812/space-invaders/blob/main/src/alien.cpp): `src/alien.cpp`
- [Bullet](https://github.com/petar812/space-invaders/blob/main/src/bullet.cpp): `src/bullet.cpp`

### Rendering

- [Framebuffer renderer](https://github.com/petar812/space-invaders/blob/main/src/renderer.cpp): `src/renderer.cpp`
- [Sprites and animation](https://github.com/petar812/space-invaders/blob/main/src/sprite.cpp): `src/sprite.cpp`
- [Bitmap font](https://github.com/petar812/space-invaders/blob/main/src/font.cpp): `src/font.cpp`

### Input

- [Keyboard input](https://github.com/petar812/space-invaders/blob/main/src/input.cpp): `src/input.cpp`

### Other components

- **Player**
- **GLFW window**

## Connections

- Game loop → Game state: controls states (evidence: `src/main.cpp`)
- Game loop → Keyboard input: reads controls (evidence: `src/main.cpp`)
- Game loop → Framebuffer renderer: draws screens (evidence: `src/main.cpp`)
- Game loop → Sprites and animation: creates animations (evidence: `src/main.cpp`)
- Game loop → Bitmap font: draws text (evidence: `src/main.cpp`)
- Keyboard input → GLFW window: registers callbacks
- Player → Keyboard input: presses keys
- Game loop → Player: moves player (evidence: `src/main.cpp`)
- Game state → Player: tracks player (evidence: `src/game.cpp`)
- Game state → Alien: creates and updates (evidence: `src/game.cpp`)
- Game state → Bullet: creates and updates (evidence: `src/game.cpp`)
- Framebuffer renderer → Sprites and animation: draws sprites
- Framebuffer renderer → Bitmap font: draws text
