-
Notifications
You must be signed in to change notification settings - Fork 0
/
category_pass_helpers.c
100 lines (91 loc) · 2.56 KB
/
category_pass_helpers.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* category_pass_helpers.c :+: :+: */
/* +:+ */
/* By: cschuijt <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/11/20 14:06:53 by cschuijt #+# #+# */
/* Updated: 2022/11/20 14:06:53 by cschuijt ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
void initial_wall_seed(t_map *map)
{
size_t i;
i = map->width * 2;
while (i < map->size - map->width * 3)
{
if (map->content[i] == '1' && map->sprite_categories[i] != 'W')
if (map->content[i + 1] == '1')
if (map->content[i + map->width] == '1')
if (map->content[i + map->width + 1] == '1')
map->sprite_categories[i] = 'W';
i++;
}
}
void recursive_walls(t_map *map)
{
size_t i;
size_t changed;
map->size = ft_strlen(map->content);
i = map->width;
changed = 0;
while (i < map->size - map->width)
{
if (map->content[i] == '1' && map->sprite_categories[i] == ' ')
{
if (neighbors_wall(map, i) && can_be_wall(map, i))
{
map->sprite_categories[i] = 'W';
changed++;
}
}
i++;
}
if (changed)
recursive_walls(map);
}
int neighbors_wall(t_map *map, size_t i)
{
if (map->sprite_categories[i + 1] == 'W')
return (1);
if (map->sprite_categories[i - 1] == 'W')
return (1);
if (map->sprite_categories[i + map->width] == 'W')
return (1);
if (map->sprite_categories[i - map->width] == 'W')
return (1);
return (0);
}
int can_be_wall(t_map *map, size_t i)
{
if (map->content[i + map->width] == '1')
return (1);
if (map->content[i - map->width] == '1')
return (1);
return (0);
}
void lava_and_pillars(t_map *map)
{
size_t i;
char *loc;
i = 0;
while (map->content[i])
{
if (map->content[i] == '1' && map->sprite_categories[i] == ' ')
{
loc = &map->content[i];
if (*(loc + 1) != '1' && *(loc - 1) != '1')
{
if (*(loc + map->width) != '1' && *(loc - map->width) != '1')
map->sprite_categories[i] = 'P';
else
map->sprite_categories[i] = 'L';
}
else
map->sprite_categories[i] = 'L';
}
i++;
}
}