Overview
Cub3D uses.cub files to define game maps. These files contain texture paths, colors, entity definitions, and the map grid layout.
Map files must have the
.cub extension and be valid ASCII text files.File Structure
A.cub file consists of three main sections:
- Sprite and Resource Definitions - Textures, sounds, and assets
- Environment Configuration - Floor and ceiling colors
- Map Grid - The actual level layout using identifiers
Basic Example
Here’s a minimal map file:maps/smol.cub
1= walls with default textures (NO/SO/WE/EA)0= empty space (air)EandW= enemy/character spawn points
Default Map Configuration
headers/cub3d.h
- Air characters:
0and whitespace characters - Wall character:
1 - Player spawn:
N(north),S(south),E(east),W(west) - indicates starting direction
Environment Configuration
Floor and Ceiling Colors
- Format:
R,G,Bwhere each value is 0-255 - Must be defined before the map grid
Default Wall Textures
The four cardinal directions define default wall textures:1 character) based on which side is visible.
Custom Entity Definitions
Cub3D supports extensive customization through identifier-based entity definitions. Each entity type (wall, door, billboard, character, etc.) can have custom properties.Identifier Pattern
- identifier: Single character (a-z, A-Z)
- PROPERTY: Configuration key in UPPER_CASE
- value: The property value
Entity Types
Wall Entity
maps/42lisboa.cub
Wall Properties
Wall Properties
TYPE: Must be “WALL”NO,SO,EA,WE: Texture for each cardinal directionHARD: Whether the wall blocks movement (default: true)TARGETABLE: Can be targeted/interacted with (default: false)TRANSPARENT: See-through texture support (default: false)ULTRA_MEGA_TRANSPARENT: Always transparent (default: false)NO_TRANSPARENCY_FOR_BILL: Blocks billboards but not rays (default: false)
Door Entity
maps/42lisboa.cub
Door Properties
Door Properties
TYPE: Must be “DOOR”DOOR_SPRITE: Closed door textureDIRECTION: Which way the door faces (NORTH/SOUTH/EAST/WEST)ANIMATION_DELAY: Time for door animation in secondsOPEN_SOUND: Sound when door opensCLOSE_SOUND: Sound when door closesTARGETABLE: Can be interacted withAUTO_CLOSE_DELAY: Time before auto-closing (optional)
Billboard Entity
Billboards are sprite objects that always face the camera:maps/42lisboa.cub
Billboard Properties
Billboard Properties
TYPE: Must be “BILLBOARD”HARD: Whether it blocks movement (FALSE = can walk through)STILL_<N>_SPRITE: Directional sprites (1-8 for 8 directions)Y_CENTERED: Vertical centering (default: false)TARGETABLE: Can be interacted with
Multi-Directional Billboards
Billboards support 8-directional sprites for different viewing angles:maps/42lisboa.cub
The engine automatically selects the appropriate sprite based on the player’s viewing angle relative to the billboard.
Character Entity
Characters can be enemies, NPCs, or other players:maps/42lisboa.cub
Character Properties
Character Properties
STILL_<N>_SPRITE: Idle animation sprites for 8 directionsWALKING_<N>_SPRITE: Walking animation (can be colon-separated list)DEATH_SPRITE: Death animationHIT_SPRITE: Damage taken spriteUSING_<ITEM>_<N>_SPRITE: Using item animation (P=pistol, M=machinegun, K=knife)<SPRITE>_UPDATE_DELAY: Animation frame delay in seconds<SPRITE>_LOOP: Whether animation loopsDEATH_SOUND: Sound on death (can be colon-separated list for random)HIT_SOUND: Sound when taking damage
Elevator Entity
maps/42lisboa.cub
Sprite Animations
Sprites can be animated by providing multiple images:- Colon-separated paths: Multiple frames
- UPDATE_DELAY: Time between frames (seconds)
- LOOP: Whether to repeat animation
Background and Audio
maps/42lisboa.cub
Map Grid
The map grid is defined using the configured identifiers:maps/42lisboa.cub
- Each character represents a 1x1 grid cell
- Spaces and
0represent empty/walkable areas - Map boundaries should be enclosed by walls to prevent out-of-bounds issues
- Player spawn points use
N,S,E,Wto indicate starting direction
Map Grid Rules
-
Valid characters:
- Any identifier defined in the file
- Air characters:
0and whitespace - Player spawns:
N,S,E,W
-
Map boundaries:
- Must be enclosed by solid walls
- Prevents players from accessing out-of-bounds areas
-
Player spawns:
- At least one required (
N,S,E, orW) - Letter indicates starting facing direction
- At least one required (
Complete Example: 42 Lisboa Map
Here’s a section from the full 42 Lisboa campus map:maps/42lisboa.cub
Map Parsing
Maps are parsed in three stages:src/utils/map/map1.c
Map Data Structure
headers/cub3d.h
Best Practices
Map Design Tips
Map Design Tips
- Always enclose maps with walls - Prevents out-of-bounds access
- Use descriptive identifiers - Makes large maps easier to maintain
- Group related definitions - Keep wall definitions together, billboards together, etc.
- Test spawn points - Ensure players don’t spawn inside walls
- Use consistent naming - Prefix identifiers by type (w_wall1, d_door1, etc.)
- Optimize textures - Reuse textures where possible
- Consider performance - Very large maps may impact frame rates
Related Topics
- Entities - Detailed information about entity types
- Raycasting - How the map is rendered
- Game Engine - Map loading and management