A high-performance, object-oriented 8-bit retro arcade game built with Python, Pygame-CE (Community Edition), and SDL, featuring a custom DSP procedural audio synthesis engine and stateful weapon systems.
- Toggle dynamically between two strategic firing patterns:
-
Single Fire Mode (Press
Q): Controlled shooting with a strict$400\text{ms}$ cooldown rate limit to prevent spamming. -
Rapid Fire Mode (Press
E): High-speed firing for a$5$ -second continuous window, followed by a stateful$5$ -second cooldown cycle where the player's weapon must cool down.
-
Single Fire Mode (Press
- Player ship starts with a 3-point shield (HP) segment HUD. Hitting obstacles reduces shield capacity, triggers screen shake, and activates a temporary flashing invincibility window for
$1.5$ -seconds to prevent instant deaths.
- Implements depth-layered starry backgrounds (foreground, midground, background) traveling at different speeds to create a rich 3D forward flight illusion.
- Generates 8-12 unique rock fragments with vector velocities, gravity drift, and opacity decay whenever a meteor is destroyed.
- Displays real-time shield levels, level progression, and a responsive Rapid Fire weapon heat meter representing heat accumulation and cooling cycles.
- Sounds and background chiptune music are generated programmatically via Python's native
waveandstructlibraries, bypassing external binary audio dependencies. - Features frequency-swept square waves for lasers, triangle-wave bass lines for background chiptunes, and exponentially decaying white noise for explosions.
- Meteors are spawned with custom trajectory vectors (
pygame.Vector2) and continuous rotational zoom (pygame.transform.rotozoom) to create a realistic tumbling effect in space.
- Utilizes Pygame's bitmask overlay detection (
pygame.sprite.collide_mask) to guarantee ultra-precise projectile collision overlays and reliable hitboxes under high sprite counts.
- Tracks and displays player high scores dynamically during runtime using local filesystem I/O caching to save the lifetime record.
Images/: Contains core graphical sprite sheets and icons (player.png,laser.png,meteor.png,star.png,game_icon.png).Sound/: Holds synthesized audio files (laser.wav,rapid_fire_sound.wav,explosion.wav,game_over.wav,game_music.wav,powerup.wav).explosion/explosion/: A sequential 21-frame list of sprite images (0.pngto20.png) utilized by the animation handler for explosion sprites.Rustic_Barn.ttf: Digital font asset for in-game HUD score displays.
SpaceInvader.py: The game entry point coordinating the Pygame canvas initialization, event loop tick clock, custom timer events, and game updates.player.py: Declares thePlayerclass managing user controls, screen boundary constraints, and weapon fire state machines.meteor.py: Defines theMeteorsprite behavior, speed vectors, decay timers, and continuous rotation.laser.py: Standard laser projectile class handling directional velocity.star.py: Handles background star generation for the scrolling parallax effect.powerup.py: Defines thePowerUpdrops including Shield restorers, Triple-shot boosts, and Rapid-fire cooldown resets.debris.py: Manages the physics-based explosion debris particle dispersion on meteor destruction.functions.py: Implements collision check states, high score filesystem load/save functions, and HUD draw coordinates.generate_sounds.py: The DSP math synthesis engine file used to generate all WAV sound effects.
setup.py&SpaceInvader.spec: Configuration templates for compiling the game into standalone desktop executables..gitignore: Excludes virtual environment files (Lib,Include), pycache, and compilation outputs from repository tracking.
Ensure you have Python 3.10 or higher installed on your system.
git clone https://github.com/AnkitKumarAman/SpaceInvader.git
cd SpaceInvaderpip install pygame-ceIf you want to re-generate the 8-bit sound library:
python generate_sounds.pypython SpaceInvader.py| Action | Control Key |
|---|---|
| Move Spaceship | Arrow Keys / A, D, W, S |
| Shoot Laser | Spacebar |
| Single Fire Mode | Q |
| Rapid Fire Mode | E |
| Start Game (Start Screen) | Spacebar |
| Replay Game (Game Over Screen) | R |
| Quit Game (Game Over / Play Screen) | Q |
- Pygame-CE: High-performance SDL wrapper library for Python game development.
- SDL (Simple DirectMedia Layer): Low-level access to audio, keyboard, mouse, and graphics hardware.
- DSP Reference: Standard digital signal processing formulas for wave-shape sound synthesis.
This project is licensed under the MIT License. See the LICENSE file for more details.