diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | inc/cub3d.h | 2 | ||||
-rw-r--r-- | src/ft_extra_keys.c | 39 | ||||
-rw-r--r-- | src/ft_key_events.c | 13 |
4 files changed, 52 insertions, 4 deletions
@@ -88,6 +88,8 @@ ifneq (${OS}, Darwin) CDEFS += -DFT_S_KEY=115 CDEFS += -DFT_D_KEY=100 CDEFS += -DFT_F1_KEY=65470 + CDEFS += -DFT_L_ARR_KEY=65361 + CDEFS += -DFT_R_ARR_KEY=65363 CDEFS += -DFT_ESC_KEY=65307 endif #--------------------------------------------------------------------------------------------------# diff --git a/inc/cub3d.h b/inc/cub3d.h index a0e48fc..60c9bb1 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -95,5 +95,7 @@ int8_t ft_draw_verline(t_cub *cl, int32_t x, int32_t y1, void ft_castray(t_cub *cl); void ft_draw_map(char **map, t_cub *clist); int8_t ft_f1_key(t_cub *clist); +int8_t ft_left_key(t_cub *clist); +int8_t ft_right_key(t_cub *clist); # endif diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c index 5bbb4b4..c920b48 100644 --- a/src/ft_extra_keys.c +++ b/src/ft_extra_keys.c @@ -1,5 +1,44 @@ #include <cub3d.h> #include <stdint.h> +#include <math.h> + +int8_t + ft_left_key(t_cub *clist) +{ + t_player *pl; + float sav_dir_x; + float sav_plane_x; + float rot_speed; + + pl = clist->plist; + rot_speed = 0.3; + sav_dir_x = pl->dir_x; + pl->dir_x = pl->dir_x * cos(rot_speed) - pl->dir_y * sin(rot_speed); + pl->dir_y = sav_dir_x * sin(rot_speed) + pl->dir_y * cos(rot_speed); + sav_plane_x = pl->plane_x; + pl->plane_x = pl->plane_x * cos(rot_speed) - pl->plane_y * sin(rot_speed); + pl->plane_y = sav_plane_x * sin(rot_speed) + pl->plane_y * cos(rot_speed); + return (0); +} + +int8_t + ft_right_key(t_cub *clist) +{ + t_player *pl; + float sav_dir_x; + float sav_plane_x; + float rot_speed; + + pl = clist->plist; + rot_speed = 0.3; + sav_dir_x = pl->dir_x; + pl->dir_x = pl->dir_x * cos(-rot_speed) - pl->dir_y * sin(-rot_speed); + pl->dir_y = sav_dir_x * sin(-rot_speed) + pl->dir_y * cos(-rot_speed); + sav_plane_x = pl->plane_x; + pl->plane_x = pl->plane_x * cos(-rot_speed) - pl->plane_y * sin(-rot_speed); + pl->plane_y = sav_plane_x * sin(-rot_speed) + pl->plane_y * cos(-rot_speed); + return (0); +} int8_t ft_f1_key(t_cub *clist) diff --git a/src/ft_key_events.c b/src/ft_key_events.c index da416fa..2c189ad 100644 --- a/src/ft_key_events.c +++ b/src/ft_key_events.c @@ -61,23 +61,28 @@ int { t_player *pl; t_map *ml; - int8_t (*fun_ptr[4])(t_cub*); + int8_t (*fun_ptr[6])(t_cub*); const uint16_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; 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 == 3) ? (keycode = INT16_MAX) : 0; - (tmp_code == 4) ? (keycode = INT16_MAX) : 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 <= 3) + if (keycode <= 5) { (*fun_ptr[keycode])(clist); (pl->pos_y < 1) ? (pl->pos_y = 1.1) : 0; |