diff --git a/Makefile b/Makefile index 337416e..083f1eb 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,6 @@ IFLAGS := -Ilibft/include -Iinclude -IMLX42/include SRC_DIR := src SRCS = parser/check_elements.c \ - parser/check_walls.c \ parser/parse_elements.c \ parser/parse_map.c \ parser/check_map.c \ diff --git a/include/meta.h b/include/meta.h index d8ce814..99a9838 100644 --- a/include/meta.h +++ b/include/meta.h @@ -206,6 +206,11 @@ typedef struct s_sprite { t_tex tex; } t_sprite; +typedef struct s_door { + t_tex tex; + uint32_t idx; +} + typedef struct s_attr { t_tex n; //add bit flag, if tex_path is missing then it means it is a color value t_tex s; @@ -219,6 +224,8 @@ typedef struct s_attr { uint32_t sprite_count; uint32_t sprite_arr_index; t_sprite *sprites; // we need to make the sprite count modular + uint32_t door_count; + t_door *doors; } t_attr; typedef struct s_minimap { diff --git a/src/parser/check_map.c b/src/parser/check_map.c index e473c56..ab4b116 100644 --- a/src/parser/check_map.c +++ b/src/parser/check_map.c @@ -114,6 +114,8 @@ t_cell_type find_enum_value(char c) { return (MAP_WALL); } + else if (c == 'D') + return (MAP_DOOR); else { return (MAP_SPACE); @@ -135,6 +137,7 @@ bool save_map(t_meta *meta, char *rect) } return (true); } + int check_map(t_meta *meta, char *rect) { if (!is_map_chars_valid(rect)) diff --git a/src/parser/check_walls.c b/src/parser/check_walls.c deleted file mode 100644 index ba95e33..0000000 --- a/src/parser/check_walls.c +++ /dev/null @@ -1,108 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* :::::::: */ -/* check_walls.c :+: :+: */ -/* +:+ */ -/* By: yzaim +#+ */ -/* +#+ */ -/* Created: 2024/01/08 16:08:46 by yzaim #+# #+# */ -/* Updated: 2024/01/08 16:08:50 by yzaim ######## odam.nl */ -/* */ -/* ************************************************************************** */ - -#include "parser.h" - -// returns 1 if walls are not closed -int check_horiz_left(t_meta *meta, char *map) -{ - uint32_t x; - uint32_t y; - bool closed; - - y = 0; - while (y < meta->map.height) - { - closed = false; - x = 0; - while (x < meta->map.width) - { - // printf("c: %c\n", map[find_index(meta, y, x)]); - if (map[find_index(meta, x, y)] == '1') - closed = true; - if (!closed && map[find_index(meta, x, y)] == '0') // walls not closed - return (pr_err(INV_WALLS), EXIT_FAILURE); - x++; - } - y++; - } - return (EXIT_SUCCESS); -} - -int check_vert_top(t_meta *meta, char *map) -{ - uint32_t x; - uint32_t y; - bool closed; - - x = 0; - closed = false; - while (x < meta->map.width) - { - closed = false; - y = 0; - while (y < meta->map.height) - { - if (map[find_index(meta, x, y)] == '1') - closed = 1; - if (!closed && map[find_index(meta, x, y)] == '0') // walls not closed - return (pr_err(INV_WALLS), EXIT_FAILURE); - y++; - } - x++; - } - return (EXIT_SUCCESS); -} - -int check_horiz_right(t_meta *meta, char *map) -{ - uint32_t x; - uint32_t y; - bool closed; - - y = meta->map.height; - while (--y > 0) - { - closed = false; - x = meta->map.width; - while (--x > 0) - { - if (map[find_index(meta, x, y)] == '1') - closed = true; - if (!closed && map[find_index(meta, x, y)] == '0') // walls not closed - return (pr_err(INV_WALLS), EXIT_FAILURE); - } - } - return (EXIT_SUCCESS); -} - -int check_vert_down(t_meta *meta, char *map) -{ - uint32_t x; - uint32_t y; - bool closed; - - x = meta->map.width; - while (--x > 0) - { - closed = false; - y = meta->map.height; - while (--y > 0) - { - if (map[find_index(meta, x, y)] == '1') - closed = true; - if (!closed && map[find_index(meta, x, y)] == '0') // walls not closed - return (pr_err(INV_WALLS), EXIT_FAILURE); - } - } - return (EXIT_SUCCESS); -} diff --git a/src/parser/parse_elements.c b/src/parser/parse_elements.c index 45624e5..327ab40 100644 --- a/src/parser/parse_elements.c +++ b/src/parser/parse_elements.c @@ -159,12 +159,48 @@ int set_up_sprites(t_meta *meta) return (EXIT_SUCCESS); } +uint32_t count_doors(t_cell_type *map, uint32_t w, uint32_t h) +{ + uint32_t doors; + uint32_t i; + + doors = 0; + i = 0; + while (i < w * h) + { + if (map[i] == MAP_DOOR) + doors++; + i++; + } + return (doors); +} + +int save_index(t_door *doors, uint32_t door_count) +{ + uint32_t i; + + i = 0; +} + +int set_doors(t_meta *meta) +{ + meta.attributes.doors = malloc(sizeof(t_door) * meta.attributes.door_count); + if (!meta.attributes.doors) + return (pr_err(MALL_ERR)); + +} + int parse_elements(t_meta *meta) { t_flag *elements = meta->elements; meta->attributes.sprite_count = count_sprites(meta->elements); + meta.attributes.door_count = count_doors(meta.map.level, meta.map.width, meta.map.height); meta->attributes.sprite_arr_index = 0; + if (meta.attributes.door_count) + { + // save door idx + } if (set_up_sprites(meta)) return (EXIT_FAILURE); while (elements != NULL) diff --git a/src/parser/utils_one.c b/src/parser/utils_one.c index 68efc0c..04c839e 100644 --- a/src/parser/utils_one.c +++ b/src/parser/utils_one.c @@ -42,7 +42,7 @@ void skip_digits(char **file) int valid_map_char(char c) { return (c == '1' || c == '0' || c == 'N' || c == 'S' \ - || c == 'E' || c == 'W' || c == ' '); + || c == 'E' || c == 'W' || c == ' ' || c == 'D'); } int player_pos_char(char c)