-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitems_a.c
72 lines (64 loc) · 1.82 KB
/
items_a.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* items_a.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jbartosi <jbartosi@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/10 18:29:34 by jbartosi #+# #+# */
/* Updated: 2023/09/25 18:01:31 by jbartosi ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
t_item *last_item(t_item *i)
{
if (!i)
return (NULL);
while (i->next)
i = i->next;
return (i);
}
void item_add_back(t_box *box, t_item *new)
{
if (box->items == NULL)
box->items = new;
else
{
new->prev = last_item(box->items);
last_item(box->items)->next = new;
}
}
t_item *find_item(t_box *box, int id)
{
t_item *items;
items = box->items;
if (!items)
return (NULL);
while (items)
{
if (items->data->id == id)
return (items);
items = items->next;
}
return (NULL);
}
void item_append(t_box *box, t_sprite *sprite)
{
t_item *new;
new = new_item();
new->data->id = sprite->data->id;
new->data->texture = ITEMS;
item_add_back(box, new);
sprite_remove(box, sprite);
}
void item_remove(t_box *box, t_item *to_rem)
{
if (to_rem == box->items)
box->items = box->items->next;
else
to_rem->prev->next = to_rem->next;
if (to_rem->next)
to_rem->next->prev = to_rem->prev;
free(to_rem->data);
free(to_rem);
}