-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathso_long.c
More file actions
113 lines (106 loc) · 3.8 KB
/
Copy pathso_long.c
File metadata and controls
113 lines (106 loc) · 3.8 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_long.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bbento-e <bbento-e@student.42porto.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/14 17:23:27 by bbento-e #+# #+# */
/* Updated: 2023/06/29 18:33:38 by bbento-e ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int key_handler(int key, t_data *data)
{
if (key == XK_Escape)
end(data);
else if (key == XK_w || key == XK_a || key == XK_s || key == XK_d)
mvmnt(data, key);
else
return (-1);
return (0);
}
int end(t_data *data)
{
free_2d(data->map, data->y);
mlx_destroy_image(data->mlx, data->floor);
mlx_destroy_image(data->mlx, data->wall[0]);
mlx_destroy_image(data->mlx, data->wall[1]);
mlx_destroy_image(data->mlx, data->wall[2]);
mlx_destroy_image(data->mlx, data->wall[3]);
mlx_destroy_image(data->mlx, data->wall[4]);
mlx_destroy_image(data->mlx, data->wall[5]);
mlx_destroy_image(data->mlx, data->wall[6]);
mlx_destroy_image(data->mlx, data->wall[7]);
mlx_destroy_image(data->mlx, data->wall[8]);
mlx_destroy_image(data->mlx, data->wall[9]);
mlx_destroy_image(data->mlx, data->clct[0]);
mlx_destroy_image(data->mlx, data->clct[1]);
mlx_destroy_image(data->mlx, data->exit[0]);
mlx_destroy_image(data->mlx, data->exit[1]);
mlx_destroy_image(data->mlx, data->exit[2]);
mlx_destroy_image(data->mlx, data->exit[3]);
mlx_destroy_image(data->mlx, data->exit[4]);
destroy_img_array(data);
mlx_destroy_window(data->mlx, data->win);
mlx_destroy_display(data->mlx);
free(data->mlx);
free_dp(data);
exit(0);
}
void destroy_img_array(t_data *data)
{
mlx_destroy_image(data->mlx, data->playeru[0]);
mlx_destroy_image(data->mlx, data->playeru[1]);
mlx_destroy_image(data->mlx, data->playeru[2]);
mlx_destroy_image(data->mlx, data->playeru[3]);
mlx_destroy_image(data->mlx, data->playeru[4]);
mlx_destroy_image(data->mlx, data->playerd[0]);
mlx_destroy_image(data->mlx, data->playerd[1]);
mlx_destroy_image(data->mlx, data->playerd[2]);
mlx_destroy_image(data->mlx, data->playerd[3]);
mlx_destroy_image(data->mlx, data->playerd[4]);
mlx_destroy_image(data->mlx, data->playerl[0]);
mlx_destroy_image(data->mlx, data->playerl[1]);
mlx_destroy_image(data->mlx, data->playerl[2]);
mlx_destroy_image(data->mlx, data->playerl[3]);
mlx_destroy_image(data->mlx, data->playerl[4]);
mlx_destroy_image(data->mlx, data->playerr[0]);
mlx_destroy_image(data->mlx, data->playerr[1]);
mlx_destroy_image(data->mlx, data->playerr[2]);
mlx_destroy_image(data->mlx, data->playerr[3]);
mlx_destroy_image(data->mlx, data->playerr[4]);
}
void free_dp(t_data *data)
{
free(data->wall);
free(data->clct);
free(data->exit);
free(data->playerd);
free(data->playeru);
free(data->playerl);
free(data->playerr);
}
int main(int argc, char *argv[])
{
t_data data;
t_types types;
if (argc == 2)
{
if (verify(&data, &types, argv[1]) == -1)
{
free_2d(data.map, data.y);
return (0);
}
data.mlx = mlx_init();
data.win = mlx_new_window(data.mlx, (data.x * 64),
((data.y + 1) * 64), "so_long");
populate(&data);
mlx_hook(data.win, DestroyNotify, StructureNotifyMask, &end, &data);
mlx_key_hook(data.win, &key_handler, &data);
mlx_loop_hook(data.mlx, &updates, &data);
mlx_loop(data.mlx);
end(&data);
}
return (int_err_handler(0));
}