42_cube3D/game/game.c
Etienne Rey-bethbeder 4bd265e213 SIG HEIL
2023-06-13 14:19:45 +02:00

73 lines
1.9 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* game.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/26 12:59:53 by erey-bet #+# #+# */
/* Updated: 2023/06/13 14:19:08 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "game.h"
static int destroy(t_game *game)
{
if (game->textures[0])
{
mlx_delete_texture(game->textures[0]);
if (game->textures[1])
{
mlx_delete_texture(game->textures[1]);
if (game->textures[2])
{
mlx_delete_texture(game->textures[2]);
if (game->textures[3])
{
mlx_delete_texture(game->textures[3]);
if (game->mlx)
mlx_terminate(game->mlx);
}
}
}
}
return (1);
}
#include <stdio.h>
static void hook(void *param)
{
t_game *game;
game = param;
//printf("%d\n", mlx_is_key_down(game->mlx, MLX_KEY_ESCAPE));
if (manage_keys(game))
raycasting(game);
}
int start_game(t_map map)
{
t_game game;
if (init(map, &game))
return (destroy(&game));
game.window = mlx_new_image(game.mlx, WIDTH, HEIGHT);
if (!game.window)
{
mlx_terminate(game.mlx);
return (destroy(&game));
}
if (mlx_image_to_window(game.mlx, game.window, 0, 0) == -1)
{
mlx_terminate(game.mlx);
return (destroy(&game));
}
raycasting(&game);
mlx_loop_hook(game.mlx, &hook, &game);
mlx_loop(game.mlx);
destroy(&game);
return (0);
}