-
Notifications
You must be signed in to change notification settings - Fork 0
/
north_walls.c
78 lines (69 loc) · 2.01 KB
/
north_walls.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* north_walls.c :+: :+: */
/* +:+ */
/* By: cschuijt <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/12/04 23:05:25 by cschuijt #+# #+# */
/* Updated: 2022/12/04 23:05:25 by cschuijt ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
void fill_in_north_wall_sprites(t_map *map)
{
size_t i;
i = 0;
while (i < map->size)
{
if (map->sprite_categories[i] == 'N')
i += fill_in_north_wall_segment(map, i);
else
i++;
}
}
size_t fill_in_north_wall_segment(t_map *map, size_t i)
{
size_t len;
size_t iterator;
len = 0;
while (map->sprite_categories[i + len] == 'N')
len++;
if (len >= 5)
decorate_north_wall_segment(map, i, len);
iterator = 0;
while (iterator < len)
{
if (!map->render_terrain[i + iterator])
map->render_terrain[i + iterator] = undecorated_north_wall_sprite();
iterator++;
}
return (len);
}
void decorate_north_wall_segment(t_map *map, size_t i, size_t len)
{
size_t remainder;
remainder = len % 3;
if (remainder == 2)
{
map->render_terrain[i + (len / 3)] = 90;
map->render_terrain[i + len - (len / 3) - 1] = 90;
}
else
{
map->render_terrain[i + (len / 3) - 1] = 90;
map->render_terrain[i + len - (len / 3)] = 90;
}
}
uint8_t undecorated_north_wall_sprite(void)
{
static size_t i = 0;
i++;
if (i % 20 == 4)
return (61);
if (i % 20 == 11)
return (62);
if (i % 20 == 15)
return (63);
return (60);
}