From 9cd2f6e29e5164f9b172cd2fe0d10863085183fa Mon Sep 17 00:00:00 2001 From: mcolonna Date: Tue, 1 Oct 2024 14:08:22 +0200 Subject: [PATCH] add include/map.h --- include/map.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 include/map.h diff --git a/include/map.h b/include/map.h new file mode 100644 index 0000000..67e379e --- /dev/null +++ b/include/map.h @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* map.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mcolonna +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */ +/* Updated: 2024/10/01 14:00:40 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MAP_H +# define MAP_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 free everything). + /// @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 Width of the map. + int width; + /// @brief Height of the map. + int height; + /// @brief An 2D array of all the cases. + /// Syntax to get a case: cases[y][x] + /// x is left to right, y is top to bottom. + t_map_case **cases; +} t_map; + +#endif \ No newline at end of file