diff options
Diffstat (limited to '')
-rw-r--r-- | src/ft_key_loop.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index d40de34..45ed379 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -12,6 +12,7 @@ #include <libft.h> #include <cub3d.h> +#include <mlx.h> #include <stdint.h> #include <stddef.h> @@ -26,7 +27,7 @@ static uint64_t return (pl->pos_x - (pl->dir_y * FT_COLL_MULT)); else if (key == 3) return (pl->pos_x - (pl->dir_x * (FT_COLL_MULT / 2))); - return (1); + return ((uint64_t)pl->pos_x); } static uint64_t @@ -40,7 +41,7 @@ static uint64_t return (pl->pos_y - (pl->dir_x * FT_COLL_MULT)); else if (key == 3) return (pl->pos_y + (pl->dir_y * (FT_COLL_MULT / 2))); - return (1); + return ((uint64_t)pl->pos_y); } static void @@ -53,12 +54,20 @@ static void pl = &cl->plist; x = ft_find_x(key, pl); y = ft_find_y(key, pl); - if (ft_ischarset(FT_CHRST_COLLISION, cl->mlist.map[y][x]) || - cl->mlist.map[y][x] == '\0') + if (cl->mlist.map[y][x] == 'T') { - pl->pos_y = old_y; - pl->pos_x = old_x; + pl->pos_x = old_x + ((old_x - x) / 3); + pl->pos_y = old_y + ((old_y - y) / 3); + ft_suffer_animation(cl); + x = ft_find_x(key, pl); + y = ft_find_y(key, pl); } + if (ft_ischarset(FT_CHRST_COLLISION, cl->mlist.map[(uint64_t)old_y][x]) || + cl->mlist.map[(uint64_t)old_y][x] == '\0') + pl->pos_x = old_x; + if (ft_ischarset(FT_CHRST_COLLISION, cl->mlist.map[y][(uint64_t)old_x]) || + cl->mlist.map[y][(uint64_t)old_x] == '\0') + pl->pos_y = old_y; } int @@ -75,14 +84,16 @@ int ft_collision(old_y, old_x, cl->key_input[i], cl); if (cl->mlist.isnlvl) { - if (ft_warp_level(cl) < 0) - return (ft_exit(FT_RET_FAILED_STRUCTS, cl)); + if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx && + (uint32_t)cl->plist.pos_y == cl->mlist.nly) + { + return ((ft_warp_level(cl) < 0) ? + (ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0)); + } } i++; } if (cl->key_input[0] != -1) - { ft_draw_scene(cl); - } return (0); } |