diff options
Diffstat (limited to '')
-rw-r--r-- | src/ft_key_events.c | 54 |
1 files changed, 11 insertions, 43 deletions
diff --git a/src/ft_key_events.c b/src/ft_key_events.c index 395761e..317715d 100644 --- a/src/ft_key_events.c +++ b/src/ft_key_events.c @@ -15,59 +15,27 @@ #include <stdlib.h> #include <stdint.h> -static uint16_t - ft_set_keycode(const uint16_t tmp_code) -{ - 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; - return (keycode); -} - static void - ft_secure_player_pos(t_player *pl, t_map *ml) + ft_insert_key(uint16_t keycode, t_cub *clist) { - (pl->pos_y < 1) ? (pl->pos_y = 1.1) : 0; - (pl->pos_x < 1) ? (pl->pos_x = 1.1) : 0; - (pl->pos_y > ml->map_h - 1.4) ? (pl->pos_y = ml->map_h - 1.4) : 0; - (pl->pos_x > ml->map_w - 1.4) ? (pl->pos_x = ml->map_w - 1.4) : 0; + uint8_t i; + + i = 0; + while (i < 5 && clist->key_input[i] != keycode && clist->key_input[i] != -1) + i++; + clist->key_input[i] = keycode; } int ft_key_event(int keycode, t_cub *clist) { - int (*fun_ptr[6])(t_cub*); - const uint16_t tmp_code = keycode; + const int32_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; - fun_ptr[4] = ft_left_key; - fun_ptr[5] = ft_right_key; - keycode = ft_set_keycode(tmp_code); - if (keycode <= 5) - { - (*fun_ptr[keycode])(clist); - ft_secure_player_pos(clist->plist, clist->mlist); - ft_draw_scene(clist); - return (0); - } - else if (keycode == FT_ESC_KEY) + keycode = ft_convert_keycode(tmp_code); + if (keycode == FT_ESC_KEY) return (ft_exit(0, (clist))); else if (keycode == FT_F1_KEY || keycode == FT_TAB_KEY) return (ft_f1_key(clist)); + ft_insert_key(keycode, clist); return (0); } |