A classic Space Invaders arcade game built with Python and Pygame, featuring dynamic invader loading and modern game mechanics.
- Classic Space Invaders Gameplay - Defend Earth from alien invaders!
- Dynamic Invader Loading - Automatically loads all invader images from the images folder
- Random Invader Types - Each invader spawns with a random appearance for visual variety
- Multiple Bullets - Fire rapidly without waiting for bullets to hit
- Smooth Controls - Responsive player movement and shooting
- Score System - Earn points for each invader destroyed
- Game Over & Restart - Press R to restart when the game ends
- Sound Effects - Background music, laser sounds, and explosion effects
- Error Handling - Game runs even with missing assets using placeholder graphics
- Left Arrow / A - Move player left
- Right Arrow / D - Move player right
- Spacebar - Fire bullets
- R - Restart game (when game over)
- Python 3.6 or higher
- Pygame library
- Install Python from python.org
- Install Pygame:
pip install pygame
- Download or clone this game
- Run the game:
python main.py
SpaceInvaders/
├── main.py # Main game file
├── README.md # This file
├── images/ # Image assets folder
│ ├── background.jpg # Game background
│ ├── arcade-player.png # Player spaceship
│ ├── bullet.png # Bullet sprite
│ ├── spaceship.png # Game icon
│ ├── invader1.png # Invader sprites (any name)
│ ├── pink.png # Invader sprites (any name)
│ ├── white.png # Invader sprites (any name)
│ ├── yellow.png # Invader sprites (any name)
│ └── ... # Add more invader images here!
└── sound/ # Audio assets folder
├── background.wav # Background music (loops)
├── laser.wav # Shooting sound effect
└── explosion.wav # Explosion sound effect
- Simply drop any image file into the
images/folder - The game will automatically detect and use it as a random invader type
- Supported formats: PNG, JPG, JPEG, GIF, BMP
- Recommended size: 32x32 pixels (will auto-scale)
Note: Don't rename these core files, or they'll be treated as invaders:
background.jpg/png- Game backgroundarcade-player.png- Player shipbullet.png- Bullet spritespaceship.png- Game icon
Replace any sound file in the sound/ folder:
background.wav- Background music (should loop well)laser.wav- Bullet firing soundexplosion.wav- Invader destruction sound
You can modify these constants at the top of main.py:
SCREEN_WIDTH/SCREEN_HEIGHT- Game window sizePLAYER_SPEED- How fast the player movesBULLET_SPEED- How fast bullets travelINVADER_SPEED- How fast invaders move horizontallyNUM_OF_ENEMIES- Number of invaders on screenFPS- Game frame rate
- Objective: Destroy all invaders before they reach the bottom of the screen
- Scoring: Earn 10 points for each invader destroyed
- Game Over: Occurs when any invader reaches too close to the bottom
- Invader Behavior:
- Move horizontally across the screen
- Drop down and reverse direction when hitting screen edges
- Respawn with random appearance when destroyed
- Speed increases as game progresses
- Object-Oriented Design - Clean, modular class-based architecture
- Error Handling - Graceful fallbacks for missing assets
- Performance Optimized - Efficient collision detection and rendering
- Extensible - Easy to add new features and game mechanics
SpaceInvaders- Main game classload_assets()- Dynamic asset loading with error handlingload_invader_images()- Automatic invader image detectionupdate()- Game logic updatesdraw()- Rendering systemcheck_collisions()- Collision detection system
Game won't start:
- Make sure Python and Pygame are installed
- Check that
main.pyis in the same folder asimages/andsound/
No sound:
- Verify sound files are in the
sound/folder - Check audio file formats (WAV recommended)
- Game will run silently if sound files are missing
Graphics issues:
- Ensure image files are in the
images/folder - Game will use colored rectangles as placeholders if images are missing
- Supported formats: PNG, JPG, JPEG, GIF, BMP
Performance issues:
- Reduce
NUM_OF_ENEMIESconstant - Lower the
FPSconstant - Use smaller image files
Feel free to fork this project and add your own features! Some ideas:
- Power-ups (multi-shot, shields, speed boost)
- Different enemy types with unique behaviors
- Multiple levels with increasing difficulty
- Particle effects and animations
- High score persistence
- Menu system
- Original Space Invaders concept by Tomohiro Nishikado
- Built with Python and Pygame
- Sound effects and music: [Add your sources here]
- Graphics: [Add your sources here]
This project is open source. Feel free to use, modify, and distribute as needed.
Enjoy defending Earth from the alien invasion! 🚀👾