42_solong/main.c
Camille Chauvet eb54b7bc0f kekw
2023-01-11 19:10:28 +01:00

75 lines
2.0 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 17:20:17 by cchauvet #+# #+# */
/* Updated: 2023/01/11 19:07:19 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "solong.h"
int ft_initialised(char *path, t_data *data)
{
t_map *map;
map = ft_getmap(path);
if (map == NULL)
{
free(data);
ft_printf("Map error\n");
exit(1);
}
data->map = map;
data->window = mlx_new_window(data->mlx, WINDOW_SIZE, WINDOW_SIZE, "long");
data->nb_foots = 0;
data->nb_swaps = ft_random_generator(0, 100);
ft_draw_map(data);
mlx_hook(data->window, 17, (0L), ft_exit, data);
mlx_hook(data->window, 2, (1L << 0), ft_key, data);
mlx_loop(data->mlx);
return (0);
}
int ft_exit(t_data *data)
{
t_map *map;
size_t i;
map = data->map;
i = 0;
while (i < NB_COLORS * 2)
{
if (data->assets[i] != NULL)
mlx_destroy_image(data->mlx, data->assets[i]);
i++;
}
ft_freer_tab_ultimate(1, map->patern);
mlx_destroy_window(data->mlx, data->window);
mlx_destroy_display(data->mlx);
free(data->mlx);
free(map);
exit(0);
}
int main(int ac, char **av)
{
t_data data;
if (ac != 2)
{
ft_printf("Map error\n");
return (1);
}
data.mlx = mlx_init();
ft_printf("Generating assets ...");
ft_gen_assets(&data);
ft_printf("\rGenerating assets [FINISHED]\n");
if (ft_initialised(av[1], &data))
ft_printf("Memory error");
return (1);
}