2023-04-26 08:58:24 -04:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* game.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/04/26 12:59:53 by erey-bet #+# #+# */
|
2023-06-15 11:21:07 -04:00
|
|
|
/* Updated: 2023/06/15 12:40:32 by erey-bet ### ########.fr */
|
2023-04-26 08:58:24 -04:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
2023-04-27 09:13:32 -04:00
|
|
|
#include "game.h"
|
2023-04-26 08:58:24 -04:00
|
|
|
|
2023-06-15 11:21:07 -04:00
|
|
|
static void destroy(t_game *game)
|
2023-05-11 10:25:29 -04:00
|
|
|
{
|
2023-05-19 11:54:06 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-11 10:25:29 -04:00
|
|
|
}
|
|
|
|
|
2023-06-13 08:19:45 -04:00
|
|
|
static void hook(void *param)
|
|
|
|
{
|
|
|
|
t_game *game;
|
|
|
|
|
|
|
|
game = param;
|
|
|
|
if (manage_keys(game))
|
|
|
|
raycasting(game);
|
|
|
|
}
|
|
|
|
|
2023-05-03 11:48:36 -04:00
|
|
|
int start_game(t_map map)
|
2023-04-26 08:58:24 -04:00
|
|
|
{
|
2023-05-02 09:39:16 -04:00
|
|
|
t_game game;
|
2023-04-26 08:58:24 -04:00
|
|
|
|
2023-05-09 08:46:49 -04:00
|
|
|
if (init(map, &game))
|
2023-06-15 11:21:07 -04:00
|
|
|
{
|
|
|
|
destroy(&game);
|
|
|
|
return (1);
|
|
|
|
}
|
2023-05-02 09:39:16 -04:00
|
|
|
game.window = mlx_new_image(game.mlx, WIDTH, HEIGHT);
|
|
|
|
if (!game.window)
|
2023-04-26 09:45:21 -04:00
|
|
|
{
|
2023-05-03 11:48:36 -04:00
|
|
|
mlx_terminate(game.mlx);
|
2023-06-15 11:21:07 -04:00
|
|
|
destroy(&game);
|
|
|
|
return (1);
|
2023-04-26 09:45:21 -04:00
|
|
|
}
|
2023-05-02 09:39:16 -04:00
|
|
|
if (mlx_image_to_window(game.mlx, game.window, 0, 0) == -1)
|
2023-04-26 09:45:21 -04:00
|
|
|
{
|
2023-05-03 11:48:36 -04:00
|
|
|
mlx_terminate(game.mlx);
|
2023-06-15 11:21:07 -04:00
|
|
|
destroy(&game);
|
|
|
|
return (1);
|
2023-04-26 09:45:21 -04:00
|
|
|
}
|
2023-05-03 11:48:36 -04:00
|
|
|
raycasting(&game);
|
2023-06-13 08:19:45 -04:00
|
|
|
mlx_loop_hook(game.mlx, &hook, &game);
|
2023-05-02 09:39:16 -04:00
|
|
|
mlx_loop(game.mlx);
|
2023-05-11 10:25:29 -04:00
|
|
|
destroy(&game);
|
2023-04-26 08:58:24 -04:00
|
|
|
return (0);
|
|
|
|
}
|