diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_check_map_line.c | 1 | ||||
-rw-r--r-- | src/ft_check_missing.c | 21 | ||||
-rw-r--r-- | src/ft_draw_map.c | 2 | ||||
-rw-r--r-- | src/ft_get_topsp.c | 30 | ||||
-rw-r--r-- | src/ft_init_map.c | 23 |
5 files changed, 66 insertions, 11 deletions
diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index c88e1f5..b9fd636 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -39,6 +39,7 @@ static int8_t } if (line[i] == 'T') clist->mlist.istraps = 1; + ft_get_topsp(line[i], clist); return (0); } diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c index 51c0c23..d01a77f 100644 --- a/src/ft_check_missing.c +++ b/src/ft_check_missing.c @@ -20,7 +20,22 @@ int ft_dprintf(STDERR_FILENO, "Error\n"); ft_dprintf(STDERR_FILENO, "\033[1;31m%s %s\033[0m\n", FT_ERR_MISS_ELEMENT, err); - return (ft_exit(1, clist)); + return (ft_exit(FT_ERR_MISSING, clist)); +} + +static int + ft_check_missing_sprites(t_cub *clist) +{ + int8_t i; + + i = 0; + while ((i + 2) <= clist->mlist.topsp) + { + if (!clist->mlist.sprite_path[i][0]) + return (ft_missing_error(FT_ERR_MISS_SPRITE, clist)); + i++; + } + return (0); } static int @@ -46,7 +61,7 @@ static int return (ft_missing_error(FT_ERR_MISS_NLVL_PATH, clist)); if (clist->mlist.istraps && !clist->mlist.traps_path[0]) return (ft_missing_error(FT_ERR_MISS_TRAP, clist)); - return (0); + return (ft_check_missing_sprites(clist)); } int @@ -60,7 +75,7 @@ int return (ft_missing_error(FT_ERR_MISS_EAST, clist)); else if (!clist->mlist.we_tex_path[0]) return (ft_missing_error(FT_ERR_MISS_WEST, clist)); - else if (!clist->mlist.sprite_path[0]) + else if (!clist->mlist.sprite_path[0][0]) return (ft_missing_error(FT_ERR_MISS_SPRITE, clist)); else if (clist->wlist.x_size == 0 || clist->wlist.y_size == 0) return (ft_missing_error(FT_ERR_MISS_RESOLUTION, clist)); diff --git a/src/ft_draw_map.c b/src/ft_draw_map.c index fc2613b..5d37566 100644 --- a/src/ft_draw_map.c +++ b/src/ft_draw_map.c @@ -55,7 +55,7 @@ void else if (map[y][x] == '2') ft_draw_square(scale + 9 + (x * (scale)), ft_y_offset(clist) - 9 + (y * (scale)), 0x0033ccff, clist); - else if (ft_ischarset("0LNSEWT", map[y][x])) + else if (ft_ischarset(FT_CHRST_MAP_NON_WALL, map[y][x])) ft_draw_square(scale + 9 + (x * (scale)), ft_y_offset(clist) - 9 + (y * (scale)), 0x006afa6a, clist); x++; diff --git a/src/ft_get_topsp.c b/src/ft_get_topsp.c new file mode 100644 index 0000000..ee16714 --- /dev/null +++ b/src/ft_get_topsp.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_check_map_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:28:34 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:37 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stddef.h> +#include <stdint.h> + +void + ft_get_topsp(char c, t_cub *clist) +{ + int8_t x; + + if ((x = ft_strlchr(FT_CHRST_SPRITES, c)) > 0) + { + if ((x + 2) > clist->mlist.topsp) + { + clist->mlist.topsp = x + 2; + } + } +} diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 8f6bb3d..813a795 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -57,12 +57,27 @@ static int8_t } int8_t + ft_init_map_norme(t_map *mlist) +{ + mlist->scale = 0; + mlist->nlx = 0; + mlist->nly = 0; + mlist->sprite_var = 0; + mlist->topsp = 0; + ft_bzero(mlist->sprite_order, 4096); + ft_bzero(mlist->traps_order, 512); + return (0); +} + +int8_t ft_init_map(t_map *mlist) { if (ft_init_map_callocs(mlist) < 0) return (-1); mlist->map[1] = 0; mlist->mcmd_words[1] = 0; + if (ft_calloc_sprites(mlist) < 0) + return (-1); mlist->map_w = 0; mlist->map_h = 0; mlist->mapl_len = 0; @@ -80,11 +95,5 @@ int8_t mlist->sprite_nbr = 0; mlist->traps_nbr = 0; mlist->darklvl = 0; - mlist->scale = 0; - mlist->nlx = 0; - mlist->nly = 0; - mlist->sprite_var = 0; - ft_bzero(mlist->sprite_order, 4096); - ft_bzero(mlist->traps_order, 512); - return (ft_calloc_sprites(mlist)); + return (ft_init_map_norme(mlist)); } |