Map File Overview
Cub3D map files use the.cub extension and contain two main sections:
- Configuration section: Texture paths and colors
- Map grid section: The actual level layout
Map files are plain text files that you can create with any text editor.
Map File Format
A Cub3D map file follows this structure:Configuration Section
Texture Paths
Four texture identifiers must be defined, each on its own line:Texture paths can have flexible spacing, but must be on separate lines.
Texture Identifier Rules
Fromasignatributes.c:24-35, texture assignment validation:
Texture File Validation
Fromasignatributes.c:49-54:
Supported Texture Format
Cub3D uses the XPM (X PixMap) image format for textures.XPM Format
XPM is a plain text image format native to X11 systems. Texture files must have the
.xpm extension.Color Configuration
Floor and ceiling colors are specified in RGB format:- F: Floor color
- C: Ceiling color
- RGB values: Each value must be between 0 and 255
Color Validation
Fromutils4.c:15-27, RGB range validation:
Color Format Validation
Fromutils4.c:29-54, the parser validates:
- Exactly 3 values: RGB format requires three comma-separated numbers
- All digits: Each value must be composed only of digit characters
- Valid range: Each value must be 0-255
Color Parsing
Fromutils7.c:15-29, colors are parsed into hex format:
0xRRGGBB
Configuration Order
Fromparselineutils.c:55-62, all configuration attributes must be present:
All six configuration attributes (NO, SO, WE, EA, F, C) must be defined before the map grid begins.
Map Grid Section
Valid Map Characters
Fromutils4.c:56-62, the allowed characters are:
1
WallSolid wall block
0
Empty SpaceWalkable floor
N
Player NorthStarting position facing north
S
Player SouthStarting position facing south
E
Player EastStarting position facing east
W
Player WestStarting position facing west
(space)
VoidEmpty space outside map
(tab)
WhitespaceTreated as void
Player Position
Fromutils3.c:30-53, player validation:
Map Closure Validation
The most critical rule: the map must be completely enclosed by walls. Fromutils4.c:64-84, flood fill validation:
Map Closure Rules
Example Maps
Let’s examine real example maps from the repository:Simple Map: COME.cub
Frommaps/COME.cub:
Analysis
Analysis
Configuration:
- North texture:
./pizza.xpm - South texture:
./doom2.xpm - West texture:
./doom3.xpm - East texture:
./eagle.xpm - Floor: Orange (RGB: 220, 100, 0)
- Ceiling: Red-orange (RGB: 225, 30, 0)
- Note: Flexible spacing is allowed before texture identifiers
- Minimal 3x3 map
- Player starts in center facing North
- Completely enclosed by walls
- Perfect for testing basic functionality
Medium Map: DOOMGUY.cub
Frommaps/DOOMGUY.cub:
Analysis
Analysis
Configuration:
- DOOM-themed textures
- Same floor/ceiling colors as COME.cub
- Irregular shape with indented sections
- Leading spaces create interesting geometry
- Player in middle area facing North
- Multiple corridor widths
- Demonstrates complex but valid map structure
- Notice how walkable areas never touch void spaces
Complex Map: Dommed.cub
Frommaps/Dommed.cub:
Analysis
Analysis
Configuration:
- Generic texture names (tex1-4)
- Standard floor/ceiling colors
- Highly irregular shape
- Multiple room-like areas
- Internal spaces in walls (see row 12: spaces between numbers)
- Player at right edge facing North
- Demonstrates that spaces inside walls are valid
- Trailing spaces/empty areas are allowed
- Shows complex but properly enclosed structure
Step-by-Step Map Creation
Let’s create a simple custom map from scratch:Add floor and ceiling colors
Pick RGB values for floor and ceiling:This creates a gray floor and sky blue ceiling.
Complete Map Template
Here’s a complete template you can use as a starting point:Common Errors and Solutions
Error: Map is not closed
Error: Map is not closed
Cause: Walkable space touches a void space or map edge.Solution:
- Ensure all edges of your map are walls (
1) - Check for spaces adjacent to
0or player characters - Verify irregular shapes have walls on all exposed edges
Error: Should have only one player
Error: Should have only one player
Cause: Zero or multiple player characters (N/S/E/W).Solution:
- Ensure exactly one N, S, E, or W character exists
- Check for accidentally duplicated player positions
- Verify you haven’t forgotten to place a player
Error: The image of one of the directions was not found
Error: The image of one of the directions was not found
Cause: Texture file path is incorrect or file doesn’t exist.Solution:
- Verify all texture files exist:
- Check paths are correct (relative or absolute)
- Ensure file permissions allow reading
- Use paths relative to where you run cub3d
Error: Some introduced number is not valid for rgb standard
Error: Some introduced number is not valid for rgb standard
Cause: RGB values outside 0-255 range.Solution:
- Check all RGB values are between 0 and 255
- Verify no negative values
- Ensure no decimal points (must be integers)
Error: There aren't three arguments after splitting
Error: There aren't three arguments after splitting
Cause: Floor or ceiling color doesn’t have exactly 3 RGB values.Solution:
- Ensure colors have format: R,G,B
- Use exactly two commas
- No spaces between values
Error: Atribute is found more than once
Error: Atribute is found more than once
Cause: Duplicate configuration identifiers.Solution:
- Remove duplicate NO, SO, WE, EA, F, or C lines
- Keep only one of each identifier
Advanced Map Techniques
Creating Rooms and Corridors
Irregular Shapes
Large Open Areas
Map Size Considerations
Fromcub3.h:89, the map buffer size:
Maps can be up to 500x500 cells. However, practical sizes are much smaller for performance and playability.
Recommended Sizes
- Small maps: 10x10 to 20x20 cells
- Medium maps: 20x20 to 40x40 cells
- Large maps: 40x40 to 100x100 cells
SIZE in cub3.h:33).
Testing Your Map
Next Steps
You’re now ready to create complex, interesting maps for Cub3D!Building
Review the build process
Running
Test your maps
Controls
Navigate your creations
Architecture
Understand the rendering engine