-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinits.c
88 lines (82 loc) · 2.57 KB
/
inits.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* inits.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bmacmaho <bmacmaho@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/18 23:13:57 by barramacmah #+# #+# */
/* Updated: 2023/07/08 15:23:21 by bmacmaho ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static void ft_initmap(t_colour *floor, t_colour *ceiling, t_cub *cub)
{
floor->r = 0;
floor->g = 0;
floor->b = 0;
floor->a = 0;
ceiling->r = 0;
ceiling->g = 0;
ceiling->b = 0;
ceiling->a = 0;
cub->map.floor = *floor;
cub->map.ceiling = *ceiling;
cub->map.map = NULL;
cub->map.no = NULL;
cub->map.so = NULL;
cub->map.we = NULL;
cub->map.ea = NULL;
cub->map.map_x = 0;
cub->map.map_y = 0;
cub->map.mapsize = 0;
cub->map.all_info = 0;
cub->map.pos.y = 0;
cub->map.pos.x = 0;
cub->map.pos.dir = 127;
}
int ft_map(t_cub *cub, char *file, int *how_long_till_map)
{
t_colour floor;
t_colour ceiling;
int fd;
ft_initmap(&floor, &ceiling, cub);
fd = open(file, O_RDONLY);
if (fd == -1)
return (!!printf("Error\nNo such file or directory\n"));
close(fd);
if (!gather_data(&(cub->map), file, how_long_till_map) \
|| !create_int_map(&(cub->map)) || !fill_that_map(cub, file, \
*how_long_till_map) || !validate_walls(&(cub->map)))
return (1);
return (0);
}
void ft_init_player(t_cub *cub)
{
cub->player.pos.x = cub->map.pos.x + 0.5;
cub->player.pos.y = cub->map.pos.y + 0.5;
cub->player.plane.x = 0.0;
cub->player.plane.y = 0.66;
cub->player.dir.x = 1;
cub->player.dir.y = 0;
if (cub->map.pos.dir == 'N')
rotate(cub, M_PI * 1.5);
else if (cub->map.pos.dir == 'W')
rotate(cub, M_PI);
else if (cub->map.pos.dir == 'S')
rotate(cub, M_PI / 2);
}
int ft_init_cub(t_cub *cub, int argc, char **argv)
{
(void)argc;
(void)argv;
cub->mlx = mlx_init(WIDTH, HEIGHT, "MLX42", true);
if (!cub->mlx)
return (1);
cub->img = mlx_new_image(cub->mlx, WIDTH, HEIGHT);
if (!cub->img)
return (2);
if (mlx_image_to_window(cub->mlx, cub->img, 0, 0) == -1)
return (3);
return (0);
}