Skip to content

Latest commit

 

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Space Invaders

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.

Screenshot


What I Built

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


Project Structure

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

Architecture

  • Game owns all runtime state: entity lists (std::list), input map (std::unordered_map), timers, score, lives, and audio handles. The main loop delegates to run() → input → update → draw → collision.
  • Entities are small, focused classes (Spaceship, Alien, Laser, Block, Obstacle, MysteryShip) with draw(), update(), and getBounds() where needed.
  • Shared assets (laser dimensions/colors, block scale/color, alien textures) load once via loadLaser(), loadBlock(), and loadAlien() before entities are constructed.
  • main.cpp holds tunable constants (screen size, formation layout, fire rates, speeds) and passes them into the Game constructor — configuration separated from logic.

Build & Run

Requirements: g++, Raylib development libraries

make
./main

Run from the project root so asset paths resolve correctly.

make clean   # remove dist/ and binary

Tech Stack

  • Language: C++17 (-Wall -Wextra -pedantic)
  • Graphics / input / audio: Raylib
  • Build: Make, object files in dist/

Development Timeline

Built incrementally in focused commits:

  1. Window, audio, and spaceship rendering
  2. Movement and laser system
  3. Destructible bunkers (block grid)
  4. Alien formation — spawn, animate, fire
  5. Collision detection across all entity types
  6. Score, lives, mystery ship
  7. Game states (menu, win, game over) and HUD text

About

Classic Space Invaders game written in c++ using Raylib.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages