-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatch_hook.c
More file actions
63 lines (57 loc) · 1.78 KB
/
Copy pathcatch_hook.c
File metadata and controls
63 lines (57 loc) · 1.78 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* catch_hook.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ekutlay <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/31 01:17:26 by ekutlay #+# #+# */
/* Updated: 2022/07/31 04:02:18 by ekutlay ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int close_window(t_data *mlx)
{
mlx_destroy_window(mlx->mlx, mlx->mlx_win);
exit (0);
}
void catch_moves(t_data *mlx)
{
int prev_x;
int prev_y;
static int moves;
prev_x = mlx->p_row;
prev_y = mlx->p_col;
fill_p_act(mlx);
if (prev_x != mlx->p_row || prev_y != mlx->p_col)
printf("moves = %d \n", ++moves);
}
int key_hook(int key, t_data *mlx)
{
if (key == 53)
{
mlx_destroy_window(mlx->mlx, mlx->mlx_win);
free_map(&mlx);
exit (0);
}
else if (key == 1)
mlx->key = 'S';
else if (key == 13)
mlx->key = 'W';
else if (key == 0)
mlx->key = 'A';
else if (key == 2)
mlx->key = 'D';
else
mlx->key = 'Z';
if (mlx->key == 'A' || mlx->key == 'S'
|| mlx->key == 'W' || mlx->key == 'D')
catch_moves(mlx);
return (0);
}
int catch_hook(t_data *mlx)
{
mlx_hook(mlx->mlx_win, 2, (1L << 0), key_hook, mlx);
mlx_hook(mlx->mlx_win, 17, (1L << 8), close_window, mlx);
return (0);
}