-
Notifications
You must be signed in to change notification settings - Fork 0
/
floor_tile_helpers.c
108 lines (99 loc) · 3.07 KB
/
floor_tile_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
101
102
103
104
105
106
107
108
/* ************************************************************************** */
/* */
/* :::::::: */
/* floor_tile_helpers.c :+: :+: */
/* +:+ */
/* By: cschuijt <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/11/28 13:42:20 by cschuijt #+# #+# */
/* Updated: 2022/11/28 13:42:20 by cschuijt ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
#include <stdlib.h>
// "\x4F\0\0\0\0" single dark tile
// "\x5E\x5F\0\0\0" 2x1 dark tiles
// "\x41\0\0\x50\0" 1x2 dark tiles
// "\x40\0\0\0\0" single quad dark tile
// "\x60\0\x70\x6F\0" dark corner bottom left
// "\x44\x45\x54\0\0" dark corner top right
// "\x52\x53\x62\x61\0" 2x2 dark square
// "\x63\0\0\x72\x71" dark corner bottom right
// "\x42\x43\0\x51\0" dark corner top left
t_floortile *initialize_tile_list(void)
{
t_floortile *list;
list = NULL;
add_tile_to_list(&list, "\x4F\0\0\0\0");
add_tile_to_list(&list, "\x5E\x5F\0\0\0");
add_tile_to_list(&list, "\x4F\0\0\0\0");
add_tile_to_list(&list, "\x4F\0\0\0\0");
add_tile_to_list(&list, "\x41\0\0\x50\0");
add_tile_to_list(&list, "\x40\0\0\0\0");
add_tile_to_list(&list, "\x60\0\x70\x6F\0");
add_tile_to_list(&list, "\x4F\0\0\0\0");
add_tile_to_list(&list, "\x44\x45\x54\0\0");
add_tile_to_list(&list, "\x52\x53\x62\x61\0");
add_tile_to_list(&list, "\x4F\0\0\0\0");
add_tile_to_list(&list, "\x4F\0\0\0\0");
add_tile_to_list(&list, "\x4F\0\0\0\0");
add_tile_to_list(&list, "\x63\0\0\x72\x71");
add_tile_to_list(&list, "\x4F\0\0\0\0");
add_tile_to_list(&list, "\x9A\0\0\0\0");
add_tile_to_list(&list, "\x42\x43\0\x51\0");
add_tile_to_list(&list, "\x4F\0\0\0\0");
return (list);
}
t_floortile *add_tile_to_list(t_floortile **list, char *pattern)
{
t_floortile *newtile;
t_floortile *start;
t_floortile *last;
start = *list;
newtile = new_tile(pattern);
if (*list == NULL)
{
*list = newtile;
newtile->next = newtile;
}
else
{
last = *list;
while (last->next != start)
last = last->next;
last->next = newtile;
newtile->next = *list;
}
return (newtile);
}
t_floortile *new_tile(char *pattern)
{
t_floortile *tile;
tile = ft_calloc(1, sizeof(t_floortile));
if (!tile)
return (NULL);
tile->pattern = ft_calloc(5, 1);
if (!tile->pattern)
{
free(tile);
return (NULL);
}
ft_memmove(tile->pattern, pattern, 5);
return (tile);
}
void free_tile_list(t_floortile **list)
{
t_floortile *start;
t_floortile *next;
start = *list;
while (*list)
{
free((*list)->pattern);
next = (*list)->next;
free(*list);
*list = next;
if (*list == start)
break ;
}
*list = NULL;
}