diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-14 18:55:43 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-14 18:55:43 +0100 |
commit | caa6cc5bc81278f446d852f73422af36c4c846c5 (patch) | |
tree | 58bcdba2ef530c6c1ab423209964b1b4e8877135 /src/ft_death_hooks.c | |
parent | Can't death hook (diff) | |
download | 42-cub3d-caa6cc5bc81278f446d852f73422af36c4c846c5.tar.gz 42-cub3d-caa6cc5bc81278f446d852f73422af36c4c846c5.tar.bz2 42-cub3d-caa6cc5bc81278f446d852f73422af36c4c846c5.tar.xz 42-cub3d-caa6cc5bc81278f446d852f73422af36c4c846c5.tar.zst 42-cub3d-caa6cc5bc81278f446d852f73422af36c4c846c5.zip |
Perfect but leaks
Diffstat (limited to 'src/ft_death_hooks.c')
-rw-r--r-- | src/ft_death_hooks.c | 60 |
1 files changed, 54 insertions, 6 deletions
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); } |