A classic Asteroids game implementation in Python using Pygame. Navigate your spaceship through an asteroid field, destroy asteroids by shooting them, and survive as long as possible!
- Classic Gameplay: Faithful recreation of the classic Asteroids arcade game
- Smooth Controls: Responsive ship movement and rotation
- Asteroid Spawning: Procedurally spawned asteroid fields with varying sizes
- Collision Detection: Precise collision detection between player, shots, and asteroids
- Asteroid Splitting: Large asteroids split into smaller pieces when destroyed
- Shooting Mechanics: Cooldown-based shooting system with projectile physics
- Game Over: Collision detection ends the game when hitting asteroids
- Python 3.13 or higher
- Pygame 2.6.1
- Clone the repository:
git clone <repository-url>
cd asteroids- Install dependencies using uv (recommended) or pip:
# Using uv (recommended)
uv sync
# Or using pip
pip install pygame==2.6.1Run the game from the project root directory:
python main.pyOr using uv:
uv run python main.py- A: Rotate ship left
- D: Rotate ship right
- W: Move ship forward
- S: Move ship backward
- SPACE: Shoot projectiles
- ESC/Quit: Close the game window
- The ship rotates in place and moves in the direction it's facing
- Forward movement (W) propels the ship in the direction of the ship's nose
- Backward movement (S) moves the ship opposite to its facing direction
- Asteroids spawn continuously in the asteroid field
- Three different sizes of asteroids (determined by
ASTEROID_KINDSin constants.py) - Larger asteroids split into smaller asteroids when destroyed
- Smallest asteroids are destroyed completely when hit
- Projectiles have a cooldown period between shots (
PLAYER_SHOOT_COOLDOWN) - Asteroids are destroyed when hit by projectiles
- Game ends when the ship collides with an asteroid
asteroids/
├── main.py # Main game loop and initialization
├── player.py # Player ship class and controls
├── asteroid.py # Asteroid class and splitting mechanics
├── asteroidfield.py # Asteroid spawning system
├── shot.py # Projectile class
├── circleshape.py # Base class for circular game objects
├── constants.py # Game configuration constants
├── pyproject.toml # Project configuration
└── README.md # This file
Game settings can be modified in constants.py:
SCREEN_WIDTHandSCREEN_HEIGHT: Window dimensionsASTEROID_SPAWN_RATE: How often asteroids spawn (in seconds)PLAYER_SPEED: Ship movement speedPLAYER_SHOOT_SPEED: Projectile velocityPLAYER_SHOOT_COOLDOWN: Time between shots (in seconds)
- Pygame 2.6.1: For game graphics, input handling, and game loop management
This project uses modern Python packaging with uv for dependency management. The code follows object-oriented principles with sprite groups for efficient game object management.
This project is open source and available under the MIT License.
Contributions are welcome! Please feel free to submit issues and pull requests.
Classic Asteroids game concept by Atari. This implementation created as a learning project for Python game development with Pygame.