Archived
1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
so_long/main.c

74 lines
2.0 KiB
C
Raw Normal View History

2024-01-06 17:15:02 +01:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/06 16:18:56 by adjoly #+# #+# */
2024-01-13 19:04:22 +01:00
/* Updated: 2024/01/13 19:01:34 by adjoly ### ########.fr */
2024-01-06 17:15:02 +01:00
/* */
/* ************************************************************************** */
2024-01-13 19:04:22 +01:00
#include "libft/libft.h"
2024-01-06 17:15:02 +01:00
#include "so_long.h"
void ft_freemap(char **map)
{
int i;
i = 0;
while (map[i])
{
free(map[i]);
i++;
}
free(map);
}
2024-01-06 17:15:02 +01:00
int win_close(int event, void *param)
{
if (event == 0)
mlx_loop_end(param);
return (0);
}
2024-01-13 19:04:22 +01:00
void ft_exit(t_window *win)
2024-01-07 22:45:08 +01:00
{
2024-01-13 19:04:22 +01:00
mlx_destroy_image(win->mlx, win->img);
mlx_destroy_window(win->mlx, win->win);
mlx_destroy_display(win->mlx);
ft_freemap(win->map);
free(win->p_coords);
free(win->e_coords);
free(win);
}
2024-01-07 22:45:08 +01:00
2024-01-06 17:15:02 +01:00
int main(int ac, char **av)
{
2024-01-07 22:45:08 +01:00
t_window *win;
char **map;
2024-01-06 17:15:02 +01:00
(void) ac;
(void) av;
map = ft_read_map(av[1]);
win = malloc(sizeof(map) + sizeof(t_window));
2024-01-07 22:45:08 +01:00
win->mlx = mlx_init();
win->win = mlx_new_window(win->mlx, 1600, 900, "so_fluffy");
win->map = map;
2024-01-13 19:04:22 +01:00
win->mov_count = 0;
2024-01-07 22:45:08 +01:00
mlx_on_event(win->mlx, win->win, MLX_WINDOW_EVENT, win_close, win->mlx);
mlx_on_event(win->mlx, win->win, MLX_KEYDOWN, ft_key_event, win);
2024-01-09 16:12:58 +01:00
// mlx_loop_hook(win->mlx, win_update, win);
ft_printmap(win->map, win);
2024-01-07 22:45:08 +01:00
mlx_loop(win->mlx);
mlx_destroy_image(win->mlx, win->img);
2024-01-07 22:45:08 +01:00
mlx_destroy_window(win->mlx, win->win);
mlx_destroy_display(win->mlx);
2024-01-13 19:04:22 +01:00
ft_freemap(win->map);
free(win->p_coords);
2024-01-13 19:04:22 +01:00
free(win->e_coords);
2024-01-08 13:33:55 +01:00
free(win);
2024-01-06 17:15:02 +01:00
return (0);
}