Skip to content

Commit

Permalink
Added turn_around movement with R_KEY and SPACE_KEY to interact with …
Browse files Browse the repository at this point in the history
…door
  • Loading branch information
Tsunghao-C committed Sep 4, 2024
1 parent f53f20d commit a6d4efc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
5 changes: 4 additions & 1 deletion includes/cub3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 12 additions & 2 deletions srcs/events/key_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* key_events.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jteissie <jteissie@student.42.fr> +#+ +:+ +#+ */
/* By: tsuchen <tsuchen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions srcs/events/mouse_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* mouse_events.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jteissie <jteissie@student.42.fr> +#+ +:+ +#+ */
/* By: tsuchen <tsuchen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion srcs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down

0 comments on commit a6d4efc

Please sign in to comment.