A classic arcade-style Asteroids game built with Python and Pygame.
Navigate your spaceship, avoid asteroids, and shoot them down in this timeless space shooter. The game features smooth controls, collision detection, and increasing difficulty as more asteroids spawn.
- Player-controlled spaceship with rotation and thrust
- Asteroid spawning and movement
- Shooting mechanics with cooldown
- Collision detection for player-asteroid and shot-asteroid interactions
- Game over on player collision
- Logging of game events and state (for debugging)
- Python 3.8+
- Pygame
- Clone the repository:
git clone <repository-url> cd Asteroids
- Install dependencies
pip install pygame
- (Optional) Set up a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install pygame
Run the game with:
python [main.py]A/D: Rotate left/right W/S: Move forward/backward Space: Shoot Close window to quit
The player starts in the center of the screen. Asteroids spawn randomly and move in straight lines. Shots destroy asteroids on contact. If the player collides with an asteroid, the game ends. Shots disappear when they leave the screen.
main.py: Main game loop and initialization player.py: Player spaceship class asteroid.py: Asteroid class shot.py: Shot/projectile class circleshape.py: Base class for circular game objects asteroidfield.py: Manages asteroid spawning constants.py: Game constants (sizes, speeds, etc.) logger.py: Logging utilities for game state and events
Adjust constants in constants.py to change speeds, sizes, or spawn rates. Modify asteroidfield.py for different spawning patterns.
This project is for educational purposes. Feel free to modify and distribute.
If the game doesn't start, ensure Pygame is installed and your Python version is compatible. Check the console for any error messages. Game logs are saved to game_state.jsonl and game_events.jsonl for debugging.