cub3D

A corridor rendered by the engine: a stone wall on the left, a blue one on the right, both receding towards a vanishing point at the centre of the frame

The demo needs JavaScript. Here is what it shows.

Commands

Move
Look around
Mini-map
Exit

Loading the module…

Theme

Choosing one restarts the program.

Map

Choosing one restarts the program.

How it works

What runs here

The cub3D program written in C, compiled to WebAssembly with Emscripten. Nothing was rewritten in JavaScript: the raycaster, the map parser and the game loop are the project’s own code, started with the same arguments as in a terminal.

What had to be adapted

cub3D draws through MiniLibX, which needs an X11 window. A browser has none, so a small replacement library with the same functions draws into this page instead, listens to the keyboard and reads the XPM textures.

What differs from the original

The browser drives the loop, capped at 60 frames per second. Maps and textures are packed into the binary, and each game is a new instance of the program. A theme is a generated .cub file: the same plan, other textures and other colors.