diff --git a/ressources/bad_maps/wrongmap_hole_map.cub b/ressources/bad_maps/wrongmap_hole_map.cub new file mode 100644 index 0000000..06a79e0 --- /dev/null +++ b/ressources/bad_maps/wrongmap_hole_map.cub @@ -0,0 +1,22 @@ +NO ./path_to_the_north_texture +SO ./path_to_the_south_texture +WE ./path_to_the_west_texture +EA ./path_to_the_east_texture + +F 220,100,0 +C 225,30,0 + + 1111111111111111111111111 + 1000000000110000000000001 + 1011000001110000000000001 + 1001000000000000000000001 +111111111011000001110000000000001 +100 00000011000001110111110111111 +11110111111111011100000010001 +11110111111111011101010010001 +11000000110101011100000010001 +10000000000000001100000010001 +10000000000000001101010010001 +11000001110101011111011110N0111 +11110111 1110101 101111010001 +11111111 1111111 111111111111 diff --git a/src/main.c b/src/main.c index 2bd7447..1bcd785 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: tchampio map[i]) + while (map->mapflood[i]) { j = 0; - while (map->map[i][j]) + while (map->mapflood[i][j]) { - if (map->map[i][j] == '1') + if (map->mapflood[i][j] == '1') draw_2d_wall(map->f_color, data, 10, 10 * j, 10 * i); else if (ft_strchr("NSEW", map->map[i][j])) draw_2d_wall(0x00FF0000, data, 10, 10 * j, 10 * i); diff --git a/src/map/map_checker.c b/src/map/map_checker.c index 8f7699e..adb2560 100644 --- a/src/map/map_checker.c +++ b/src/map/map_checker.c @@ -6,7 +6,7 @@ /* By: tchampio mapflood[y][x] == '1') + return ; + if (map->mapflood[y][x] == ' ' || map->mapflood[y][x] == '\n') + map->isvalid = false; + + map->mapflood[y][x] = '1'; + flood_fill(map, x + 1, y); + flood_fill(map, x, y + 1); + flood_fill(map, x - 1, y); + flood_fill(map, x, y - 1); +} + bool check_cubfile(char *file, t_mapdata *map) { int fd; @@ -75,5 +89,8 @@ bool check_cubfile(char *file, t_mapdata *map) if (!check_bare_minimum(map)) return (close(fd), false); map->isvalid = true; + flood_fill(map, map->startx, map->starty); + if (!map->isvalid) + return (close(fd), ft_strlcpy(map->error, "Map has holes!", 16), false); return (true); }