Cub3D

A 3D raycaster engine in C inspired by the classic Wolfenstein 3D, built from scratch using the MiniLibX graphic library.

2021-11-01

graphicsOpen GitHub
Cub3D

Cub3D

A first-person 3D maze game in C, inspired by Wolfenstein 3D. The "3D" is an illusion created by a raycasting engine running on top of a 2D map, rendered through the MiniLibX graphics library.

Features

  • Real-time rendering with the DDA (Digital Differential Analysis) raycasting algorithm
  • Separate XPM textures for each wall direction (N, S, E, W)
  • Configurable floor and ceiling colors set in the scene file
  • Smooth player movement and camera rotation
  • Mini-map overlay and sprite rendering in the bonus version
  • Map validation before anything renders, invalid maps exit cleanly

How the raycasting works

For every vertical column of pixels, a ray is cast from the player at a slightly different angle. It steps through the 2D grid until it hits a wall. The distance to that wall determines how tall the wall slice appears on screen. The right texture column gets sampled based on exactly where the ray hit.

Player → Ray → Wall hit → Distance → Slice height → Texture column

That's the whole trick. A 2D grid gives you the illusion of depth.

Scene file format (.cub)

NO ./textures/north.xpm
SO ./textures/south.xpm
WE ./textures/west.xpm
EA ./textures/east.xpm

F 220,100,0
C 225,30,0

1111111111
1000000001
100N000001
1111111111

1 is a wall, 0 is open space, and N/S/E/W sets the player's start position and direction.

Controls

KeyAction
W / SMove forward / backward
A / DStrafe left / right
Arrow keysRotate camera
ESCQuit

SCREENSHOTS // 01 FRAMES

Screenshot 1
01 / 01