diff options
author | Rudy Bousset <rbousset@z2r5p6.le-101.fr> | 2020-02-14 18:47:19 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r5p6.le-101.fr> | 2020-02-14 18:47:19 +0100 |
commit | 8e6080e73661cc8747b21b1153e4336796575cf7 (patch) | |
tree | 2eaec487a73f9df1a69627cff23c42746f1b296e /src/ft_key_events.c | |
parent | Added turn around keys (diff) | |
download | 42-cub3d-8e6080e73661cc8747b21b1153e4336796575cf7.tar.gz 42-cub3d-8e6080e73661cc8747b21b1153e4336796575cf7.tar.bz2 42-cub3d-8e6080e73661cc8747b21b1153e4336796575cf7.tar.xz 42-cub3d-8e6080e73661cc8747b21b1153e4336796575cf7.tar.zst 42-cub3d-8e6080e73661cc8747b21b1153e4336796575cf7.zip |
Norme is bav
Diffstat (limited to 'src/ft_key_events.c')
-rw-r--r-- | src/ft_key_events.c | 95 |
1 files changed, 33 insertions, 62 deletions
diff --git a/src/ft_key_events.c b/src/ft_key_events.c index 2c189ad..e08e3d0 100644 --- a/src/ft_key_events.c +++ b/src/ft_key_events.c @@ -1,67 +1,51 @@ /* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_key_events.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2020/02/02 17:19:30 by rbousset #+# ## ## #+# */ -/* Updated: 2020/02/02 17:19:30 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ +/* */ +/* ::: :::::::: */ +/* ft_key_events.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:28:55 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:55 by rbousset ### ########lyon.fr */ +/* */ /* ************************************************************************** */ #include <libft.h> #include <cub3d.h> #include <stdlib.h> +#include <stdint.h> -static int8_t - ft_w_key(t_cub *clist) +static uint16_t + ft_set_keycode(const uint16_t tmp_code) { - t_player *pl; + uint16_t keycode; - pl = clist->plist; - pl->pos_y += 0.2 * (-1); /* pl->mult; */ - pl->pos_x += 0; - return (0); -} - -static int8_t - ft_a_key(t_cub *clist) -{ - t_player *pl; - - pl = clist->plist; - pl->pos_x -= 0.2; - return (0); -} - -static int8_t - ft_s_key(t_cub *clist) -{ - t_player *pl; - - pl = clist->plist; - pl->pos_y += 0.2; - return (0); + 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; + return (keycode); } -static int8_t - ft_d_key(t_cub *clist) +static void + ft_secure_player_pos(t_player *pl, t_map *ml) { - t_player *pl; - - pl = clist->plist; - pl->pos_x += 0.2; - return (0); + (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; } int ft_key_event(int keycode, t_cub *clist) { - t_player *pl; - t_map *ml; - int8_t (*fun_ptr[6])(t_cub*); + int (*fun_ptr[6])(t_cub*); const uint16_t tmp_code = keycode; fun_ptr[0] = ft_w_key; @@ -70,25 +54,12 @@ int fun_ptr[3] = ft_d_key; fun_ptr[4] = ft_left_key; fun_ptr[5] = ft_right_key; + keycode = ft_set_keycode(tmp_code); 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; - (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; - pl = clist->plist; - ml = clist->mlist; if (keycode <= 5) { (*fun_ptr[keycode])(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; + ft_secure_player_pos(clist->plist, clist->mlist); ft_draw_scene(clist); return (0); } |