Skip to content

JMADIL/CUB3D

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎮 Cub3D

My first RayCaster with miniLibX — 42 Network project

42 School Language License


📖 About

Cub3D is a 42 school project inspired by the legendary Wolfenstein 3D (1992) — the first-ever first-person shooter. Using raycasting, the program renders a dynamic 3D perspective view inside a maze defined by a 2D map file.

This project explores the foundations of computer graphics, trigonometry, and real-time rendering using the miniLibX graphics library.

✨ Features

  • 🎯 Raycasting Engine — Real-time 3D rendering from a 2D map using the DDA algorithm
  • 🧱 Textured Walls — Different textures for North, South, East, and West walls
  • 🎨 Floor & Ceiling Colors — Configurable RGB colors for floor and ceiling
  • 🕹️ Player Movement — Smooth WASD movement and arrow-key rotation
  • 🗺️ Map Parsing — Load custom .cub map files with validation
  • 🚪 Collision Detection — Wall collision prevents walking through walls

🚀 Getting Started

Prerequisites

  • GCC compiler
  • Make
  • miniLibX (included or install via package manager)
  • X11 libraries (sudo apt install libx11-dev libxext-dev on Ubuntu)
  • A UNIX-based OS (Linux / macOS)

Build

git clone https://github.com/JMADIL/CUB3D.git
cd CUB3D
make

Usage

./cub3d maps/map.cub

Controls

Key Action
W Move forward
S Move backward
A Strafe left
D Strafe right
Rotate camera left
Rotate camera right
ESC Exit the game

🗺️ Map Format (.cub)

NO ./textures/north.xpm
SO ./textures/south.xpm
WE ./textures/west.xpm
EA ./textures/east.xpm

F 220,100,0
C 135,206,235

111111
100101
101001
1100N1
111111
Symbol Meaning
1 Wall
0 Empty space
N/S/E/W Player start position + facing direction

📂 Project Structure

CUB3D/
├── Makefile            # Build system
├── cub3d.c             # Entry point & game loop
├── cub3d.h             # Header with structs & prototypes
├── cub.cub             # Sample map file
├── PROJECT_SUMMARY.md  # Detailed project documentation
├── parsing/            # Map file parsing & validation
├── raycasting/         # Raycasting engine (DDA algorithm)
├── textures/           # Wall texture files (.xpm)
├── utils/              # Utility functions
├── libft/              # Custom C library (libft)
└── documentation/      # Additional docs & references

🏗️ How Raycasting Works

         Player
           │
    ╲      │      ╱        For each vertical column of the screen:
     ╲     │     ╱          1. Cast a ray from the player
      ╲    │    ╱           2. Find where the ray hits a wall (DDA)
       ╲   │   ╱            3. Calculate the wall height based on distance
        ╲  │  ╱             4. Draw the textured wall slice
         ╲ │ ╱              5. Apply the correct texture (N/S/E/W)
          ╲│╱
     ══════════════         Result: A 3D perspective illusion
     ║            ║         from a 2D grid!
     ║   WALL     ║
     ║            ║
     ══════════════

🔑 Key Concepts Learned

Concept Description
Raycasting Rendering a 3D view from a 2D map using rays
DDA Algorithm Efficient grid traversal for ray-wall intersection
Trigonometry Angles, sine/cosine for movement and rotation
Texture Mapping Applying 2D textures to 3D-rendered wall surfaces
miniLibX Low-level graphics rendering and event handling
File Parsing Reading and validating structured map files
Game Loop Continuous rendering and input handling

👤 Author

Adil Jamoun@JMADIL

🏫 1337 Coding School (42 Network) — Morocco

About

A first-person 3D maze game rendered from a grid-based 2D map using raycasting principles. It features real-time player movement, wall collision handling, and camera rotation within a custom graphics window.

Topics

Resources

Stars

Watchers

Forks

Contributors