2023-04-27 09:13:32 -04:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* init.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/04/27 14:50:22 by erey-bet #+# #+# */
|
2023-06-01 07:49:12 -04:00
|
|
|
/* Updated: 2023/06/01 13:28:15 by erey-bet ### ########.fr */
|
2023-04-27 09:13:32 -04:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "game.h"
|
|
|
|
|
2023-05-03 11:48:36 -04:00
|
|
|
void init_ply(t_map map, t_ply *ply)
|
2023-04-27 09:13:32 -04:00
|
|
|
{
|
2023-06-01 07:49:12 -04:00
|
|
|
ply->pos_x = map.ply_x + 0.5;
|
|
|
|
ply->pos_y = map.ply_y + 0.5;
|
2023-05-11 10:25:29 -04:00
|
|
|
ply->dir_x = 0.0;
|
|
|
|
ply->dir_y = 0.0;
|
2023-05-05 11:06:47 -04:00
|
|
|
if (map.direction == 'N')
|
2023-05-11 10:25:29 -04:00
|
|
|
ply->dir_y = -1.0;
|
2023-05-05 11:06:47 -04:00
|
|
|
if (map.direction == 'S')
|
2023-05-11 10:25:29 -04:00
|
|
|
ply->dir_y = 1.0;
|
2023-05-05 11:06:47 -04:00
|
|
|
if (map.direction == 'E')
|
2023-05-11 10:25:29 -04:00
|
|
|
ply->dir_x = 1.0;
|
2023-05-05 11:06:47 -04:00
|
|
|
if (map.direction == 'W')
|
2023-05-11 10:25:29 -04:00
|
|
|
ply->dir_x = -1.0;
|
2023-05-05 11:06:47 -04:00
|
|
|
ply->pla_x = -(ply->dir_y) * 0.66;
|
|
|
|
ply->pla_y = (ply->dir_x) * 0.66;
|
2023-04-27 09:13:32 -04:00
|
|
|
}
|
|
|
|
|
2023-05-02 09:39:16 -04:00
|
|
|
void init_ray(t_ray *ray)
|
2023-04-27 09:13:32 -04:00
|
|
|
{
|
2023-05-03 06:45:40 -04:00
|
|
|
ray->dir_x = 0;
|
|
|
|
ray->dir_y = 0;
|
2023-04-27 09:13:32 -04:00
|
|
|
}
|
|
|
|
|
2023-05-09 08:46:49 -04:00
|
|
|
int init_textures(t_map map, mlx_texture_t *textures[4])
|
2023-05-05 11:06:47 -04:00
|
|
|
{
|
2023-05-09 08:46:49 -04:00
|
|
|
textures[0] = mlx_load_png(map.img_path[0]);
|
2023-05-05 11:06:47 -04:00
|
|
|
if (!textures[0])
|
|
|
|
return (1);
|
2023-05-09 08:46:49 -04:00
|
|
|
textures[1] = mlx_load_png(map.img_path[1]);
|
2023-05-05 11:06:47 -04:00
|
|
|
if (!textures[1])
|
|
|
|
return (1);
|
2023-05-09 08:46:49 -04:00
|
|
|
textures[2] = mlx_load_png(map.img_path[2]);
|
2023-05-05 11:06:47 -04:00
|
|
|
if (!textures[2])
|
|
|
|
return (1);
|
2023-05-09 08:46:49 -04:00
|
|
|
textures[3] = mlx_load_png(map.img_path[3]);
|
2023-05-05 11:06:47 -04:00
|
|
|
if (!textures[3])
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2023-05-09 08:46:49 -04:00
|
|
|
int init(t_map map, t_game *game)
|
2023-04-27 09:13:32 -04:00
|
|
|
{
|
2023-05-19 11:54:06 -04:00
|
|
|
if (init_textures(map, game->textures))
|
|
|
|
return (2);
|
2023-05-03 06:45:40 -04:00
|
|
|
game->mlx = mlx_init(WIDTH, HEIGHT, "jan lili", true);
|
|
|
|
if (!game->mlx)
|
2023-05-09 08:46:49 -04:00
|
|
|
return (1);
|
2023-05-03 06:45:40 -04:00
|
|
|
game->map = map;
|
2023-05-03 11:48:36 -04:00
|
|
|
init_ply(map, &game->ply);
|
|
|
|
init_ray(&game->ray);
|
2023-05-09 08:46:49 -04:00
|
|
|
return (0);
|
2023-04-27 09:13:32 -04:00
|
|
|
}
|