-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcategory_pass_updaters.c
84 lines (77 loc) · 2.44 KB
/
category_pass_updaters.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* category_pass_updaters.c :+: :+: */
/* +:+ */
/* By: cschuijt <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/11/20 15:08:51 by cschuijt #+# #+# */
/* Updated: 2022/11/20 15:08:51 by cschuijt ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
void north_walls(t_map *map)
{
size_t i;
i = 0;
while (i < map->size - (map->width * 2))
{
if (map->sprite_categories[i] == 'W')
if (map->sprite_categories[i + map->width] == ' ')
map->sprite_categories[i] = 'N';
i++;
}
}
void fill_floors_and_strip_walls(t_map *map)
{
size_t i;
i = map->width;
while (i < map->size - map->width)
{
if (map->sprite_categories[i] == ' ')
{
if (map->content[i] == 'E')
map->sprite_categories[i] = 'E';
else
map->sprite_categories[i] = 'F';
}
i++;
}
i = 0;
while (i < map->size)
{
if (!is_edge_wall(i, map))
map->sprite_categories[i] = ' ';
i++;
}
}
int is_edge_wall(size_t i, t_map *map)
{
if (i > map->width + 1 && floor_or_north_wall(i - map->width - 1, map))
return (1);
if (i > map->width && floor_or_north_wall(i - map->width, map))
return (1);
if (i > map->width - 1 && floor_or_north_wall(i - map->width + 1, map))
return (1);
if (i > 0 && floor_or_north_wall(i - 1, map))
return (1);
if (i < map->size - 1 && floor_or_north_wall(i + 1, map))
return (1);
if (i < map->size - map->width + 1)
if (floor_or_north_wall(i + map->width - 1, map))
return (1);
if (i < map->size - map->width && floor_or_north_wall(i + map->width, map))
return (1);
if (i < map->size - map->width - 1)
if (floor_or_north_wall(i + map->width + 1, map))
return (1);
return (0);
}
int floor_or_north_wall(size_t i, t_map *map)
{
if (map->sprite_categories[i] == 'N' || map->sprite_categories[i] == 'F')
return (1);
if (map->sprite_categories[i] == 'E')
return (1);
return (0);
}