Skip to content
← All projects

2023–2025

cub3D

A basic 3D game engine in C, built with the MiniLibX graphics library. It renders a 3D world from a 2D map with raycasting, like classic games such as Wolfenstein 3D, and adds bonus features: mouse camera control, a hand animation, interactive doors and a minimap.

Context

cub3D is a 3D graphics project from the 42 curriculum, built with the MiniLibX library.

Problem

Turn a flat 2D map into a 3D world you can walk through, drawing every frame yourself with only a small graphics library. The projection, the textures and the collisions all have to be written by hand.

Objectives

  • Render textured walls in 3D perspective from a 2D map, using raycasting.
  • Move with W, A, S and D, and rotate the view with the mouse or the arrow keys.
  • Stop the player from walking through walls or doors.
  • Bonus: a hand animation on key press, doors the player can open, and a minimap.

How it works

Raycasting

The draw_plane function casts rays from the player's point of view and works out what is visible. Each ray keeps going until it hits a wall (1 on the map) or a door (D). The perform_dda function walks the ray through the map to find that hit accurately.

Collision detection

The same DDA algorithm checks each ray's direction and computes how far the player can move before touching a wall, so the player cannot clip through walls or doors.

Animation

The hand animation is a sequence of frames. The first frame is drawn by default, and pressing F plays the rest once, with update_hand_animation moving between frames.

Controls and interactions

W, A, S and D move the player, and the mouse or the arrow keys rotate the camera. F plays the hand animation, and E opens a door.

Architecture

Written in C on the MiniLibX library, with a custom libft, and built with a Makefile (make bonus). The repository holds srcs/, include/, libft/, maps/ and textures/. The game starts from a .cub map file, where 1 is a wall and D is a door, for example ./cub3D_bonus maps/map_bonus.cub. It runs on macOS or Linux.

Outcome

A playable first-person 3D game with textured walls, mouse and keyboard movement, a hand animation, interactive doors and a minimap.

Stack

  • C
  • MiniLibX
  • Raycasting
  • UNIX/Linux