Map File Format
Cub3D maps use the.cub format, which combines configuration directives with ASCII grid layouts. Maps are located in the maps/ directory.
Basic Structure
Minimal Example
Here’s a simple working map:maps/smol.cub
Required elements:
- NO, SO, WE, EA texture paths
- F (floor) and C (ceiling) RGB colors
- Map grid with walls (1) and at least one player spawn (N/S/E/W)
Configuration Directives
Wall Textures
Define default textures for wall faces:Environment Colors
Audio Configuration
Background Sprite
Add a background texture (for skyboxes or distant scenery):Mouse Control
Disable mouse look by default:Entity Identifiers
Entities are placed in the map grid using single characters. Each identifier can be configured with properties.Built-in Identifiers
- Map Elements
- Player Spawns
| Character | Type | Description |
|---|---|---|
0 | Air | Empty space (walkable) |
1 | Wall | Standard wall using default textures |
| Space | Air | Alternative to 0 |
| Tab | Air | Alternative to 0 |
Custom Wall Types
Define walls with specific textures:3 in the map grid to place this wall.
Door Configuration
Doors can open and close with animations:2 in the map grid to create a door.
Door direction (NORTH, SOUTH, EAST, WEST) determines the opening axis.
Billboard Entities
Create 3D sprites that always face the player:Elevator Configuration
Elevators transport players to different maps:Advanced Entity Properties
Entity Attributes
Health & Combat
Health & Combat
Transparency
Transparency
Interaction
Interaction
Collision
Collision
Map Grid Layout
The map grid defines the level geometry:Grid Rules
Closed Maps
Maps must be surrounded by walls (1) or will fail validation
Player Spawn
At least one player spawn (N/S/E/W) is required
Spacing
Use spaces or tabs for empty cells, maintains alignment
Custom Entities
Any configured identifier can be placed in the grid
Example Complex Map
This example uses:
- Multiple custom wall types (p, s, 3, 9)
- Doors (2, 6)
- Player spawn (N)
- Empty spaces for room layout
Player Configuration
Configure player starting inventory and stats:Item System
Defining Items
Items can be weapons or collectibles:Drop Configuration
Place items in the world:Character Entities
Create NPCs with AI:Constants and Defaults
These constants are defined inheaders/cub3d.h:cub3d.h:
Testing Your Map
Map Examples
Simple Test
maps/smol.cub - Minimal 6x5 map for testing
Subject Map
maps/subject.cub - Original 42 project requirements
Hub World
maps/hub.cub - Main menu/hub area
Wolfenstein
maps/e1m1.cub - Complete FPS level with enemies
Troubleshooting
Map validation fails
Map validation fails
Common issues:
- Map not enclosed by walls (1)
- Missing required directives (NO/SO/WE/EA/F/C)
- Invalid RGB color format (must be
R,G,B) - Missing player spawn point
Textures not loading
Textures not loading
Check:
- File paths are relative to project root
- BMP files are in correct format (24-bit uncompressed)
- File paths have no typos
- Files exist at specified locations
Doors not working
Doors not working
Ensure:
_TYPE DOORis set- Direction is specified (NORTH/SOUTH/EAST/WEST)
- Door sprite exists
- Identifier is placed in map grid correctly
Entities not appearing
Entities not appearing
Verify:
- Entity type is defined with
_TYPE - Required properties are set (e.g.,
_SPRITEfor billboards) - Identifier matches between definition and grid
- Entity is not off-screen or behind walls
Next Steps
Building
Learn how to compile and run your custom maps
Controls
Master the game controls for testing