๐น๏ธ cub3D is a raycasting-based 3D maze game developed as part of the curriculum at 1337 School (42 Network). Inspired by the legendary Wolfenstein 3D โ the pioneer of the first-person shooter genre โ this project aims to replicate a basic 3D experience using only 2D data and raw math logic.
With the help of MiniLibX, a minimalistic graphical library, I built a dynamic 3D environment rendered from a 2D map using the raycasting technique. This simulation allows real-time movement, wall detection, and texture mapping โ all from scratch in pure C.
๐ฏ The main objective:
Take a simple .cub map file, parse it, and render a realistic 3D first-person view of a maze, complete with player movement and textured walls โ while respecting strict memory management and code standards.
๐ก Why this project is exciting: Itโs where math meets graphics. No OpenGL, no engines, no shortcuts. Just lines, pixels, and your brain.


- โ Apply C programming with graphics and math
- โ Learn how raycasting works to simulate 3D from 2D
- โ
Parse a custom map file format (
.cub
) - โ Render a 3D view with textures using MiniLibX
- โ Implement player movement and keyboard controls
- โ Ensure clean memory management and no leaks
Raycasting is a technique used in early 3D games to simulate a 3D perspective from a 2D map.
It works by casting imaginary rays from the player's point of view and calculating where each ray hits a wall. The result is a visual illusion of depth โ achieved with simple math and logic.
This method was famously used in games like Wolfenstein 3D, and it's the core rendering engine behind cub3D.
- For every vertical line (column) on the screen, a ray is cast into the 2D map.
- Using an algorithm like DDA (Digital Differential Analyzer), we detect where the ray intersects a wall.
- The distance to the wall is calculated.
- Based on that distance, we draw a vertical line on the screen โ the closer the wall, the taller the line.
- A texture is applied depending on which side of the wall was hit (North, South, East, or West).
- This process repeats for every column, forming a full frame โ creating the illusion of a 3D space.

Raycasting is fast, efficient, and doesnโt require full 3D geometry or heavy graphics engines.
Itโs perfect for simple games where performance and control matter โ and a fantastic way to understand the math behind 3D rendering.
With raycasting, you're not rendering a world โ you're calculating one.
Raycasting is used to turn a .cub
map file into a full 3D environment where you can move, rotate, and interact in real time โ with nothing but C, math, and the MiniLibX graphics library.
Feature | Description |
---|---|
๐งฑ Map Parsing | Parse .cub file and validate structure |
๐ฎ Player View | First-person camera with W/A/S/D + arrow keys |
๐ผ๏ธ Texture Support | Load and apply 4 wall textures (N/S/E/W) |
๐ง Raycasting | Simulate 3D walls from 2D map using DDA |
๐๏ธ Floor & Ceiling | Different RGB colors for floor and ceiling |
๐ช Window Handling | MiniLibX window with proper close handling |
๐งผ Error Handling | Descriptive errors for malformed files |
๐พ Memory Safe | No leaks, crashes, or norm errors |
Bonus | Description |
---|---|
๐งฑ Wall Collision | Prevent walking through walls |
๐บ๏ธ Minimap | 2D top-down view of the maze with player view |
๐ช Doors | Openable/closable doors with keypress |
๐ Animated Sprites | Moving enemies, items, etc. |
๐ฑ๏ธ Mouse Look | Rotate view using mouse movement |
๐ฏ HUD | Add health bar, weapons, shooting system |
NO ./textures/north.xpm
SO ./textures/south.xpm
WE ./textures/west.xpm
EA ./textures/east.xpm
F 02,0,0
C 01,0,0
1111111
1000001
111D111
10N0001
1111111
NO/SO/WE/EA
: Texture pathsF
/C
: Floor and ceiling colors (RGB)- Map symbols:
1
: Wall0
: FloorD
: DoorN/S/E/W
: Player start position + orientation
Map must be closed (no open edges).
cub3d/
โโโ src/ # All .c files
โโโ includes/ # .h headers
โโโ textures/ # .xpm textures
โโโ maps/ # .cub map files
โโโ libft/ # Your own libft copy
โโโ Makefile
โโโ README.md
-
Clone the repository to your local machine:
git clone https://github.com/samir-ouaammou/3D-Game
-
Navigate to the project directory:
cd 3D-Game/Project
-
Compile the source files using
make
:make
-
Clean up compiled files:
make clean
-
To remove all object files and the executable:
make fclean
-
To recompile the project from scratch:
make re
-
Run the program:
./cub3D maps/map2.cub
Key | Action |
---|---|
W | Move forward |
S | Move backward |
A | Move left |
D | Move right |
E | Open Door |
โ / โ | Rotate view |
ESC | Exit |
Red [X] | Close window |

- ๐ฅ๏ธ C (C99)
- ๐จ MiniLibX
- ๐งฎ <math.h>
- ๐งฐ valgrind for memory leaks
- ๐งช 42 Norm compliant
- ๐ 3D rendering techniques without OpenGL
- ๐ง Raycasting & DDA algorithm
- ๐งต Event-driven programming with MiniLibX
- ๐ File parsing and validation
- ๐ฅ Manual memory management in C
- ๐ช Map design and file formats
Want to dive deeper? Here are some great resources to understand raycasting better:
- Lode's Computer Graphics Tutorial
- Interactive DDA Algorithm
- Lodev Raycasting
- Wikipedia โ Ray Casting
๐ค Samir Ouaammou
Student at [1337 School โ UM6P, 42 Network]
๐ฅ๏ธ Passionate about low-level programming, graphics, and game dev
๐ซ Connect with me on LinkedIn
Thank you for checking out my cub3D project! Stay tuned for more exciting challenges. ๐ฅ