42_cub3d/include/map.h
2024-10-04 15:32:12 +02:00

106 lines
3.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <mcolonna@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */
/* Updated: 2024/10/04 13:13:04 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MAP_H
# define MAP_H
# include <stdbool.h>
# include "color.h"
/// @brief The type of a case.
typedef enum e_map_wall
{
/// @brief Empty case, for '0' and ' '.
EMPTY,
/// @brief A wall, for '1'.
WALL,
} t_map_wall;
/// @brief An object of the map (player, enemies?)
typedef struct s_object
{
/// @brief Function called when creating the object.
///
/// @param data Address of the s_object.data pointer.
void (*init)(void **data);
/// @brief Function called when destroying the object (to avoid leaks).
///
/// @param data Address of the s_object.data pointer.
void (*destroy)(void **data);
/// @brief Function called each tick.
///
/// @param data Address of the s_object.data pointer.
void (*tick)(void **data);
/// @brief Pointer the object can use to save data.
void *data;
} t_object;
/// @brief Represents a case of the map.
typedef struct s_map_case
{
/// @brief Is the case empty or a wall?
t_map_wall wall;
/// @brief The object that appears on this case. If there is none,
/// every pointer of the struct will be NULL.
t_object object;
} t_map_case;
/// @brief Represents a map.
typedef struct s_map
{
/// @brief Color of the floor.
t_color color_floor;
/// @brief Color of the ceiling.
t_color color_ceiling;
/// @brief Path to the image file for the wall face north.
const char *texture_north;
/// @brief Path to the image file for the wall face south.
const char *texture_south;
/// @brief Path to the image file for the wall face west.
const char *texture_west;
/// @brief Path to the image file for the wall face east.
const char *texture_east;
/// @brief Width of the map.
unsigned int width;
/// @brief Height of the map.
unsigned int height;
/// @brief An 2D array of all the cases.
///
/// Syntax to get a case: cases[y * width + x]
/// x is left to right, y is top to bottom.
t_map_case *cases;
} t_map;
/// @brief Create a t_map from the content of a .cub file.
///
/// @param dest Pointer to the t_map to set.
/// @param file .cub file to use to create the t_map.
/// It must be destroyed with mapDestroy to avoid leaks.
/// @return false if an error occured, otherwise true.
bool map_from_file(t_map *dest, const char *file);
/// @brief Destroy the map to avoid leaks.
void map_destroy(t_map *map);
#endif