This project has been created as part of the 42 curriculum by amikhail and aortigos.
cub3d
Description
cub3D is a graphical programming project inspired by the classic game Wolfenstein 3D, one of the first First-Person Shooters ever created.
The goal of this project is to build a real-time 3D representation of a maze from a 2D map, using the ray-casting technique, written in C and rendered with MLX42.
Each vertical stripe of the screen is rendered by casting a ray from the player’s
point of view, detecting wall intersections, computing distances, and projecting
textured walls with correct perspective.
Floor and ceiling colors are also rendered to complete the scene.
This project focuses on:
- Low-level graphics programming
- Mathematical projection
- Parsing and validation
- Real-time rendering performance
Features
- Ray-casting rendering engine
- Directional wall textures (North, South, East, West)
- Floor and ceiling RGB colors
- Player movement and camera rotation
- Collision detection
- Strict
.cubfile parsing and validation - Clean error handling and memory management
- MLX42 rendering loop
Instructions
Requirements
- Linux or macOS
- CMake
- MLX42 / MLX
- C compiler (
gccorclang)
Compilation
Clone the repository and run:
make
This will:
- Build MLX42
- Compile
libft,ft_printf, andget_next_line - Generate the
cub3dexecutable
Execution
./cub3D assets/maps/map.cub
The program requires exactly one argument: a valid .cub map file.
Controls
| Key | Action |
|---|---|
W |
Move forward |
S |
Move backward |
A |
Strafe left |
D |
Strafe right |
← |
Rotate camera left |
→ |
Rotate camera right |
ESC |
Exit the program |
Map configuration (.cub)
A .cub file contains:
- Wall textures (NO, SO, WE, EA)
- Floor and ceiling colors (RGB format)
- Map layout, composed of:
- 1 for walls
- 0 for empty space
- N, S, E or W for the player start position
- Spaces are allowed and handled correctly
The map is strictly validated:
- Exactly one player position
- Map must be fully closed by walls
- Only valid characters
- No empty lines inside the map
- RGB values between 0 and 255
Example:
111111
100001
1000N1
111111
Resources
AI Usage
AI tools were used only as assistance, specifically for:
- Understanding ray-casting concepts
- Improving documentation clarity
- Reviewing logic and edge cases
All generated content was reviewed, understood, and manually implemented. No AI-generated code was copied blindly into the project.