*This project has been created as part of the 42 curriculum by amikhail and aortigos.*

# cub3d

## Description
<!-- Section that clearly presents the project, including its goal and a brief overview -->

**cub3D** is a graphical programming project inspired by the classic game *Wolfenstein 3D*,
one of the first First-Person Shooters ever created.

The objective of this project is to create a **real-time 3D representation of a maze** from a **2D map**, 
using the **ray-casting technique**, written in **C** and rendered with **MLX42**.

The rendering is done column by column by casting rays from the player's point of view, detecting wall intersections, calculating distances, and projecting textured walls with proper persepective correction.
Floor and ceiling colors are also rendered to complete the scene.

This project focuses on:
- Low-level graphics programming
- Mathematical projection and geometry
- 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 `.cub` file parsing and validation
- Clean error handling and memory management
- MLX42 rendering loop

---

## Instructions
<!-- Section containing any relevant information about compilation, installation, and/or execution -->

### Requirements
 - Linux or macOS
 - CMake
 - MLX42 / MLX
 - C compiler (`gcc` or `clang`)

### Compilation
Clone the repository and run:
```bash
make
```
This will:
- Build MLX42
- Compile `libft`, `ft_printf`, and `get_next_line`
- Generate the `cub3d` executable


### Execution
```bash
./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

The following resources were used during the development of this project
to understand ray-casting, cub3D structure, and common mistakes:

- **42 cub3D Approach (ES)**  
  https://42-fran-byte-f94097.gitlab.io/docs/cub3d/cub3d-approach-es/#/  
  Overview of the cub3D project.

- **Harm Smits – cub3D Docs**  
  https://harm-smits.github.io/42docs/projects/cub3d  
  One of the most complete references for cub3D, including math, ray-casting concepts,
  and implementation strategies.

- **Ray Casting in C (Medium)**  
  https://ismailassil.medium.com/ray-casting-c-8bfae2c2fc13  
  Clear explanation of ray-casting fundamentals with C-oriented examples.

- **Raycasting Tutorial (YouTube)**  
  https://www.youtube.com/watch?v=G9i78WoBBIU  
  Visual explanation of the ray-casting technique, useful for understanding
  perspective projection and wall rendering.


### 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.

