Skip to content

cmsweeting/Cub3D

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

280 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CUB3D

Cub3D is a simple raycasting engine inspired by Wolfenstein 3D. The goal is to create a FPS view of a labryinth.

last-commit repo-top-language repo-language-count

Table of Contents


Getting Started

Prerequisites

This project was built on Ubuntu 22, it is untested on other distributions and operating systems.

The MLX is included in this repositery, but you might need to install its dependencies:

sudo apt-get update && sudo apt-get install xorg libxext-dev zlib1g-dev libbsd-dev

The project also requires make for compilation :

sudo apt-get install make

Installation

Install Cub3D using one of the following methods:

Build from source:

❯ git clone https://github.com/cmsweeting/Cub3D
❯ cd Cub3D
❯ make

Usage

Cub3D requires a configuration file to be provided in order to be able to run. You can find several valid config files under the maps/ directory.

Once the executable is created, you can run it :

❯ ./cub3D maps/anymap

You can provide you own map, though note that if must contain:

  • four textures identified by 'NO ', 'SO ', 'WE ', 'EA ' (with the quotes removed)
  • two RGB colors identified by 'F ' and 'C '
  • A closed map composed of '0', '1', and one of those four identifiers : N, S, W or E to determine the player's start position and orientation.

You may also provide your own textures in .xpm format.


Features

Feature Summary
⚙️ Architecture
  • Cub3D uses a modular architecture with separate modules for parsing, rendering, and game logic.
  • The project is built using the C programming language.
  • It utilizes various libraries and dependencies to manage graphics, input/output operations, and other system resources.
🔌 Integrations
  • Cub3D integrates various libraries and dependencies for graphics rendering, input/output operations, and system resources.
  • The project uses XPM (X PixMap) files for image rendering and CUB files for map parsing.
🧩 Modularity
  • Cub3D has a modular architecture, which allows for easy maintenance, modification, and extension of individual modules.
  • The project's modularity enables the development of new features and game modes without affecting the overall structure.
🧪 Testing
  • Running bash scripts/test_parsing will run a serie of unit test on the map's parsing to ensure that a range of case are handled.


Project Structure

.
├── libs/
│   ├── mlx
│   └── libft
├── maps
├── scripts/
│   ├── exf
│   ├── extract_funct
│   ├── norm
│   ├── prep
│   ├── push
│   ├── readme
│   └── test_parsing
├── src/
│   ├── error_handling/
│   │   └── error_handling.c
│   ├── includes/
│   │   ├── cub3D.h
│   │   └── struct.h
│   ├── parsing/
│   │   ├── extract_file.c
│   │   ├── get_map_data.c
│   │   ├── handle_colors.c
│   │   ├── init_mlx.c
│   │   ├── init_textures.c
│   │   ├── is_map_valid.c
│   │   ├── iterative_floodfill.c
│   │   ├── memory_allocation
│   │   └── p_utils.c
│   ├── print_strcts.c
│   ├── raycasting/
│   │   ├── display.c
│   │   ├── draw.c
│   │   ├── events.c
│   │   ├── math_utils.c
│   │   ├── movements.c
│   │   ├── raycasting.c
│   │   └── raycasting_utils.c
│   ├── main.c
│   └── print_strcts.c
├── textures
└── Makefile

Project Index

src
main.c - Initialize and run a game by parsing a map file, validating its contents, and setting up the display
- The main function takes one command-line argument, which is the path to the map file
- It then populates a ray structure with the configuration files values, validates the map, initializes the display, and runs the game.
print_strcts.c - The `print_strcts.c` file provides a mechanism to print the structure of various game elements, including player positions, textures, and map information
This code helps developers visualize and debug their projects by providing a clear representation of the game's internal state.
includes
struct.h - Defines the fundamental data structures and types used throughout the project's architectur.
error_handling
error_handling.c - Handles error messages by joining error codes and messages into a single string, then prints the resulting message to the standard error stream.
parsing
init_mlx.c - Initialize and load textures from XPM files into the game's rendering engine. This function creates images from XPM files representing the east, south, west, and north walls of a room in a Cub3D game.
- It uses the MLX library to load these textures and store them as pointers within the `t_ray` structure.
extract_file.c - The `extract_file` function parses a file and extracts its contents into a character array, allowing the file's data to be processed further
- This code is part of a larger project that handles parsing and processing of files in a specific format
- The extracted file content is then used to populate a parser object with relevant values.
is_map_valid.c - Validates the integrity of a map by ensuring the presence of a player start position and allocates memory for the square map
- This code ensures the map meets the necessary conditions to be considered valid.
handle_colors.c Handles colors by parsing RGB values from input files, validating their format and range, and storing them as integers in a data structure
- This functionality enables the creation of color-coded maps with distinct floor and ceiling colors.
init_textures.c - Initialize textures by retrieving XPM data from the MLX library, assigning it to respective ray structures (ea, we, so, no), and verifying successful retrieval
- This code enables the parsing of texture information, a crucial step in rendering 3D graphics.
p_utils.c This file provides utility functions for parsing and validating map elements in the Cub3D project
- It includes checks for invalid characters, element presence, and maximum line length
- The code ensures that all required elements are present and correctly formatted, reporting errors if any issues are found.
get_map_data.c - The `get_map_data.c` file is responsible for parsing map data from a .cub configuration file
- It extracts and processes information about the game's elements, such as textures, colors, and paths, to populate the parser's internal structures
- This code plays a crucial role in setting up the game environment and ensuring proper rendering of game objects.
iterative_floodfill.c - The iterative_floodfill.c file implements the iwall function, which performs a flood fill algorithm on a given map to identify and mark walls in a 2D environment
- This function takes a parser object as input, iterates through the map, and marks non-zero cells as ' ' (space) characters, effectively creating a wall representation.
memory_allocation
destroy_structs.c - Destroying memory structures is the primary purpose of this code file
- It frees allocated memory blocks for parser and ray objects, ensuring proper deallocation and preventing memory leaks.
memalloc.c - The `memalloc.c` file optimizes memory allocation for the parsing module of a project by providing functions to dynamically reallocate and copy map data structures
- It ensures efficient handling of large maps, reallocating memory as needed while preserving original data integrity.
raycasting
display.c - The `display.c` file initializes and manages the graphical display of a raycasting game
- It sets up the rendering context, creates windows, and handles user input events to control the game's camera angles and movement
- The file also cleans up resources when the display is closed.
movements.c Updates the player's position and angle based on movement inputs, ensuring valid movements within the game map while maintaining a consistent orientation. Enables the player to move around the 3D environment and respond to user input.
draw.c Render raycasting results by drawing a column of pixels representing a wall's texture and color, taking into account distance, height, and ceiling/floor colors
math_utils.c - Calculate distances between points and normalize angles within the raycasting system.Provides mathematical functions to support the overall architecture of the project
- It enables accurate calculations of distances between points and ensures that angles are properly normalized.
events.c - Handles user input events in the raycasting game, enabling movement and rotation controls
- The file processes keyboard inputs to update the player's movements and camera orientation, allowing for seamless navigation through the game environment.
raycasting.c - The `raycasting.c` file implements the raycasting algorithm for rendering a 3D scene onto a 2D surface
- It calculates the intersection points of rays with walls, determines the closest hit point, and draws columns based on the distance from the camera
- The code handles vertical and horizontal intersections, normalizes angles, and adjusts the camera's view to remove the fish-eye effect.
raycasting_utils.c - The file provides utility functions to check collisions and find walls in a given environment
- It enables the detection of boundaries, such as walls or floors, allowing for more accurate rendering and navigation within the 3D space.

Ressources


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors