From 88cd7098410c7ab80baecc6c2a4d5da99e10162f Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Thu, 12 Mar 2020 17:48:43 +0100 Subject: kk --- src/ft_exit.c | 2 +- src/ft_get_sprite.c | 57 +++++++++++++++++++++++++++++++++++++++++++++------- src/ft_init_funptr.c | 9 ++++++++- src/ft_init_map.c | 18 ++++++++++++++++- src/ft_select_get.c | 8 ++++++-- src/ft_tex_init.c | 29 +++++++++++++------------- src/ft_warp_level.c | 2 +- 7 files changed, 97 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/ft_exit.c b/src/ft_exit.c index e0093da..7056114 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -27,7 +27,7 @@ static void ft_memdel((void**)&clist->mlist.so_tex_path); ft_memdel((void**)&clist->mlist.ea_tex_path); ft_memdel((void**)&clist->mlist.we_tex_path); - ft_memdel((void**)&clist->mlist.sprite_path); + ft_free_words(clist->mlist.sprite_path); ft_memdel((void**)&clist->mlist.nl_tex_path); ft_memdel((void**)&clist->mlist.fl_tex_path); ft_memdel((void**)&clist->mlist.ce_tex_path); diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index a158940..902ab87 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -75,28 +75,71 @@ void } } +static int8_t + ft_get_sprite_id(char *word) +{ + int8_t ret; + char ref[8][3]; + + ft_sprintf(ref[0], "S"); + ft_sprintf(ref[1], "S2"); + ft_sprintf(ref[2], "S3"); + ft_sprintf(ref[3], "S4"); + ft_sprintf(ref[4], "S5"); + ft_sprintf(ref[5], "S6"); + ft_sprintf(ref[6], "S7"); + ft_sprintf(ref[7], "S8"); + ret = 0; + while (ft_strncmp(word, ref[ret], 3) && ref[ret][0]) + ret++; + return (ret); +} + +static int8_t + ft_check_sprite_amount(int8_t id, t_cub *clist) +{ + int8_t i; + + i = 0; + while (i < id) + { + if (!clist->mlist.sprite_path[i][0]) + return (-1); + i++; + } + return (0); +} + int8_t ft_get_sprite(char **words, t_cub *clist) { + int8_t id; + if (!(*words) || !words[1] || words[2]) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ARGS); + ft_sprintf(clist->errmsg, FT_ERR_ARGS); return (-1); } if (ft_check_ext(*(words + 1), ".xpm") < 0) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM); + ft_sprintf(clist->errmsg, FT_ERR_NOT_A_XPM); + return (-1); + } + id = ft_get_sprite_id(words[0]); + if (ft_check_sprite_amount(id, clist) < 0) + { + ft_sprintf(clist->errmsg, FT_ERR_SPRITE_DUMB); return (-1); } - ft_memdel((void**)&clist->mlist.sprite_path); - if (!(clist->mlist.sprite_path = ft_strdup(*(words + 1)))) + ft_memdel((void**)&clist->mlist.sprite_path[id]); + if (!(clist->mlist.sprite_path[id] = ft_strdup(*(words + 1)))) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE); + ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE); return (-1); } - if (ft_check_not_found(clist->mlist.sprite_path) < 0) + if (ft_check_not_found(clist->mlist.sprite_path[id]) < 0) { - ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_SP); + ft_sprintf(clist->errmsg, FT_ERR_RD_SP); return (-1); } return (0); diff --git a/src/ft_init_funptr.c b/src/ft_init_funptr.c index c299336..98fae3c 100644 --- a/src/ft_init_funptr.c +++ b/src/ft_init_funptr.c @@ -30,7 +30,14 @@ void ft_sprintf(clist->ref[11], "SH"); ft_sprintf(clist->ref[12], "SB"); ft_sprintf(clist->ref[13], "T"); - ft_bzero(clist->ref[14], 3); + ft_sprintf(clist->ref[14], "S2"); + ft_sprintf(clist->ref[15], "S3"); + ft_sprintf(clist->ref[16], "S4"); + ft_sprintf(clist->ref[17], "S5"); + ft_sprintf(clist->ref[18], "S6"); + ft_sprintf(clist->ref[19], "S7"); + ft_sprintf(clist->ref[20], "S8"); + ft_bzero(clist->ref[21], 3); } void diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 867a5b0..1462ef3 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -23,7 +23,7 @@ static int8_t !(mlist->so_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->ea_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->we_tex_path = (char*)ft_calloc(1, sizeof(char))) || - !(mlist->sprite_path = (char*)ft_calloc(1, sizeof(char))) || + !(mlist->sprite_path = (char**)ft_calloc(9, sizeof(char*))) || !(mlist->nl_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->fl_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->ce_tex_path = (char*)ft_calloc(1, sizeof(char))) || @@ -41,6 +41,21 @@ static int8_t return (0); } +static int8_t + ft_calloc_sprites(t_map *mlist) +{ + uint8_t i; + + i = 0; + while (i < 9) + { + if (!(mlist->sprite_path[i] = (char*)ft_calloc(1, sizeof(char)))) + return (-1); + i++; + } + return (0); +} + int8_t ft_init_map(t_map *mlist) { @@ -68,5 +83,6 @@ int8_t mlist->scale = 0; mlist->nlx = 0; mlist->nly = 0; + ft_calloc_sprites(mlist); return (0); } diff --git a/src/ft_select_get.c b/src/ft_select_get.c index f748721..745b26d 100644 --- a/src/ft_select_get.c +++ b/src/ft_select_get.c @@ -31,7 +31,7 @@ static int8_t return (-1); else if (ret == 4 && (clist->mlist.we_tex_path[0])) return (-1); - else if (ret == 5 && (clist->mlist.sprite_path[0])) + else if (ret == 5 && (clist->mlist.sprite_path[0][0])) return (-1); else if (ret == 6 && ((clist->f_rgb.r != -1) || (clist->f_rgb.g != -1) || (clist->f_rgb.b != -1))) @@ -57,6 +57,8 @@ static int8_t return (-1); if (ret == 13 && (clist->mlist.traps_path[0])) return (-1); + if (ret > 13 && ret < 21 && (clist->mlist.sprite_path[ret - 13][0])) + return (-1); return (ret); } @@ -70,10 +72,12 @@ static int8_t ret = 0; while (ft_strncmp(words[0], clist->ref[ret], 3) && clist->ref[ret][0]) ret++; - if (ret == 14) + if (ret == 21) ret = FT_PARSE_END_RET; ret = ft_check_exists(ret, clist); ret = ft_check_exists_two(ret, clist); + if (ret > 13 && ret < 21) + ret = 5; return (ret); } diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 0290a0c..cae07bd 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -38,18 +38,17 @@ static void ft_next_sprite_init(t_cub *cl) { - uint16_t i; + uint8_t i; - i = 8; - cl->tlist[i].img = mlx_xpm_file_to_image(cl->wlist.wlx, - "./media/img/larry.xpm", &cl->tlist[i].img_w, &cl->tlist[i].img_h); - cl->tlist[i].ptr = mlx_get_data_addr(cl->tlist[i].img, - &cl->tlist[i].bpp, &cl->tlist[i].sizeline, &cl->tlist[i].endian); - i++; - cl->tlist[i].img = mlx_xpm_file_to_image(cl->wlist.wlx, - "./media/img/crapaud.xpm", &cl->tlist[i].img_w, &cl->tlist[i].img_h); - cl->tlist[i].ptr = mlx_get_data_addr(cl->tlist[i].img, - &cl->tlist[i].bpp, &cl->tlist[i].sizeline, &cl->tlist[i].endian); + i = 1; + while (cl->mlist.sprite_path[i][0]) + { + cl->tlist[i + 7].img = mlx_xpm_file_to_image(cl->wlist.wlx, + cl->mlist.sprite_path[i], &cl->tlist[i + 7].img_w, &cl->tlist[i + 7].img_h); + cl->tlist[i + 7].ptr = mlx_get_data_addr(cl->tlist[i + 7].img, + &cl->tlist[i + 7].bpp, &cl->tlist[i + 7].sizeline, &cl->tlist[i + 7].endian); + i++; + } } static void @@ -71,9 +70,9 @@ static void } cl->walltexgood = 1; if (cl->mlist.sprite_var > 1) - { - ft_next_sprite_init(cl); - } + { + ft_next_sprite_init(cl); + } } static void @@ -123,7 +122,7 @@ void cl->tlist[3].ptr = mlx_get_data_addr(cl->tlist[3].img, &cl->tlist[3].bpp, &cl->tlist[3].sizeline, &cl->tlist[3].endian); cl->tlist[4].img = mlx_xpm_file_to_image(cl->wlist.wlx, - cl->mlist.sprite_path, &cl->tlist[4].img_w, &cl->tlist[4].img_h); + cl->mlist.sprite_path[0], &cl->tlist[4].img_w, &cl->tlist[4].img_h); cl->tlist[4].ptr = mlx_get_data_addr(cl->tlist[4].img, &cl->tlist[4].bpp, &cl->tlist[4].sizeline, &cl->tlist[4].endian); ft_wall_tex_init_norme(cl); diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index faaf322..5b1a821 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -28,7 +28,7 @@ static void ft_memdel((void**)&ml->so_tex_path); ft_memdel((void**)&ml->ea_tex_path); ft_memdel((void**)&ml->we_tex_path); - ft_memdel((void**)&ml->sprite_path); + ft_free_words(ml->sprite_path); ft_memdel((void**)&ml->nl_tex_path); ft_memdel((void**)&ml->fl_tex_path); ft_memdel((void**)&ml->ce_tex_path); -- cgit v1.2.3