https://github.com/mdbentaleb/cub3d_42
https://github.com/mdbentaleb/cub3d_42
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mdbentaleb/cub3d_42
- Owner: mdbentaleb
- Created: 2025-08-28T10:07:13.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-08-28T16:58:12.000Z (9 months ago)
- Last Synced: 2025-08-28T17:32:52.830Z (9 months ago)
- Language: C
- Size: 1.5 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐น๏ธ CUB3D

## ๐ Overview
**CUB3D** is a core project in the 42 curriculum that aims to build a simple 3D graphics engine using **C** and **MLX**. The project focuses on learning the basics of **raycasting**, window management, image handling, and converting 2D maps into a 3D first-person perspective similar to games like Wolfenstein 3D.
## โจ Features
* ๐ง 3D rendering engine using **raycasting**
* ๐ Load and display 2D maps (`.cub` files)
* ๐ช Render walls, floor, and ceiling with colors and textures
* ๐ Smooth player movement and rotation
* ๐ File parsing and map validation
* ๐งฑ Image management using **MLX**
* โก Wall collision detection to prevent walking through walls
* ๐ผ๏ธ Texture loading and rendering
* ๐งช Proper memory management to avoid leaks
* ๐จ Basic graphics with dynamic coloring
* โฑ๏ธ Real-time updates of player movement
## ๐งญ What CUB3D Supports
### ๐งต Execution Engine
* Parse `.cub` map files to generate the environment
* Use **raycasting** to calculate distances and render walls
* Draw walls and floors in real time
### ๐งน Parsing & Map Loading
* Read map files and validate their structure
* Check player position and other map elements
* Support fully enclosed maps to avoid errors
### โ๏ธ Movement & Physics
* Move forward, backward, left, and right
* Rotate smoothly left/right
* Wall collision detection to prevent walking through walls
### ๐ Graphics
* Render walls column by column (raycasting)
* Apply textures to walls and floors
* Render elements dynamically on the screen
* Continuously update the screen with player movement
### ๐ฌ Input & Interaction
* Keyboard input for movement and rotation
* Safe exit by closing the window or pressing ESC
* Smooth screen updates for a better experience
### โ ๏ธ Error Handling
* Validate files and inputs
* Handle loading and rendering errors
* Avoid memory leaks and ensure proper file handling
## ๐ ๏ธ Technical Constraints
* โ No external graphics libraries except **MLX**
* โ
Must comply with **Norminette** rules:
* Max 25 lines per function
* Max 4 variables per function
* Max 4 arguments per function
* ๐ Proper memory management to prevent leaks
* ๐ Smooth frame updates without freezing
## โถ๏ธ How to Use
### ๐ ๏ธ First-Time Setup
Before using the project for the first time, you need to run the `setup.sh` script to install all required dependencies (like MLX and any required libraries).
If your system requires administrative privileges to install libraries, run the script with sudo:
```bash
cd Cub3D_42/
```
```bash
./setup.sh
```
This will check your system, install any missing libraries, and prepare the environment for CUB3D.
### ๐ Running CUB3D
Run the game with:
```bash
./cub3d path/to/map.cub
```
A window will open displaying the 3D world where you can navigate using the keyboard.
### ๐ก Tips
* Use **W/A/S/D** to move
* Use **Arrow keys** to rotate
* Close the window or press **ESC** to exit
* Make sure your map files are valid before running
### ๐งช Example Usage
```shell
./cub3d maps/map1.cub
```
* You can move within the map
* Walls and floors are rendered in 3D
* Wall collision prevents walking through walls