A classic arcade shooter rebuilt from scratch in C++17 with Raylib. The player defends the bottom of the screen against a descending alien formation, using destructible bunkers for cover while a bonus ship occasionally crosses the top.
This is a full game loop — not a prototype — with entity-based design, collision handling, audio, and state management.
| Area | Implementation |
|---|---|
| Player ship | Horizontal movement with screen clamping; rate-limited laser fire |
| Alien formation | 11×5 grid (3 types: small / medium / large); synchronized side-to-side movement with edge detection, step-down, and direction reversal |
| Enemy AI | Random alien selected each interval to fire downward |
| Bunkers | Four destructible shields built from a 23×13 block grid; lasers chip away individual blocks |
| Mystery ship | Spawns on a random timer, crosses the screen at variable speed, awards random bonus points on hit |
| Collisions | Rectangle-based detection between lasers, aliens, ship, bunkers, and mystery ship |
| Game flow | Start menu, active play, win (all aliens destroyed), game over (lives exhausted); Enter to start or restart |
| HUD | Six-digit score (top-left), lives counter (top-right) |
| Audio | Background music loop, laser and explosion sound effects |
Controls: ← → move · Space fire · Enter start / restart
space-invaders/
├── Makefile # g++ build, -std=c++17, links raylib
├── assets/
│ ├── img/ # Sprites (ship, aliens, mystery ship)
│ └── sound/ # Music, laser, explosion
└── src/
├── main.cpp # Window setup, constants, game bootstrap
├── game.hpp / .cpp # Core loop, states, collisions, scoring
├── spaceship.hpp / .cpp
├── alien.hpp / .cpp
├── laser.hpp / .cpp
├── block.hpp / .cpp
├── obstacle.hpp / .cpp
└── mysteryship.hpp / .cpp
Gameowns all runtime state: entity lists (std::list), input map (std::unordered_map), timers, score, lives, and audio handles. The main loop delegates torun()→ input → update → draw → collision.- Entities are small, focused classes (
Spaceship,Alien,Laser,Block,Obstacle,MysteryShip) withdraw(),update(), andgetBounds()where needed. - Shared assets (laser dimensions/colors, block scale/color, alien textures) load once via
loadLaser(),loadBlock(), andloadAlien()before entities are constructed. main.cppholds tunable constants (screen size, formation layout, fire rates, speeds) and passes them into theGameconstructor — configuration separated from logic.
Requirements: g++, Raylib development libraries
make
./mainRun from the project root so asset paths resolve correctly.
make clean # remove dist/ and binary- Language: C++17 (
-Wall -Wextra -pedantic) - Graphics / input / audio: Raylib
- Build: Make, object files in
dist/
Built incrementally in focused commits:
- Window, audio, and spaceship rendering
- Movement and laser system
- Destructible bunkers (block grid)
- Alien formation — spawn, animate, fire
- Collision detection across all entity types
- Score, lives, mystery ship
- Game states (menu, win, game over) and HUD text
