diff options
author | Rudy Bousset <rbousset@z2r5p6.le-101.fr> | 2020-02-02 19:32:46 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r5p6.le-101.fr> | 2020-02-02 19:32:46 +0100 |
commit | 1432b9d3d519d427499a3864796b7a5a5d79eea3 (patch) | |
tree | de84496fbda69f82bcc1e27b48712a641ff55726 /src/ft_key_events.c | |
parent | Better color for the player (diff) | |
download | 42-cub3d-1432b9d3d519d427499a3864796b7a5a5d79eea3.tar.gz 42-cub3d-1432b9d3d519d427499a3864796b7a5a5d79eea3.tar.bz2 42-cub3d-1432b9d3d519d427499a3864796b7a5a5d79eea3.tar.xz 42-cub3d-1432b9d3d519d427499a3864796b7a5a5d79eea3.tar.zst 42-cub3d-1432b9d3d519d427499a3864796b7a5a5d79eea3.zip |
It moves
Diffstat (limited to 'src/ft_key_events.c')
-rw-r--r-- | src/ft_key_events.c | 28 |
1 files changed, 17 insertions, 11 deletions
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 <stdlib.h> 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); |