diff --git a/includes/cub3d.h b/includes/cub3d.h index 933e0a9..47f7b11 100644 --- a/includes/cub3d.h +++ b/includes/cub3d.h @@ -6,7 +6,7 @@ /* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/15 00:19:44 by tsuchen #+# #+# */ -/* Updated: 2024/09/04 09:11:56 by tsuchen ### ########.fr */ +/* Updated: 2024/09/04 09:44:06 by tsuchen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -77,10 +77,12 @@ typedef enum e_keys ARROW_UP = 65362, ARROW_DOWN = 65364, ESC_KEY = 65307, + SPACE_KEY = 32, W_KEY = 119, A_KEY = 97, S_KEY = 115, D_KEY = 100, + R_KEY = 114, M1 = 65307, P_KEY = 112, } t_keys; @@ -142,6 +144,7 @@ int key_events(int keycode, t_data *data); int mouse_move(int x, int y, t_data *data); void move_check(t_vec *step, t_data *data, int add_or_sub); int mouse_press(int button, int x, int y, t_data *data); +void interact_door(t_data *data); /* color utils*/ int create_trgb(int t, int r, int g, int b); int get_color(int trgb, char index); diff --git a/srcs/events/key_events.c b/srcs/events/key_events.c index f3bf8fd..a1f81e3 100644 --- a/srcs/events/key_events.c +++ b/srcs/events/key_events.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* key_events.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jteissie +#+ +:+ +#+ */ +/* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/27 18:40:50 by jteissie #+# #+# */ -/* Updated: 2024/09/02 17:28:10 by jteissie ### ########.fr */ +/* Updated: 2024/09/04 09:48:55 by tsuchen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,6 +54,12 @@ static void key_move_camera(t_data *data, t_rot dir) return ; } +static void turn_around(t_data *data) +{ + vec_mirror(&data->p_cam); + vec_mirror(&data->p_dir); +} + static void pause_game(t_data *data) { if (data->pause == TRUE) @@ -78,6 +84,10 @@ int key_events(int keycode, t_data *data) move_player(data, LEFT); else if (keycode == D_KEY && data->pause == FALSE) move_player(data, RIGHT); + else if (keycode == R_KEY && data->pause == FALSE) + turn_around(data); + else if (keycode == SPACE_KEY && data->pause == FALSE) + interact_door(data); else if (keycode == ESC_KEY) cleanup(data); return (SUCCESS); diff --git a/srcs/events/mouse_events.c b/srcs/events/mouse_events.c index 539991f..0a33799 100644 --- a/srcs/events/mouse_events.c +++ b/srcs/events/mouse_events.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* mouse_events.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jteissie +#+ +:+ +#+ */ +/* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/02 11:59:13 by jteissie #+# #+# */ -/* Updated: 2024/09/02 17:25:01 by jteissie ### ########.fr */ +/* Updated: 2024/09/04 09:38:09 by tsuchen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,7 +51,7 @@ static void change_door_state(t_data *data, t_vec *p_ray) data->map[door_x][door_y] = 'D'; } -static void interact_door(t_data *data) +void interact_door(t_data *data) { t_vec p_ray; double dist; diff --git a/srcs/main.c b/srcs/main.c index 13b98bc..84fa48c 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/15 12:03:33 by tsuchen #+# #+# */ -/* Updated: 2024/09/04 09:27:55 by tsuchen ### ########.fr */ +/* Updated: 2024/09/04 09:42:34 by tsuchen ### ########.fr */ /* */ /* ************************************************************************** */