A small Asteroids clone built with Python and Pygame.
- Player ship that rotates and moves
- Asteroids spawn and move across the screen
- Player can shoot bullets
- Collision detection between player and asteroids
- Sprite groups for efficient updates and drawing
- Shield power-up: pick up a shield to become invulnerable for a short time
- HUD timer: remaining shield time is shown under the score while active
- A / D: Rotate ship left/right
- W / S: Move ship forward/backward
- Spacebar: Shoot bullets
- Esc / Close Window: Quit game
- Python 3.12 (project pyproject.toml targets >=3.12)
- Pygame (see pinned version in pyproject.toml)
- (Optional) Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate - Install dependencies (pyproject pins pygame):
pip install -r <(python - <<'PY'
import tomllib, sys pyproject = tomllib.loads(open('pyproject.toml','rb').read()) deps = pyproject.get('project',{}).get('dependencies', []) print('\n'.join(d for d in deps)) PY )
Or simply:
```bash
pip install pygame==2.6.1
- Make sure you have a background image named
asteroids_background.jpgin the project folder. - Run the game:
python main.py
- Shield: spawns periodically (see
POWERUP_SPAWN_RATEinconstants.py). - Picking up a shield sets a timer (see
SHIELD_DURATION) and grants temporary invulnerability; the remaining time is displayed in the HUD.
You can tweak spawn rates and durations in constants.py:
SHIELD_DURATION— how long the shield lasts (seconds).POWERUP_SPAWN_RATE— approximate seconds between power-up spawns.SHIELD_RADIUS— visual radius for the power-up pickup.
main.py— Game loop and HUD renderingplayer.py— Player ship, shooting, and shield handlingasteroid.py— Asteroid logic and splittingasteroidfield.py— Spawning of asteroids and power-upspowerup.py— Power-up sprite (shield)shot.py— Bullet logiccircleshape.py— Base class for circular spritesconstants.py— Game constants (sizes, speeds, power-up values)asteroids_background.jpg— Background image for the game
- Player acceleration
- Screen wrap-around for all objects
- Different weapon types
- Lumpy asteroids (polygonal shapes) - done
- Triangular ship hitbox
- Speed power-up
- Bombs
- Sound effects
Enjoy blasting asteroids!