/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* init.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/27 14:50:22 by erey-bet #+# #+# */ /* Updated: 2023/06/01 13:28:15 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ #include "game.h" void init_ply(t_map map, t_ply *ply) { ply->pos_x = map.ply_x + 0.5; ply->pos_y = map.ply_y + 0.5; ply->dir_x = 0.0; ply->dir_y = 0.0; if (map.direction == 'N') ply->dir_y = -1.0; if (map.direction == 'S') ply->dir_y = 1.0; if (map.direction == 'E') ply->dir_x = 1.0; if (map.direction == 'W') ply->dir_x = -1.0; ply->pla_x = -(ply->dir_y) * 0.66; ply->pla_y = (ply->dir_x) * 0.66; } void init_ray(t_ray *ray) { ray->dir_x = 0; ray->dir_y = 0; } int init_textures(t_map map, mlx_texture_t *textures[4]) { textures[0] = mlx_load_png(map.img_path[0]); if (!textures[0]) return (1); textures[1] = mlx_load_png(map.img_path[1]); if (!textures[1]) return (1); textures[2] = mlx_load_png(map.img_path[2]); if (!textures[2]) return (1); textures[3] = mlx_load_png(map.img_path[3]); if (!textures[3]) return (1); return (0); } int init(t_map map, t_game *game) { if (init_textures(map, game->textures)) return (2); game->mlx = mlx_init(WIDTH, HEIGHT, "jan lili", true); if (!game->mlx) return (1); game->map = map; init_ply(map, &game->ply); init_ray(&game->ray); return (0); }