Skip to content
ftTowerPublic

About

A "3D" game project using raycasting in C, inspired by Wolfenstein 3D

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

ย 

History

71 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Cub3D

A 3D rendering engine inspired by Wolfenstein 3D

Project developed as part of the 42 Paris curriculum

42 Project Language Graphics


๐Ÿ“– About

Cub3D is a 3D engine based on the raycasting technique, the same technology used in the legendary Wolfenstein 3D. This project transforms a 2D map into an immersive 3D experience through dynamic collision management and custom texture application.

Raycasting simulates a 3D view by casting rays from the player's position to calculate distances to walls, creating an illusion of depth without requiring a real 3D engine.

Cub3D Gameplay


๐Ÿ“‘ Table of Contents


โœจ Features

Graphics Rendering

  • โšก Real-time Raycasting: Generates a smooth 3D view from a 2D map
  • ๐ŸŽจ Texture System: Custom texture application for each direction (North, South, East, West)
  • ๐ŸŒˆ Configurable Colors: Customizable floor and ceiling via RGB

Gameplay

  • ๐ŸŽฏ Collision Detection: Precise collision system for realistic navigation
  • ๐Ÿงญ Smooth Navigation: Optimized movement and rotation
  • ๐Ÿ—บ๏ธ Interactive Mini-map: Real-time player position display

Development Tools

  • ๐Ÿ› Debug Mode (F3): Displays debugging information (FPS, position, direction)
  • ๐Ÿ” Dynamic Zoom: Mini-map zoom level control
  • ๐Ÿ“Š Performance Display: Real-time performance monitoring

Cub3D Map View


๐Ÿ› ๏ธ Technologies

  • Language: C (42 Standard)
  • Graphics Library: MiniLibX
  • Build System: GNU Make
  • Compilation: GCC with flags -Wall -Wextra -Werror
  • Mathematics: math.h library for trigonometric calculations

๐Ÿ“ฅ Installation

Prerequisites

Make sure you have the following dependencies installed on your Linux system:

# C Compiler
sudo apt-get install gcc make

# MiniLibX Dependencies
sudo apt-get install libx11-dev libxext-dev libbsd-dev

Compilation

# Clone the repository
git clone https://github.com/ftTower/Cub3D.git
cd Cub3D

# Compile MiniLibX
make minlibx

# Compile the project
make

# Run the program with a map
./cub3d maps/VanGogh.cub

Bonus Compilation

make bonus  # Compile with bonus features (if available)
make clean  # Remove object files
make fclean # Remove object files and executable
make re     # Fully recompile the project

๐ŸŽฎ Usage

Quick Start

./cub3d <path_to_map.cub>

Examples

# Van Gogh Map (recommended)
./cub3d maps/VanGogh.cub

# Basic Map
./cub3d maps/file.cub

โŒจ๏ธ Controls

Movement

Key Action
W / โ†‘ Move Forward
S / โ†“ Move Backward
A Strafe Left
D Strafe Right

Rotation

Key Action
โ† Rotate Left
โ†’ Rotate Right

Interface

Key Action
M Show/Hide Mini-map
F3 Enable/Disable Debug Mode
+ Zoom In Mini-map
- Zoom Out Mini-map
ESC Exit Program

Cub3D Debug Mode


โš™๏ธ Configuration

.cub File Format

The configuration file defines the game environment. It must contain:

1. Wall Textures

NO ./path/to/north_texture.xpm
SO ./path/to/south_texture.xpm
WE ./path/to/west_texture.xpm
EA ./path/to/east_texture.xpm

2. Colors (RGB format)

F 220,100,0    # Floor
C 225,30,0     # Ceiling

3. Map

111111111111
100000000001
101100000001
100000N00001
111111111111

Map Characters

  • 0: Empty space (navigable)
  • 1: Wall
  • N / S / E / W: Player starting position and orientation
    • N: North
    • S: South
    • E: East
    • W: West

Validation Rules

  • โœ… The map must be surrounded by walls (1)
  • โœ… Only one player must be present
  • โœ… All texture paths must be valid
  • โœ… Colors must be in RGB format (0-255)
  • โœ… Empty spaces must be closed (no openings to the void)

Example File

See full example: VanGogh.cub

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

F 184,113,39
C 51,153,255

111111111111111111111111
100000000011000000000001
101100000111000000000001
100100000000000000000001
111111111011000001110001
100000000011000001110001
111111111111111111111111

๐Ÿ—๏ธ Project Architecture

cub3d/
โ”œโ”€โ”€ src/                    # Main source code
โ”‚   โ”œโ”€โ”€ init/              # Initialization and parsing
โ”‚   โ”‚   โ”œโ”€โ”€ config.c       # Configuration parsing
โ”‚   โ”‚   โ”œโ”€โ”€ map.c          # Map parsing
โ”‚   โ”‚   โ””โ”€โ”€ map_parse.c    # Map validation
โ”‚   โ”œโ”€โ”€ raycasting/        # Rendering engine
โ”‚   โ”‚   โ”œโ”€โ”€ raycasting.c   # DDA Algorithm
โ”‚   โ”‚   โ”œโ”€โ”€ textures.c     # Texture management
โ”‚   โ”‚   โ””โ”€โ”€ raytures.c     # Texture application
โ”‚   โ”œโ”€โ”€ loop/              # Game loop
โ”‚   โ”‚   โ”œโ”€โ”€ game.c         # Main loop
โ”‚   โ”‚   โ””โ”€โ”€ key.c          # Event handling
โ”‚   โ”œโ”€โ”€ img/               # Graphics management
โ”‚   โ”‚   โ”œโ”€โ”€ img.c          # Image manipulation
โ”‚   โ”‚   โ”œโ”€โ”€ drawing.c      # Drawing functions
โ”‚   โ”‚   โ””โ”€โ”€ put_string.c   # Text display
โ”‚   โ”œโ”€โ”€ main.c             # Entry point
โ”‚   โ”œโ”€โ”€ free.c / free2.c   # Memory management
โ”‚   โ””โ”€โ”€ utils.c / utils2.c # Utility functions
โ”œโ”€โ”€ ReFile/                 # Parsing library
โ”‚   โ”œโ”€โ”€ gnl/               # Get Next Line
โ”‚   โ””โ”€โ”€ src/               # File utilities
โ”œโ”€โ”€ includes/              # Headers
โ”‚   โ””โ”€โ”€ cub3d.h           # Definitions and structures
โ”œโ”€โ”€ maps/                  # Test maps
โ”‚   โ””โ”€โ”€ textures/         # XPM Textures
โ”œโ”€โ”€ assets/                # Resources (screenshots)
โ””โ”€โ”€ Makefile              # Compilation

Key Implemented Concepts

  • Digital Differential Analyzer (DDA): Raycasting algorithm for intersection detection
  • Memory Management: Clean allocation and deallocation of resources
  • Event Loop: Rendering loop and MiniLibX event handling
  • Texture Mapping: Projection of 2D textures onto walls
  • Collision Detection: Wall collision detection

๐Ÿ‘ฅ Authors

Developed by @ftTower


โญ If you liked this project, feel free to give it a star! โญ

About

A "3D" game project using raycasting in C, inspired by Wolfenstein 3D

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages