intra to gitea
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/12 11:00:04 by lfirmin #+# #+# */
|
||||
/* Updated: 2024/11/12 15:53:59 by lfirmin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../include/so_long.h"
|
||||
|
||||
int get_map_dimensions(t_data *data, int *width, int *height)
|
||||
{
|
||||
*height = 0;
|
||||
while (data->map[*height])
|
||||
{
|
||||
if (*height == 0)
|
||||
*width = ft_strlen(data->map[0]);
|
||||
else if ((int)ft_strlen(data->map[*height]) != *width)
|
||||
return (1);
|
||||
(*height)++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int launch_game(t_data *data)
|
||||
{
|
||||
t_game *game;
|
||||
int width;
|
||||
int height;
|
||||
|
||||
if (get_map_dimensions(data, &width, &height))
|
||||
return (ft_printf_fd(2, "Error : Invalid map dimensions\n"), 1);
|
||||
game = malloc(sizeof(t_game));
|
||||
if (!game)
|
||||
return (1);
|
||||
init_struct(game);
|
||||
game->map = data->map;
|
||||
game->map_width = width;
|
||||
game->map_height = height;
|
||||
game->collectibles = data->colect;
|
||||
game->moves = 0;
|
||||
game->data = data;
|
||||
if (init_game(game))
|
||||
return (free(game), 1);
|
||||
mlx_hook(game->win, 2, 1L << 0, key_hook, game);
|
||||
mlx_hook(game->win, 17, 1L << 17, close_game, game);
|
||||
draw_map(game);
|
||||
mlx_loop(game->mlx);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
t_data *data;
|
||||
|
||||
if (ac != 2)
|
||||
return (ft_printf_fd(2, "Error : Usage: ./so_long map.ber\n"), 1);
|
||||
data = init_data();
|
||||
if (!data)
|
||||
return (ft_printf_fd(2, "Error : Init failed\n"), 1);
|
||||
if (pars_map(data, av[1]) == 1)
|
||||
return (1);
|
||||
if (launch_game(data))
|
||||
return (clean_data(data), 1);
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user