From 1432b9d3d519d427499a3864796b7a5a5d79eea3 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Sun, 2 Feb 2020 19:32:46 +0100 Subject: It moves --- src/ft_key_events.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/ft_key_events.c') diff --git a/src/ft_key_events.c b/src/ft_key_events.c index 580bb17..697670c 100644 --- a/src/ft_key_events.c +++ b/src/ft_key_events.c @@ -16,29 +16,34 @@ #include static int - ft_w_key(void) + ft_w_key(t_cub *clist) { ft_printf("[W]\n"); + clist->plist->pos_y -= 1; + ft_drawmap(clist); return (0); } static int - ft_a_key(void) + ft_a_key(t_cub *clist) { + (void)clist; ft_printf("[A]\n"); return (0); } static int - ft_s_key(void) + ft_s_key(t_cub *clist) { + (void)clist; ft_printf("[S]\n"); return (0); } static int - ft_d_key(void) + ft_d_key(t_cub *clist) { + (void)clist; ft_printf("[D]\n"); return (0); } @@ -46,18 +51,19 @@ static int int ft_key_event(int keycode, void *param) { - int (*fun_ptr[4])(void); + int (*fun_ptr[4])(t_cub*); + const int8_t tmp_code = keycode; fun_ptr[0] = ft_w_key; fun_ptr[1] = ft_a_key; fun_ptr[2] = ft_s_key; fun_ptr[3] = ft_d_key; - ft_printf("Key [%d] pressed\n", keycode); - (keycode == FT_W_KEY) ? (keycode = 0) : 0; - (keycode == FT_A_KEY) ? (keycode = 1) : 0; - (keycode == FT_S_KEY) ? (keycode = 2) : 0; - (keycode == FT_D_KEY) ? (keycode = 3) : 0; - (keycode <= 3) ? ((*fun_ptr[keycode])()) : 0; + ft_printf("Key [%d] pressed\n", tmp_code); + (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; + (keycode <= 3) ? ((*fun_ptr[keycode])((t_cub*)param)) : 0; if (keycode == FT_ESC_KEY) ft_exit(0, ((t_cub*)param)); return (0); -- cgit v1.2.3