Files
42_INT_10_cube3d/srcs/cube3d.c

64 lines
1.5 KiB
C

#include "cube3d.h"
void destroy_mlx(void *param)
{
t_game *game;
game = param;
// tmp, to draw map
mlx_destroy_image(game->mlx_ptr, game->map_img.ptr);
mlx_destroy_window(game->mlx_ptr, game->map_win.ptr);
// tmp end
mlx_destroy_image(game->mlx_ptr, game->img.ptr);
mlx_destroy_window(game->mlx_ptr, game->win.ptr);
mlx_destroy_display(game->mlx_ptr);
}
int shut_down(void)
{
mb_exit(B_RED"close windows"RESET"\n");
return (0);
}
int main(int ac, char **av)
{
t_game *game;
if ((ac != 2 || check_extension(av[1], ".cub")) && \
write(2, "Error\nPlease use a valid .cub file as single argument.\n", 53))
return (EXIT_FAILURE);
game = init_struct();
if (init_parsing(game, av[1]) && write(2, "The .cub file is invalid.\n", 26))
return (EXIT_FAILURE);
if (check_map(&(game->map)) && write(2, "The map is invalid.\n", 20))
return (EXIT_FAILURE);
// init game variables
init_game(game);
mb_init(destroy_mlx, game);
// draw game a first time before it start
// tmp
plr_turn(&game->plr, -63);
// tmp end
draw(game);
// receive a keypress event
mlx_hook(game->win.ptr, 2, 1L << 0, keypress, game);
// receive a keyprelease event
mlx_hook(game->win.ptr, 3, 1L << 1, keyrelease, game);
// receive event when clicking the red button to close the window
mlx_hook(game->win.ptr, 17, 1L << 17, shut_down, NULL);
// infinite loop that waits for events to occurs
mlx_loop_hook(game->mlx_ptr, hook_action, game);
mlx_loop(game->mlx_ptr);
return (0);
}