diff options
-rw-r--r-- | inc/cub3d_defines.h | 2 | ||||
-rw-r--r-- | src/ft_convert_keycode.c | 25 | ||||
-rw-r--r-- | src/ft_death_hooks.c | 60 | ||||
-rw-r--r-- | src/ft_death_screen.c | 5 | ||||
-rw-r--r-- | src/ft_suffer_animation.c | 2 | ||||
-rw-r--r-- | src/ft_warp_level.c | 4 |
6 files changed, 74 insertions, 24 deletions
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index 5f368f3..c931b2d 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -67,6 +67,7 @@ enum # define FT_F1_KEY 122 # define FT_TAB_KEY 48 # define FT_ESC_KEY 53 +/* TODO macOS return key */ # else # define FT_W_KEY 119 # define FT_A_KEY 97 @@ -77,6 +78,7 @@ enum # define FT_TAB_KEY 65289 # define FT_F1_KEY 65470 # define FT_ESC_KEY 65307 +# define FT_RET_KEY 65293 # endif /* diff --git a/src/ft_convert_keycode.c b/src/ft_convert_keycode.c index 5a037c5..899dae9 100644 --- a/src/ft_convert_keycode.c +++ b/src/ft_convert_keycode.c @@ -19,17 +19,18 @@ int32_t uint16_t keycode; keycode = UINT16_MAX; - (tmp_code == FT_W_KEY) ? (keycode = 0) : 0; - (tmp_code == FT_A_KEY) ? (keycode = 1) : 0; - (tmp_code == FT_S_KEY) ? (keycode = 2) : 0; - (tmp_code == FT_D_KEY) ? (keycode = 3) : 0; - (tmp_code == FT_L_ARR_KEY) ? (keycode = 4) : 0; - (tmp_code == FT_R_ARR_KEY) ? (keycode = 5) : 0; - (tmp_code == 3) ? (keycode = UINT16_MAX) : 0; - (tmp_code == 4) ? (keycode = UINT16_MAX) : 0; - (tmp_code == 5) ? (keycode = UINT16_MAX) : 0; - (tmp_code == FT_ESC_KEY) ? (keycode = FT_ESC_KEY) : 0; - (tmp_code == FT_F1_KEY) ? (keycode = FT_F1_KEY) : 0; - (tmp_code == FT_TAB_KEY) ? (keycode = FT_TAB_KEY) : 0; + keycode = (tmp_code == FT_W_KEY) ? (0) : (keycode); + keycode = (tmp_code == FT_A_KEY) ? (1) : (keycode); + keycode = (tmp_code == FT_S_KEY) ? (2) : (keycode); + keycode = (tmp_code == FT_D_KEY) ? (3) : (keycode); + keycode = (tmp_code == FT_L_ARR_KEY) ? (4) : (keycode); + keycode = (tmp_code == FT_R_ARR_KEY) ? (5) : (keycode); + keycode = (tmp_code == 3) ? (UINT16_MAX) : (keycode); + keycode = (tmp_code == 4) ? (UINT16_MAX) : (keycode); + keycode = (tmp_code == 5) ? (UINT16_MAX) : (keycode); + keycode = (tmp_code == FT_ESC_KEY) ? (FT_ESC_KEY) : (keycode); + keycode = (tmp_code == FT_F1_KEY) ? (FT_F1_KEY) : (keycode); + keycode = (tmp_code == FT_TAB_KEY) ? (FT_TAB_KEY) : (keycode); + keycode = (tmp_code == FT_RET_KEY) ? (FT_RET_KEY) : (keycode); return (keycode); } diff --git a/src/ft_death_hooks.c b/src/ft_death_hooks.c index ccf7741..5482e75 100644 --- a/src/ft_death_hooks.c +++ b/src/ft_death_hooks.c @@ -13,14 +13,62 @@ #include <libft.h> #include <cub3d.h> #include <mlx.h> +#include <unistd.h> + +static int + ft_death_key_event(int keycode, t_cub *clist) +{ + const int32_t tmp_code = keycode; + + keycode = ft_convert_keycode(tmp_code); + if (keycode == FT_ESC_KEY) + return (ft_exit(0, (clist))); + if (keycode == FT_RET_KEY) + { + if (ft_warp_level(clist->mlist.filename, clist) < 0) + return (ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist)); + ft_draw_scene(clist); + ft_hooks_and_loops(&clist->wlist, clist); + return (0); + } + return (0); +} + +static int + ft_death_key_loop(t_cub *cl) +{ + (void)cl; + return (0); +/* uint8_t i; */ +/* const float old_y = cl->plist.pos_y; */ +/* const float old_x = cl->plist.pos_x; */ + +/* i = 0; */ +/* while (i < 5 && cl->key_input[i] != -1 && cl->key_input[i] <= 5) */ +/* { */ +/* cl->key_ptr[cl->key_input[i]](cl); */ +/* ft_collision(old_y, old_x, cl->key_input[i], cl); */ +/* if (cl->mlist.isnlvl) */ +/* { */ +/* if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx && */ +/* (uint32_t)cl->plist.pos_y == cl->mlist.nly) */ +/* { */ +/* ft_sfx_new_level(cl); */ +/* return ((ft_warp_level(cl->mlist.nlevel_path, cl) < 0) ? */ +/* (ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0)); */ +/* } */ +/* } */ +/* i++; */ +/* } */ +/* if (cl->key_input[0] != -1) */ +/* ft_draw_scene(cl); */ +/* return (0); */ +} void ft_death_hooks(t_win *wl, t_cub *cl) { - /* mlx_hook(wl->winptr, 2, (1L << 0), ft_key_event, cl); */ - /* mlx_hook(wl->winptr, 3, (1L << 1), ft_key_release, cl); */ - /* mlx_loop_hook(wl->wlx, ft_key_loop, cl); */ - /* mlx_hook(wl->winptr, 17, 0L, ft_click_close, cl); */ - (void)cl; - (void)wl; + mlx_hook(wl->winptr, 2, (1L << 0), ft_death_key_event, cl); + mlx_loop_hook(wl->wlx, ft_death_key_loop, cl); + mlx_loop(wl->wlx); } diff --git a/src/ft_death_screen.c b/src/ft_death_screen.c index 7afff98..16d75d5 100644 --- a/src/ft_death_screen.c +++ b/src/ft_death_screen.c @@ -71,8 +71,7 @@ void ft_calc_death_screen(cl); mlx_put_image_to_window(cl->wlist.wlx, cl->wlist.winptr, cl->img.img, 0, 0); + /* mlx_destroy_image(cl->wlist.wlx, cl->death_screen.img); */ + /* mlx_destroy_image(cl->wlist.wlx, cl->img.img); */ ft_death_hooks(&cl->wlist, cl); - sleep(8); - mlx_destroy_image(cl->wlist.wlx, cl->img.img); - mlx_destroy_image(cl->wlist.wlx, cl->death_screen.img); } diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index c5187f9..d08fa54 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -40,7 +40,6 @@ void cl->plist.life -= 20; if (cl->plist.life <= 0) { - /* ft_warp_level(cl->mlist.filename, cl); */ ft_sfx_death(cl); ft_death_screen(cl); } @@ -73,7 +72,6 @@ void cl->plist.life -= 20; if (cl->plist.life <= 0) { - /* ft_warp_level(cl->mlist.filename, cl); */ ft_sfx_death(cl); ft_death_screen(cl); } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index f4a978d..69b7b78 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -52,11 +52,13 @@ static void cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); i = -1; - while (++i <= 5) + while (++i < 5) { mlx_destroy_image(cl->wlist.wlx, cl->tlist[i].img); cl->tlist[i].img = NULL; } + if (cl->mlist.isnlvl && cl->tlist[5].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[5].img); if (cl->mlist.isftex && cl->tlist[6].img) mlx_destroy_image(cl->wlist.wlx, cl->tlist[6].img); if (cl->mlist.isctex && cl->tlist[7].img) |