A 3D game engine inspired by Wolfenstein 3D, built from scratch using raycasting techniques
Features โข Installation โข Usage โข Documentation โข Technical Details
Cub3D is a 3D raycasting engine that creates a first-person perspective game similar to the classic Wolfenstein 3D. This project demonstrates advanced graphics programming concepts, mathematical algorithms, and real-time rendering techniques using the MLX graphics library.
- Real-time 3D Rendering using raycasting algorithm
- Textured Walls with XPM image support
- Smooth Player Movement with collision detection
- Configurable Maps via .cub configuration files
- Cross-platform Compatibility (macOS/Linux)
- Optimized Performance for 60+ FPS gameplay
- GCC compiler with C99 support
- Make build system
- MLX Library (included)
- macOS or Linux operating system
# Clone the repository
git clone https://github.com/yourusername/cub3d.git
cd cub3d
# Build the project
make
# Run with a map file
./cub3d maps/test.cub
Key | Action |
---|---|
W |
Move forward |
S |
Move backward |
A |
Strafe left |
D |
Strafe right |
โ |
Rotate left |
โ |
Rotate right |
ESC |
Exit game |
cub3d/
โโโ ๐ Makefile # Build configuration
โโโ ๐ includes/ # Header files
โ โโโ cube3d.h # Main header
โโโ ๐ src/ # Source code
โ โโโ ๐ events/ # Input handling
โ โโโ ๐ init/ # Initialization
โ โโโ ๐ movement/ # Player movement
โ โโโ ๐ parsing/ # File parsing
โ โโโ ๐ raycasting/ # 3D rendering
โ โโโ ๐ render/ # Graphics output
โ โโโ ๐ utils/ # Utilities
โโโ ๐ docs/ # Documentation
โโโ ๐ maps/ # Game maps (.cub)
โโโ ๐ textures/ # Wall textures (.xpm)
โโโ ๐ libft/ # Custom C library
โโโ ๐ mlx/ # Graphics library
NO ./textures/north.xpm
SO ./textures/south.xpm
WE ./textures/west.xpm
EA ./textures/east.xpm
F 220,100,0
C 225,30,0
111111
100001
101001
1000N1
111111
- NO/SO/WE/EA: Texture paths for each wall direction
- F: Floor color (RGB format)
- C: Ceiling color (RGB format)
- Map Grid:
1
= Wall0
= Empty spaceN/S/E/W
= Player start position and direction
- Language: C (C99 standard)
- Graphics: MLX (MiniLibX)
- Mathematics: Trigonometry, Linear Algebra
- Algorithms: DDA, Raycasting, Texture Mapping
graph TD
A[Main Loop] --> B[Event Handling]
A --> C[Raycasting Engine]
A --> D[Rendering Pipeline]
B --> E[Keyboard Input]
B --> F[Window Events]
C --> G[Ray Calculation]
C --> H[Wall Detection]
C --> I[Distance Calculation]
D --> J[Texture Mapping]
D --> K[Pixel Drawing]
D --> L[Frame Buffer]
- Frame Rate: 60+ FPS
- Resolution: 800x600 (configurable)
- Memory Usage: < 50MB
- CPU Usage: Optimized for real-time rendering
Module | Description | Documentation |
---|---|---|
Events | Input and window management | ๐ Events Docs |
Movement | Player movement mechanics | ๐ Movement Docs |
Raycasting | 3D rendering algorithm | ๐ Raycasting Docs |
Parsing | File parsing and validation | ๐ Parsing Docs |
Render | Graphics rendering pipeline | ๐ Render Docs |
Init | System initialization | ๐ Init Docs |
Utils | Utility functions | ๐ Utils Docs |
๐ Project Overview - Comprehensive technical documentation
make # Build the project
make clean # Remove object files
make fclean # Remove all generated files
make re # Rebuild from scratch
make leaks # Run with memory leak detection
- -Wall -Wextra -Werror: Strict error checking
- 42 Norm Compliant: Follows 42 School coding standards
- Optimized Build: Performance-focused compilation
- โ Wall enclosure verification
- โ Player position validation
- โ Texture file existence
- โ Color format validation
- โ Frame rate monitoring
- โ Memory leak detection
- โ Input responsiveness
- โ Rendering efficiency
Map | Description | Difficulty |
---|---|---|
simple.cub |
Basic rectangular room | Beginner |
complex.cub |
Multi-room layout | Intermediate |
maze.cub |
Challenging maze | Advanced |
This project demonstrates mastery of:
- Graphics Programming: Real-time 3D rendering
- Mathematical Concepts: Trigonometry, vector mathematics
- Algorithm Implementation: DDA, raycasting
- Memory Management: Efficient resource handling
- System Programming: Low-level graphics operations
- Software Architecture: Modular design patterns
- Follow 42 Norm: Strict adherence to coding standards
- Modular Design: Keep functions focused and reusable
- Error Handling: Comprehensive error checking
- Documentation: Clear code documentation
- Testing: Validate all changes thoroughly
// Function naming: lowercase with underscores
int calculate_distance(t_player *player, t_wall *wall);
// Structure naming: s_ prefix for struct, t_ for typedef
typedef struct s_game
{
void *mlx;
void *win;
t_img img;
} t_game;
This project is part of the 42 School curriculum. Educational use only.
- 42 School for the project specifications
- MLX Library developers for the graphics framework
- Wolfenstein 3D for the original raycasting inspiration
- John Carmack for pioneering 3D graphics techniques
Built with โค๏ธ at 42 School