-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
73 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/15 00:19:44 by tsuchen #+# #+# */ | ||
/* Updated: 2024/09/02 16:11:01 by tsuchen ### ########.fr */ | ||
/* Updated: 2024/09/02 16:18:49 by tsuchen ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -48,6 +48,7 @@ | |
# define HEIGHT 720 | ||
# define FOV 90 | ||
# define ROT_STEP 1.5f | ||
# define MOUSE_ROT_STEP 1.0f | ||
# define MOV_STEP 0.1f | ||
# define MINI_MAP_W 200 | ||
# define MINI_MAP_H 200 | ||
|
@@ -78,6 +79,7 @@ typedef enum e_keys | |
A_KEY = 97, | ||
S_KEY = 115, | ||
D_KEY = 100, | ||
P_KEY = 112, | ||
} t_keys; | ||
typedef enum e_bool | ||
{ | ||
|
@@ -117,6 +119,7 @@ typedef struct s_data | |
char **map; | ||
void *mlx; | ||
void *window; | ||
int pause; | ||
t_image image; | ||
t_image mini_map; | ||
t_textdata *textures; | ||
|
@@ -131,6 +134,7 @@ typedef struct s_data | |
int cleanup(t_data *data); | ||
int game_init(t_data *data); | ||
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); | ||
/* color utils*/ | ||
int create_trgb(int t, int r, int g, int b); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* mouse_events.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: jteissie <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/09/02 11:59:13 by jteissie #+# #+# */ | ||
/* Updated: 2024/09/02 13:33:50 by jteissie ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "cub3d.h" | ||
|
||
int mouse_move(int x, int y, t_data *data) | ||
{ | ||
if (data->pause == TRUE) | ||
return (0); | ||
if (x == WIDTH / 2 && y == HEIGHT / 2) | ||
return (SUCCESS); | ||
if (x >= WIDTH / 2) | ||
{ | ||
vec_rotate(&data->p_cam, MOUSE_ROT_STEP * -1); | ||
vec_rotate(&data->p_dir, MOUSE_ROT_STEP * -1); | ||
} | ||
else | ||
{ | ||
vec_rotate(&data->p_cam, MOUSE_ROT_STEP); | ||
vec_rotate(&data->p_dir, MOUSE_ROT_STEP); | ||
} | ||
mlx_mouse_move(data->mlx, data->window, WIDTH / 2, HEIGHT / 2); | ||
return (SUCCESS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/27 17:03:43 by jteissie #+# #+# */ | ||
/* Updated: 2024/09/02 16:12:09 by tsuchen ### ########.fr */ | ||
/* Updated: 2024/09/02 16:17:55 by tsuchen ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/15 12:03:33 by tsuchen #+# #+# */ | ||
/* Updated: 2024/09/02 13:48:42 by tsuchen ### ########.fr */ | ||
/* Updated: 2024/09/02 16:20:08 by tsuchen ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -61,9 +61,11 @@ static int init_data(t_data *data, char *map_file) | |
|
||
void start_game(t_data *data) | ||
{ | ||
mlx_mouse_hide(data->mlx, data->window); | ||
mlx_loop_hook(data->mlx, rc_rendering, data); | ||
mlx_hook(data->window, KeyPress, KeyPressMask, &key_events, data); | ||
mlx_hook(data->window, DestroyNotify, StructureNotifyMask, &cleanup, data); | ||
mlx_hook(data->window, MotionNotify, PointerMotionMask, &mouse_move, data); | ||
mlx_loop(data->mlx); | ||
} | ||
|
||
|