-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_hooks.c
35 lines (31 loc) · 1.45 KB
/
key_hooks.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* key_hooks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lstorey <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 14:52:43 by lstorey #+# #+# */
/* Updated: 2024/05/08 14:14:25 by lstorey ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void player_controls(t_game_list *game, mlx_t *mlx)
{
mlx_key_hook(mlx, &myhook, game);
}
void myhook(mlx_key_data_t keyd, void *param)
{
t_game_list *game;
game = param;
if (keyd.key == MLX_KEY_ESCAPE || keyd.key == MLX_KEY_Q)
end_game(game, 1);
if (keyd.key == MLX_KEY_UP && keyd.action == MLX_PRESS)
move_up(game);
if (keyd.key == MLX_KEY_DOWN && keyd.action == MLX_PRESS)
move_down(game);
if (keyd.key == MLX_KEY_LEFT && keyd.action == MLX_PRESS)
move_left(game);
if (keyd.key == MLX_KEY_RIGHT && keyd.action == MLX_PRESS)
move_right(game);
}