-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
58 lines (54 loc) · 1.82 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rboudwin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/14 10:50:19 by rboudwin #+# #+# */
/* Updated: 2023/12/29 09:47:33 by rboudwin ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void check_args(int argc, const char **argv, t_map *map)
{
if (argc <= 1)
{
ft_printf("Please specify a *.ber file to read: so_long <filename>\n");
exit(EXIT_FAILURE);
}
if (argc > 2)
{
ft_printf("Too many parameters\n");
exit(EXIT_FAILURE);
}
map->filename = argv[1];
}
int main(int argc, const char **argv)
{
mlx_t *mlx;
t_map map;
t_img p;
map.img = &p;
check_args(argc, argv, &map);
if (!map_validator(&map))
return (EXIT_FAILURE);
mlx = mlx_init(1366, 768, "so_long", true);
map.window_width = 1366;
map.window_height = 768;
map.mlx = mlx;
if (!mlx)
exit(EXIT_FAILURE);
initialize_images(mlx, &map, &p);
draw_map(mlx, &map, &p);
mlx_key_hook(mlx, my_keyhook, &map);
mlx_resize_hook(mlx, my_resize_hook, &map);
mlx_close_hook(mlx, my_close_hook, &map);
mlx_loop(mlx);
mlx_terminate(mlx);
map.i = 0;
while (map.grid[map.i] != NULL)
free(map.grid[map.i++]);
free(map.grid);
return (EXIT_SUCCESS);
}