-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_utils.c
executable file
·102 lines (94 loc) · 1.68 KB
/
map_utils.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
#include "cub3d.h"
static void free_map_line(t_map_list *map)
{
t_map_node *temp;
temp = map->head;
map->head = map->head->next;
--map->len;
free(temp->line);
free(temp);
}
int free_map_list(t_map_list *map)
{
while (map->head != NULL)
free_map_line(map);
return (0);
}
static bool map_chek_add(char **map)
{
int x;
int y;
y = 0;
x = 0;
while (map[y][x] != '\0')
{
if (map[y][x] != '1' && map[y][x] != ' ')
return (false);
++x;
}
while (map[y] != NULL)
++y;
--y;
x = 0;
while (map[y][x] != '\0')
{
if (map[y][x] != '1' && map[y][x] != ' ')
return (false);
++x;
}
return (true);
}
bool map_chek(t_set *set, int x, int y, int len1)
{
int len2;
while (set->m[++y + 1] != NULL)
{
len1 = ft_strlen(set->m[y - 1]);
len2 = ft_strlen(set->m[y + 1]);
while (set->m[y][++x + 1] != '\0')
{
if (set->m[y][x] == '2' || set->m[y][x] == '0'
|| set->m[y][x] == set->s)
{
if ((x >= len1 || set->m[y + 1][x] == ' ') || (x >= len2
|| set->m[y - 1][x] == ' ') || (set->m[y][x + 1] == ' ')
|| (set->m[y][x - 1] == ' '))
return (false);
if (set->m[y][x] == set->s)
{
set->spawn_x = x;
set->spawn_y = y;
}
}
}
x = 0;
}
return (map_chek_add(set->m));
}
bool map_line_check(t_set *set, char *ln)
{
if (*ln != '1' && *ln != ' ')
return (false);
while (*ln)
{
if (*ln == '2')
++set->sprites;
if (*ln == 'N' || *ln == 'W' || *ln == 'S' || *ln == 'E')
{
if (set->s == 0)
{
set->s = *ln;
++ln;
continue ;
}
return (false);
}
if (*ln != '0' && *ln != '1' && *ln != '2' && *ln != ' ')
return (false);
++ln;
}
--ln;
if (*ln != '1' && *ln != ' ')
return (false);
return (true);
}