A classic Space Invaders arcade game built with Python and Pygame.
Defend the Earth from waves of alien invaders! Control your spaceship, dodge enemy fire, and destroy all aliens before they overwhelm you. Features sound effects, explosions, a countdown timer, and pause/restart functionality.
- Python 3.x
- Pygame
Install dependencies with:
pip install pygamespace-invaders/
├── spaceinvaders.py # Main game loop and entry point
├── spaceship.py # Player spaceship class
├── alien.py # Alien enemy class
├── alienbullets.py # Alien bullet class
└── assets/
├── bg.jpg # Background image
├── explosion.wav # Explosion sound effect
├── explosion2.wav # Secondary explosion sound effect
└── laser.wav # Laser fire sound effect
python spaceinvaders.py| Key | Action |
|---|---|
← / → |
Move spaceship |
Space |
Fire laser |
P |
Pause game |
U |
Unpause game |
R |
Restart game |
End |
Quit game |
- A 3-second countdown plays before each round begins.
- Eliminate all 25 aliens (5 rows × 5 columns) to win.
- Aliens fire back randomly — up to 5 alien bullets can be active at once, with a 1-second cooldown between shots.
- You start with 3 lives. Lose them all and it's game over.
- The game ends with a YOU WIN! or GAME OVER! message on screen.
| Variable | Default | Description |
|---|---|---|
rows |
5 | Number of alien rows |
columns |
5 | Number of aliens per row |
alien_cooldown |
1000 ms | Delay between alien shots |
health |
3 | Player starting lives |
fps |
60 | Frames per second |