An open API service indexing awesome lists of open source software.

https://github.com/mdbentaleb/cub3d_42


https://github.com/mdbentaleb/cub3d_42

Last synced: 8 months ago
JSON representation

Awesome Lists containing this project

README

          

# ๐Ÿ•น๏ธ CUB3D

Image

## ๐Ÿ“Œ 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