Quick Start
This guide will help you compile and run Cub3D on your system in just a few steps.Prerequisites
Before you begin, ensure you have the following installed:Development Libraries
The build process will automatically compile SDL2 from source, but you may need some system dependencies.
Compilation
Build the Project
The Makefile handles all dependencies automatically, including SDL2 and miniaudio:The build process will:
The first build will take several minutes as it compiles SDL2 from source. Subsequent builds will be much faster.
- Extract and compile SDL2 from the included archive
- Extract miniaudio headers
- Compile all source files in
src/ - Link everything into the
cub3dexecutable
Running Cub3D
Default Map (Hub)
To run Cub3D with the default hub map:Specific Maps
You can launch any map directly by providing its path as an argument:Available Maps
Themaps/ directory contains several pre-built levels:
| Map File | Description |
|---|---|
hub.cub | Central hub with elevators to other maps |
42lisboa.cub | 3D recreation of 42 Lisboa campus |
e1m1.cub | Wolfenstein 3D Episode 1, Mission 1 |
e1m2.cub | Wolfenstein 3D Episode 1, Mission 2 |
smol.cub | Small test map for quick testing |
subject.cub | Original 42 project subject map |
Controls
Keyboard Controls
| Key | Action |
|---|---|
W / ↑ | Move forward |
S / ↓ | Move backward |
A | Strafe left |
D | Strafe right |
← | Turn left |
→ | Turn right |
Space | Use/Interact (open doors, use elevators) |
E | Use/Interact (alternative) |
M | Switch weapon (machine gun) |
P | Switch weapon (pistol) |
K | Switch weapon (knife) |
ESC | Exit game |
Mouse Controls
- Mouse Movement: Look around / Turn
- Left Click: Fire weapon (in Wolfenstein maps)
Controller Support
Cub3D supports Xbox, PlayStation, and compatible game controllers:- Left Stick: Move
- Right Stick: Look around
- A / X Button: Fire weapon
- B / Circle Button: Use/Interact
- Start: Pause
Map File Format
Cub3D uses.cub files to define maps. Here’s a minimal example:
maps/smol.cub
Map Format Breakdown
Map Format Breakdown
Texture Definitions
NO: North-facing wall textureSO: South-facing wall textureWE: West-facing wall textureEA: East-facing wall texture
F: Floor color (RGB)C: Ceiling color (RGB)
1: Wall0: Empty spaceN,S,E,W: Player spawn position and orientation
Build Targets
The Makefile provides several useful targets:Web Version (Advanced)
To build the WebAssembly version for browsers, you’ll need Emscripten installed:Install Emscripten
Follow the Emscripten installation guide:
Build with Emscripten
Use the Emscripten Makefile:This generates:
cub3d.html- The main HTML filecub3d.js- JavaScript glue codecub3d.wasm- WebAssembly binarycub3d.data- Packed assets (maps, textures, sounds)
The web build is optimized for performance with a reduced resolution (400x300) to run smoothly in browsers.
Troubleshooting
Compilation fails with SDL2 errors
Compilation fails with SDL2 errors
If SDL2 compilation fails, ensure you have the necessary development tools:Then run
make fclean followed by make to rebuild from scratch.Game window doesn't open
Game window doesn't open
Check that:
- You have a display server running (X11, Wayland, or macOS window server)
- You’re not trying to run it over SSH without X forwarding
- Your graphics drivers are up to date
No sound / audio issues
No sound / audio issues
The game uses miniaudio which should work out of the box. If you experience issues:
- Check your system audio settings
- Ensure your audio device is not muted
- Try running with different audio backends (miniaudio auto-detects)
Map file not found
Map file not found
Ensure you’re running the game from the project root directory where the
maps/ and assets/ directories are located:Next Steps
Explore Maps
Try out different maps to experience the variety of environments and gameplay
Create Custom Maps
Learn the .cub format and create your own levels
Technical Reference
Dive into the codebase architecture and systems
Play Online
Try the web version at omelhorsite.pt
Getting Help
If you encounter issues:- Check the GitHub repository for existing issues
- Review the source code comments for implementation details
- Examine the example maps in
maps/for reference