A Python recreation of the classic arcade game Asteroids, built with pygame. Pilot a ship through an endless field of drifting space rocks, blast them into smaller pieces, and try to survive as long as you can.
This was my first project working with Python classes, inheritance, and object composition — the codebase is organized around a shared CircleShape base class that the player, asteroids, and shots all inherit from, which was a great way to learn how OOP patterns come together in a real (if small) game.
- Asteroids spawn continuously from the edges of the screen and drift across it.
- Shoot an asteroid and it splits into two smaller ones — keep shooting and they'll keep splitting until they're too small to split further, at which point they're destroyed for good.
- Colliding with an asteroid ends the game.
- There's no score or win condition yet — it's about how long you can dodge and clear the field.
| Key | Action |
|---|---|
W |
Move forward |
S |
Move backward |
A |
Rotate left |
D |
Rotate right |
Space |
Shoot |
- Python 3.x
- uv for dependency management and running the game
- pygame (installed automatically by
uvvia the project's dependencies)
uv run main.py| File | Purpose |
|---|---|
main.py |
Game loop: initializes pygame, sets up sprite groups, handles collisions, and renders each frame |
circleshape.py |
CircleShape — the base class for all circular game objects (position, velocity, radius, collision detection) |
player.py |
Player — handles movement, rotation, and shooting |
asteroid.py |
Asteroid — handles drawing, movement, and splitting into smaller asteroids when hit |
asteroidfield.py |
AsteroidField — spawns new asteroids at random edges of the screen on a timer |
shot.py |
Shot — the projectiles fired by the player |
constants.py |
Central place for game tuning values (screen size, speeds, radii, cooldowns, etc.) |
logger.py |
Lightweight JSONL logging of game state and events (useful for debugging or replaying what happened) |
Since this was a learning project, a few things are intentionally simple or unfinished:
- No lives, scoring, or game-over screen — the game just exits when you're hit.
- No sound.
- Asteroid shapes are plain circles rather than jagged rock sprites.
Feel free to extend it — natural next steps would be adding a score counter, lives/respawn system, or a proper game-over screen instead of a hard exit.