A classic Asteroids-style arcade game built with Python and pygame.
This side-project focuses on clean structure, sprite-based architecture, and simple, readable game logic.
- Player-controlled ship with rotation, thrust, and shooting
- Procedurally spawning asteroids from screen edges
- Asteroids split into smaller pieces when shot
- Collision detection between:
- player ↔ asteroid
- shot ↔ asteroid
- Sprite group–based update and draw system
- Structured game-state and event logging (JSONL)
| Key | Action |
|---|---|
W |
Thrust forward |
S |
Thrust backward |
A |
Rotate left |
D |
Rotate right |
Space |
Shoot |
| Close window | Quit |
Asteroids/
├── main.py # Game entry point and main loop
├── player.py # Player movement, rotation, shooting
├── asteroid.py # Asteroid behavior and splitting logic
├── asteroidfield.py # Asteroid spawning system
├── shot.py # Projectile behavior
├── circleshape.py # Base class for circular game objects
├── constants.py # Game tuning values and configuration
├── logger.py # Game state + event logging (JSONL)
├── game_state.jsonl # Auto-generated state snapshots
├── game_events.jsonl # Auto-generated gameplay events
├── pyproject.toml # Project metadata and dependencies
├── uv.lock # Locked dependency versions
└── README.md
All game objects inherit from CircleShape, which provides:
- position and velocity (
pygame.Vector2) - radius-based collision detection
- a shared interface for
update()anddraw()
Sprites are organized into logical pygame.sprite.Groups:
updatabledrawableasteroidsshots
This allows clean separation of logic and rendering.
- Spawn randomly from screen edges
- Travel inward with randomized velocity and angle
- Split into two smaller asteroids when shot
- Disappear when below minimum size
- Rotates independently of movement
- Thrust-based movement (no instant velocity snapping)
- Shooting uses a cooldown timer
- Collision with an asteroid ends the game
The game automatically logs runtime data to JSON Lines files:
- Periodic snapshots (~1 per second)
- Sprite counts and sampled positions
- Velocities, rotations, radii
- Screen size and frame number
Logs discrete events such as:
asteroid_shotasteroid_splitplayer_hit
- Python 3.13+
- pygame 2.6.1
Dependencies are defined in pyproject.toml.
Using uv (recommended):
uv sync
uv run python main.pyOr using pip:
pip install pygame
python main.pyImplemented:
- Core movement and shooting
- Asteroid spawning and splitting
- Collision handling
- Logging system
Not yet implemented:
- Scoring
- Lives / restart flow
- Screen wrapping
- Sound effects
- UI / HUD
This project is primarily focused on:
- Writing readable, maintainable pygame code
- Understanding game loops and delta time
- Learning sprite-based architecture
- Building tooling (logging) alongside gameplay