A small raycasting-based 3D game developed as part of the 42 curriculum.
cub3d is a small 3D project built around .cub scene parsing, raycasting and real-time movement with MiniLibX.
It was a good way to build solid foundations in parsing, 2D-to-3D projection, graphics programming, event handling and state-driven rendering in C.
- Raycasting-based first-person rendering
- Parsing and validation of
.cubconfiguration files - Wall textures for the four cardinal directions
- Floor and ceiling color configuration
- Keyboard-based movement and rotation
- Bonus features including a minimap, mouse rotation and a start menu
includes/cub3d.h— main header file, structures, constants and function prototypessrcs/parsing/—.cubfile parsing, texture/color loading and map validationsrcs/raycasting/— ray setup, DDA calculations, wall distance computation and renderingsrcs/player/— player initialization, movement, keyboard handling and rotationsrcs/bonus/— bonus minimap and mouse rotation supportassets/— textures and menu assetsmaps/— valid and invalid.cubtest mapsincludes/libft/— local libft used by the projectminilibx_macos/— macOS version of MiniLibX bundled with the repositoryMakefile— builds thecub3Dexecutable
The mandatory part focuses on the parsing and rendering logic required to load a valid .cub scene and display it from the player point of view.
cub3D— loads a.cubfile, validates the scene, opens a window and renders the world from the player point of view
- parses the scene file and checks the
.cubextension - loads texture paths for
NO,SO,WEandEA - parses floor and ceiling colors
- validates the map structure and starting player position
- renders walls with a raycasting loop
- allows movement with
W,A,SandD - allows rotation with the arrow keys
- closes cleanly through the escape key or window close event
- the program parses the
.cubconfiguration file and validates its content - it initializes the player state, raycasting data, textures and MiniLibX context
- a window and image buffer are created for rendering
- the game loop casts one ray per screen column to detect wall intersections
- wall slices are drawn according to distance and texture sampling
- player movement and rotation update the view in real time
- the map must be parsed from a valid
.cubfile - textures and colors must be defined correctly before the map
- the map must be closed and contain exactly one player start
- movement must respect wall collisions
- rendering must use MiniLibX
- the program must handle invalid input cleanly and avoid crashes
The bonus part adds a minimap, mouse-based rotation and a simple start menu.
This repository comes from a collaborative 42 project built with GxLuck02. His part mainly focused on the parsing side of the project.
My part in this project mainly covers rendering, player interaction and the real-time side of the game.
- building the raycasting pipeline
- handling player controls, movement and rotation
- initializing and applying wall textures
- adding the mouse rotation bonus
Raycasting is the core of cub3d.
The program casts one ray per vertical screen column from the player position into the 2D map, detects where each ray hits a wall and uses that distance to draw the correct wall slice on screen.
By repeating that process for every frame, the map stays 2D internally while the player gets a convincing first-person view with depth and real-time movement.
This project was developed on macOS and the repository is currently configured for the macOS version of MiniLibX. The provided build setup therefore targets macOS first and no Linux-specific adaptation is included in this repository.
Build the project:
makeBuild the bonus version:
make bonusClean object files:
make cleanRemove object files and executable:
make fcleanRebuild everything:
make reRun the program with a valid map file:
./cub3D maps/map1.cubThis project was my first real introduction to basic 3D rendering techniques in C. It helped build solid foundations in:
- file parsing and validation
- grid-based raycasting
- DDA traversal
- texture mapping
- input and movement handling
- MiniLibX rendering workflows
