-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatrols.c
73 lines (65 loc) · 1.99 KB
/
patrols.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* patrols.c :+: :+: */
/* +:+ */
/* By: cschuijt <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/12/27 21:16:20 by cschuijt #+# #+# */
/* Updated: 2022/12/27 21:16:20 by cschuijt ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
void load_patrols(t_map *map)
{
size_t i;
i = 0;
while (map->content[i])
{
if (should_be_patrol(map->content[i]))
add_new_patrol(map, i, map->content[i]);
i++;
}
}
void add_new_patrol(t_map *map, size_t pos, char dir)
{
t_patrol *patrol;
patrol = ft_calloc(sizeof(t_patrol), 1);
if (!patrol)
exit_perror("malloc error");
patrol->pos = pos;
if (dir == 'U')
patrol->move_direction = dir_up;
else if (dir == 'R')
patrol->move_direction = dir_right;
else if (dir == 'D')
{
patrol->move_direction = dir_down;
patrol->facing_offset = 4;
}
else if (dir == 'L')
{
patrol->move_direction = dir_left;
patrol->facing_offset = 4;
}
add_patrol_to_map(map, patrol);
}
void add_patrol_to_map(t_map *map, t_patrol *patrol)
{
t_patrol *last_patrol;
patrol->next = NULL;
if (!map->patrols)
map->patrols = patrol;
else
{
last_patrol = map->patrols;
while (last_patrol->next)
last_patrol = last_patrol->next;
last_patrol->next = patrol;
}
update_patrol_movement_direction(map, patrol);
}
int should_be_patrol(char c)
{
return (c == 'U' || c == 'D' || c == 'L' || c == 'R');
}