Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Space Invaders Game

A classic Space Invaders arcade game built with Python and Pygame, featuring dynamic invader loading and modern game mechanics.

Features

  • 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

Controls

  • Left Arrow / A - Move player left
  • Right Arrow / D - Move player right
  • Spacebar - Fire bullets
  • R - Restart game (when game over)

Installation

Requirements

  • Python 3.6 or higher
  • Pygame library

Setup

  1. Install Python from python.org
  2. Install Pygame:
    pip install pygame
  3. Download or clone this game
  4. Run the game:
    python main.py

File Structure

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

Adding Custom Content

Adding New Invader Types

  1. Simply drop any image file into the images/ folder
  2. The game will automatically detect and use it as a random invader type
  3. Supported formats: PNG, JPG, JPEG, GIF, BMP
  4. 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 background
  • arcade-player.png - Player ship
  • bullet.png - Bullet sprite
  • spaceship.png - Game icon

Customizing Sounds

Replace any sound file in the sound/ folder:

  • background.wav - Background music (should loop well)
  • laser.wav - Bullet firing sound
  • explosion.wav - Invader destruction sound

Game Settings

You can modify these constants at the top of main.py:

  • SCREEN_WIDTH / SCREEN_HEIGHT - Game window size
  • PLAYER_SPEED - How fast the player moves
  • BULLET_SPEED - How fast bullets travel
  • INVADER_SPEED - How fast invaders move horizontally
  • NUM_OF_ENEMIES - Number of invaders on screen
  • FPS - Game frame rate

Gameplay

  • 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

Technical Details

Code Structure

  • 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

Key Classes & Methods

  • SpaceInvaders - Main game class
  • load_assets() - Dynamic asset loading with error handling
  • load_invader_images() - Automatic invader image detection
  • update() - Game logic updates
  • draw() - Rendering system
  • check_collisions() - Collision detection system

Troubleshooting

Common Issues

Game won't start:

  • Make sure Python and Pygame are installed
  • Check that main.py is in the same folder as images/ and sound/

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_ENEMIES constant
  • Lower the FPS constant
  • Use smaller image files

Contributing

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

Credits

  • 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]

License

This project is open source. Feel free to use, modify, and distribute as needed.


Enjoy defending Earth from the alien invasion! 🚀👾

About

The README file for the Space Invaders game covers everything you need to understand, install, play, and modify the game.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages