-
Notifications
You must be signed in to change notification settings - Fork 0
/
pars_map_part_2.c
130 lines (122 loc) · 2.81 KB
/
pars_map_part_2.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pars_map_part_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbrandy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/16 16:10:08 by lbrandy #+# #+# */
/* Updated: 2021/04/02 20:16:43 by lbrandy ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void init_dir(t_pos *pos, char temp)
{
if (temp == 'W' || temp == 'E')
{
pos->dir_x = 0;
pos->dir_y = 1;
pos->plane_x = 0.66;
pos->plane_y = 0;
if (temp == 'W')
{
pos->dir_y = -1.0;
pos->plane_x = -0.66;
}
}
else if (temp == 'N' || temp == 'S')
{
pos->dir_x = -1;
pos->dir_y = 0;
pos->plane_x = 0;
pos->plane_y = 0.66;
if (temp == 'S')
{
pos->dir_x = 1.0;
pos->plane_y = -0.66;
}
}
}
static void check_sym(t_all *all, t_pos *pos, int i, int j)
{
if (ft_strchr(" 012NSEW", all->map[i][j]) == NULL)
error_handler("trash in file\n");
else if (all->map[i][j] == 'N' || all->map[i][j] == 'E'
|| all->map[i][j] == 'W' || all->map[i][j] == 'S')
{
if (all->dir == '\0')
{
pos->pos_x = i + 0.5;
pos->pos_y = j + 0.5;
all->dir = all->map[i][j];
all->map[i][j] = '0';
init_dir(pos, all->dir);
}
else
error_handler("duplicate player position\n");
}
}
void init_pos(t_all *all, t_pos *pos)
{
int i;
int j;
i = 0;
all->dir = '\0';
while (all->map[i])
{
j = 0;
while (all->map[i][j])
{
check_sym(all, pos, i, j);
j++;
}
i++;
}
if (all->dir == '\0')
error_handler("player not found\n");
pos->map_height = i;
}
void check_up_down(char **map, int i, int h)
{
while (map[0][i])
{
if (map[0][i] == '1' || map[0][i] == ' ')
i++;
else
error_handler("bad boundaries\n");
}
i = 0;
while (map[h - 1][i])
{
if ((map[h - 1][i] == '1' || map[h - 1][i] == ' '))
i++;
else
error_handler("bad boundaries\n");
}
}
void check_boundary(t_all *all, char **map, t_pos *pos)
{
int i;
int h;
i = 0;
(void)all;
h = pos->map_height;
check_up_down(map, i, h);
i = 0;
while (map[i])
{
if (map[i][0] == '1' || map[i][0] == ' ')
i++;
else
error_handler("bad boundaries\n");
}
i = 0;
while (map[i])
{
if (map[i][ft_strlen(map[i]) - 1] == '1'
|| map[i][ft_strlen(map[i]) - 1] == ' ')
i++;
else
error_handler("bad boundaries\n");
}
}