-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectible_helpers.c
62 lines (55 loc) · 1.72 KB
/
collectible_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
/* ************************************************************************** */
/* */
/* :::::::: */
/* collectible_helpers.c :+: :+: */
/* +:+ */
/* By: cschuijt <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/11/30 17:32:48 by cschuijt #+# #+# */
/* Updated: 2022/11/30 17:32:48 by cschuijt ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
#include <stdlib.h>
void load_map_collectibles(t_map *map)
{
size_t i;
i = 0;
while (map->content[i])
{
if (map->content[i] == 'C')
add_collectible_to_map(map, i);
i++;
}
}
void add_collectible_to_map(t_map *map, size_t i)
{
t_collectible *collectible;
t_collectible *list;
collectible = ft_calloc(1, sizeof(t_collectible));
if (!collectible)
exit_perror("malloc error");
collectible->pos = i;
if (!map->collectibles)
map->collectibles = collectible;
else
{
list = map->collectibles;
while (list->next)
list = list->next;
list->next = collectible;
}
}
void clear_collectible_list(t_map *map)
{
t_collectible *collectible;
t_collectible *next;
collectible = map->collectibles;
while (collectible)
{
next = collectible->next;
free(collectible);
collectible = next;
}
map->collectibles = NULL;
}