-
Notifications
You must be signed in to change notification settings - Fork 0
/
so_long.c
61 lines (55 loc) · 2.08 KB
/
so_long.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_long.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hramaros <hramaros@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/16 10:48:44 by hramaros #+# #+# */
/* Updated: 2024/07/24 13:33:59 by hramaros ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void set_tile_px(t_mlx_data *data)
{
void *img;
int h;
int w;
img = compute_xpm_to_win(data, &w, &h, "./assets/xpm/ground.xpm");
if (!img)
return ;
data->tile_x_px = w;
data->tile_y_px = h;
mlx_destroy_image(data->mlx, img);
}
void destroy_display(t_mlx_data *data)
{
mlx_destroy_display(data->mlx);
free(data->mlx);
render_exit(NULL, "Error\n");
}
int main(int argc, char **argv)
{
t_mlx_data data;
data.mlx = mlx_init();
if (!data.mlx)
return (render_exit(NULL, "Error\n"), 0);
if (argc != 2)
return (destroy_display(&data), 0);
data.grid = malloc(sizeof(char *) * (count_lines(argv[1]) + 1));
if (!data.grid || !fullfill_grid(data.grid, argv[1])
|| !is_validgrid(data.grid) || !uniform_map(&data))
return (destroy_display(&data), 0);
if (!grid_rules(&data))
return (ft_free_splitted(data.grid), destroy_display(&data), 0);
set_tile_px(&data);
data.win = mlx_new_window(data.mlx, data.tile_x_px * data.x, data.tile_y_px
* data.y, "so_long hramaros");
if (!data.win)
return (ft_free_splitted(data.grid), destroy_display(&data), 1);
set_hooks(&data);
data.moves = 0;
render_map(&data);
mlx_loop(data.mlx);
return (ft_free_splitted(data.grid), free_mlx_data(&data), 0);
}