# griffinm64/asteroids architecture

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

- Interactive diagram: https://gitdiagram.com/griffinm64/asteroids
- Repository: https://github.com/griffinm64/asteroids

## Overview

This is a small Pygame Asteroids game. The player controls a ship, the game loop updates and draws sprites, an asteroid field spawns asteroids, and shots can split them; colliding with the player ends the game. The shared circle base provides position, velocity, radius, and collision checks. Edges show only relationships visible in the excerpts; group updates and draws are dispatched by the main loop.

Main entry points: [`main.py`](https://github.com/griffinm64/asteroids/blob/main/main.py) (Game loop), [`player.py`](https://github.com/griffinm64/asteroids/blob/main/player.py) (Player ship), [`asteroid.py`](https://github.com/griffinm64/asteroids/blob/main/asteroid.py) (Asteroid), [`shot.py`](https://github.com/griffinm64/asteroids/blob/main/shot.py) (Shot)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Game runtime"]
  node_game_loop["Game loop<br/>[main.py]"]
end

subgraph group_gameplay["Gameplay entities"]
  node_asteroid_field["Asteroid field<br/>[asteroidfield.py]"]
  node_player_ship["Player ship<br/>[player.py]"]
  node_asteroid["Asteroid<br/>[asteroid.py]"]
  node_shot["Shot<br/>[shot.py]"]
end

subgraph group_shared["Shared foundation"]
  node_circle_shape["Circle shape<br/>[circleshape.py]"]
  node_constants["Game constants<br/>[constants.py]"]
end

node_player_user(("Player"))

node_player_user -->|"quits game"| node_game_loop
node_player_user -->|"controls"| node_player_ship
node_game_loop -->|"creates"| node_asteroid_field
node_game_loop -->|"creates"| node_player_ship
node_game_loop -->|"updates and draws"| node_asteroid
node_game_loop -->|"updates and draws"| node_player_ship
node_game_loop -->|"updates and draws"| node_shot
node_game_loop -->|"checks collisions"| node_asteroid
node_game_loop -->|"checks collisions"| node_player_ship
node_game_loop -->|"checks collisions"| node_shot
node_game_loop -->|"splits on hit"| node_asteroid
node_asteroid_field -->|"spawns"| node_asteroid
node_player_ship -->|"fires"| node_shot
node_player_ship -->|"extends"| node_circle_shape
node_asteroid -->|"extends"| node_circle_shape
node_shot -->|"extends"| node_circle_shape
node_game_loop -->|"reads settings"| node_constants
node_asteroid_field -->|"reads settings"| node_constants
node_player_ship -->|"reads settings"| node_constants
node_asteroid -->|"reads settings"| node_constants
node_shot -->|"reads settings"| node_constants

click node_game_loop "https://github.com/griffinm64/asteroids/blob/main/main.py"
click node_asteroid_field "https://github.com/griffinm64/asteroids/blob/main/asteroidfield.py"
click node_player_ship "https://github.com/griffinm64/asteroids/blob/main/player.py"
click node_asteroid "https://github.com/griffinm64/asteroids/blob/main/asteroid.py"
click node_shot "https://github.com/griffinm64/asteroids/blob/main/shot.py"
click node_circle_shape "https://github.com/griffinm64/asteroids/blob/main/circleshape.py"
click node_constants "https://github.com/griffinm64/asteroids/blob/main/constants.py"

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_game_loop toneBlue
class node_asteroid_field,node_player_ship,node_asteroid,node_shot toneAmber
class node_circle_shape,node_constants toneMint
class node_player_user toneIndigo
```

## Components

### Game runtime

- [Game loop](https://github.com/griffinm64/asteroids/blob/main/main.py): `main.py`

### Gameplay entities

- [Asteroid field](https://github.com/griffinm64/asteroids/blob/main/asteroidfield.py): `asteroidfield.py`
- [Player ship](https://github.com/griffinm64/asteroids/blob/main/player.py): `player.py`
- [Asteroid](https://github.com/griffinm64/asteroids/blob/main/asteroid.py): `asteroid.py`
- [Shot](https://github.com/griffinm64/asteroids/blob/main/shot.py): `shot.py`

### Shared foundation

- [Circle shape](https://github.com/griffinm64/asteroids/blob/main/circleshape.py): `circleshape.py`
- [Game constants](https://github.com/griffinm64/asteroids/blob/main/constants.py): `constants.py`

### Other components

- **Player**

## Connections

- Player → Game loop: quits game (evidence: `main.py`)
- Player → Player ship: controls (evidence: `player.py`)
- Game loop → Asteroid field: creates (evidence: `main.py`)
- Game loop → Player ship: creates (evidence: `main.py`)
- Game loop → Asteroid: updates and draws (evidence: `main.py`)
- Game loop → Player ship: updates and draws (evidence: `main.py`)
- Game loop → Shot: updates and draws (evidence: `main.py`)
- Game loop → Asteroid: checks collisions (evidence: `main.py`)
- Game loop → Player ship: checks collisions (evidence: `main.py`)
- Game loop → Shot: checks collisions (evidence: `main.py`)
- Game loop → Asteroid: splits on hit (evidence: `main.py`)
- Asteroid field → Asteroid: spawns (evidence: `asteroidfield.py`)
- Player ship → Shot: fires (evidence: `player.py`)
- Player ship → Circle shape: extends (evidence: `player.py`)
- Asteroid → Circle shape: extends (evidence: `asteroid.py`)
- Shot → Circle shape: extends (evidence: `shot.py`)
- Game loop → Game constants: reads settings (evidence: `main.py`)
- Asteroid field → Game constants: reads settings (evidence: `asteroidfield.py`)
- Player ship → Game constants: reads settings (evidence: `player.py`)
- Asteroid → Game constants: reads settings (evidence: `asteroid.py`)
- Shot → Game constants: reads settings (evidence: `shot.py`)
