-
Notifications
You must be signed in to change notification settings - Fork 0
/
windows_hooks.c
87 lines (79 loc) · 2.5 KB
/
windows_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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* windows_hooks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ikayacio <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/09 11:12:06 by ikayacio #+# #+# */
/* Updated: 2023/05/12 17:16:48 by ikayacio ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int handle_no_event(t_data *data)
{
(void)data;
return (0);
}
void render_map(t_data *data)
{
int i;
int j;
i = -1;
while (data->map_data.map[++i])
{
j = -1;
while ((*data).map_data.map[i][++j] != '\n')
{
mlx_put_image_to_window(data -> mlx_ptr, data -> win_ptr,
data -> floor.img_ptr, j * 16, i * 16);
if ((*data).map_data.map[i][j] == 'C')
mlx_put_image_to_window(data -> mlx_ptr, data -> win_ptr,
data -> coin.img_ptr, j * 16, i * 16);
else if ((*data).map_data.map[i][j] == 'E')
mlx_put_image_to_window(data -> mlx_ptr, data -> win_ptr,
data -> exit.img_ptr, j * 16, i * 16);
else if ((*data).map_data.map[i][j] == '1')
mlx_put_image_to_window(data -> mlx_ptr, data -> win_ptr,
data -> wall.img_ptr, j * 16, i * 16);
}
}
mlx_put_image_to_window(data -> mlx_ptr, data -> win_ptr,
data -> player.img_ptr, data -> map_data.p_position_x * 16,
data -> map_data.p_position_y * 16);
}
int handle_input(int keycode, t_data *data)
{
if (keycode == ESC)
{
close_program(data);
}
if (keycode == W || keycode == A
|| keycode == S || keycode == D)
{
check_move(data, keycode);
render_map(data);
}
return (0);
}
int close_program(t_data *data)
{
int i;
mlx_destroy_window(data->mlx_ptr, data->win_ptr);
img_delete(data);
i = 0;
while (data->map_data.map[i] != NULL)
{
free(data->map_data.map[i]);
data->map_data.map[i] = NULL;
i++;
}
free(data->mlx_ptr);
exit(EXIT_SUCCESS);
}
void open_window(t_data *data)
{
data->win_ptr = mlx_new_window(data->mlx_ptr, WINDOW_WIDTH,
WINDOW_HEIGHT, "My Game");
mlx_hook(data->win_ptr, 17, 0, close_program, data);
}