diff options
author | Rudy Bousset <rbousset@z2r5p2.le-101.fr> | 2020-02-28 20:36:49 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r5p2.le-101.fr> | 2020-02-28 20:36:49 +0100 |
commit | fc792e8616d54defb50d26ed65b99cf91c18fe39 (patch) | |
tree | d775f0c586c136da0a9400c195bd4374811f99e4 /src | |
parent | L is now crapaud and you can pass through :^) (diff) | |
download | 42-cub3d-fc792e8616d54defb50d26ed65b99cf91c18fe39.tar.gz 42-cub3d-fc792e8616d54defb50d26ed65b99cf91c18fe39.tar.bz2 42-cub3d-fc792e8616d54defb50d26ed65b99cf91c18fe39.tar.xz 42-cub3d-fc792e8616d54defb50d26ed65b99cf91c18fe39.tar.zst 42-cub3d-fc792e8616d54defb50d26ed65b99cf91c18fe39.zip |
GNL fix
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_key_loop.c | 7 | ||||
-rw-r--r-- | src/ft_parse_map.c | 2 | ||||
-rw-r--r-- | src/ft_warp_level.c | 40 |
3 files changed, 46 insertions, 3 deletions
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index bc7f932..75aec65 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -40,8 +40,11 @@ int { cl->key_ptr[cl->key_input[i]](cl); ft_collision(old_y, old_x, cl->plist, cl->mlist); - /* if (cl->mlist->isnlvl) */ - /* ft_change_level(cl); */ + if (cl->mlist->isnlvl) + { + if (ft_warp_level(cl) < 0) + return (ft_exit(RET_FAILED_STRUCTS, cl)); + } i++; } if (cl->key_input[0] != -1) diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 2b5265d..400bdd4 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -75,7 +75,7 @@ static void { ft_dprintf(STDERR_FILENO, "Error\n"); ft_dprintf(STDERR_FILENO, "\033[31;1mNo map\033[0m\n"); - ft_exit(5, clist); + ft_exit(RET_NO_MAP, clist); } void diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c new file mode 100644 index 0000000..03302bd --- /dev/null +++ b/src/ft_warp_level.c @@ -0,0 +1,40 @@ +#include <libft.h> +#include <cub3d.h> +#include <stdlib.h> +#include <stdint.h> + +static void + ft_del_map(t_map *ml) +{ + ft_memdel((void**)&ml->no_tex_path); + 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_memdel((void**)&ml->nl_tex_path); + ft_memdel((void**)&ml->nlevel_path); + ft_memdel((void**)&ml->mapl); + ft_free_words(ml->map); + ft_memdel((void**)&ml); +} + +int8_t + ft_warp_level(t_cub *cl) +{ + char *next_path; + + if ((uint32_t)cl->plist->pos_x == cl->mlist->nlx + && (uint32_t)cl->plist->pos_y == cl->mlist->nly) + { + if (!(next_path = (char *)malloc + ((ft_strlen(cl->mlist->nlevel_path) + 1) * sizeof(char)))) + return (-1); + ft_sprintf(next_path, "%s", cl->mlist->nlevel_path); + ft_del_map(cl->mlist); + if (!(cl->mlist = ft_init_map())) + return (-1); + ft_parse_map(next_path, cl); + ft_memdel((void**)&next_path); + } + return (0); +} |