A small Space Invaders clone written in Zig using raylib via raylib-zig.
- Zig
0.16.0or newer
Dependencies are fetched automatically by the Zig package manager on first build.
zig build runTo just build the executable (output lands in zig-out/bin/):
zig buildRun the tests:
zig build test| Key | Action |
|---|---|
← / A |
Move left |
→ / D |
Move right |
Space |
Shoot |
Enter |
Start / restart the game |
Esc |
Quit |
Invaders march sideways, drop down a row when they reach a screen edge, and shoot back at random. Each invader you destroy is worth 10 points. Four shields sit above the player and absorb 10 hits each — from invader bullets and your own — fading out as they take damage.
You lose if an invader bullet hits you or the invaders reach your ship. You win by clearing the whole formation.
src/
├── main.zig # window setup, game loop, state machine
├── root.zig # library root, re-exports the types below
├── config/game-config.zig # GameConfig: all tunable values
├── primitives/rectangle.zig # Rectangle + AABB intersection test
├── entities/
│ ├── player.zig
│ ├── invader.zig
│ └── shield.zig
└── projectiles/
├── player_bullet.zig
└── invader_bullet.zig
Everything tunable — screen size, speeds, spacing, fire rates, grid dimensions — lives in the GameConfig literal at the top of main() in src/main.zig. The invader grid defaults to a small 1 × 2 formation; raise invader_rows and invader_columns for a real fight.