diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | inc/cub3d.h | 11 | ||||
-rw-r--r-- | inc/cub3d_defines.h | 25 | ||||
-rw-r--r-- | libft/src/get_next_line.c | 16 | ||||
-rw-r--r-- | map/lvl_one.cub | 4 | ||||
-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 |
8 files changed, 83 insertions, 23 deletions
@@ -65,6 +65,7 @@ SRCS_NAME += ft_key_loop.c SRCS_NAME += ft_draw_hud.c SRCS_NAME += ft_music.c SRCS_NAME += ft_draw_sprite.c +SRCS_NAME += ft_warp_level.c #--------------------------------------------------------------------------------------------------# SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME}) #--------------------------------------------------------------------------------------------------# diff --git a/inc/cub3d.h b/inc/cub3d.h index d72094c..4f28a84 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -18,16 +18,6 @@ #include <stddef.h> #include <stdint.h> -/* -** ret vals: -** 1: no argv[1] -** 2: failed structs init -** 3: failed mlx init -** 4: map error -** 5: no map -** 6: read error -*/ - int8_t ft_init_cub3d(t_cub **clist); t_map *ft_init_map(void); void ft_wall_tex_init(t_cub *clist); @@ -94,5 +84,6 @@ void ft_draw_life_bar(size_t map_w, t_cub *cl); void ft_music(t_cub *cl); void ft_draw_sprite(t_cub *cl, int i); +int8_t ft_warp_level(t_cub *cl); # endif diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index 5a8112b..8b15838 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -14,6 +14,31 @@ # define CUB3D_DEFINES_H /* +** ====== RETURN VALUES ====== +*/ + +enum retvals +{ + RET_FINE, + RET_NO_ARGV, + RET_FAILED_STRUCTS, + RET_FAILED_MLX, + RET_MAP_ERROR, + RET_NO_MAP, + RET_READ_ERROR +}; + +/* +** ret vals: +** 1: no argv[1] +** 2: failed structs init +** 3: failed mlx init +** 4: map error +** 5: no map +** 6: read error +*/ + +/* ** ====== KEYS ====== */ diff --git a/libft/src/get_next_line.c b/libft/src/get_next_line.c index 64ca7fc..4ace77a 100644 --- a/libft/src/get_next_line.c +++ b/libft/src/get_next_line.c @@ -21,7 +21,7 @@ static uint8_t size_t i; i = 0; - while (str && str[i]) + while (str[i] != '\0') { if (str[i] == '\n') return (1); @@ -56,12 +56,12 @@ static int buff[ret] = '\0'; tmp = *str; *str = ft_strjoin(tmp, buff); - free(tmp); + ft_memdel((void**)&tmp); } if (ret < 0) { - free(*str); - free(buff); + ft_memdel((void**)&str); + ft_memdel((void**)&buff); return (-1); } free(buff); @@ -75,7 +75,7 @@ static int *str = ft_nstr(0); if (fd < 0 || !line || BUFFER_SIZE <= 0) { - free(*str); + ft_memdel((void**)&str); return (-1); } return (0); @@ -102,10 +102,10 @@ int if (ret == 0 && ((str == NULL || str[0] == '\0') || !ft_linecheck(str))) { i = tmp[i]; - free(tmp); - tmp = NULL; + if (i == '\n') + ft_memdel((void**)&tmp); return (i == '\n'); } - free(tmp); + ft_memdel((void**)&tmp); return (1); } diff --git a/map/lvl_one.cub b/map/lvl_one.cub index 8ded9bd..ecc6955 100644 --- a/map/lvl_one.cub +++ b/map/lvl_one.cub @@ -13,7 +13,7 @@ L ./map/lvl_two.cub LT ./media/img/crapaud.xpm 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 L 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 -1 E 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 +1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 +1 E 0 0 0 L 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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); +} |