-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.c
56 lines (41 loc) · 1.02 KB
/
scene.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
#include "scene.h"
result add_entity(Scene *scene, Entity *entity)
{
EntityLink *new_elem = malloc(sizeof(EntityLink));
if (new_elem == NULL) goto_fail(MEMORY_ERROR);
new_elem->this = entity;
new_elem->next = scene->entities;
scene->entities = new_elem;
return SUCCESS;
fail:
return FAILURE;
}
Entity *pop_entity(Scene *scene)
{
if (scene->entities == NULL) return NULL;
EntityLink *top_elem = scene->entities;
Entity *entity = top_elem->this;
scene->entities = top_elem->next;
free(top_elem);
return entity;
}
void clear_scene(Scene *scene)
{
EntityLink *current = scene->entities;
while (current != NULL)
{
current = current->next;
free(current);
}
scene->entities = NULL;
}
void update_scene(Scene *scene, int time_ms)
{
EntityLink *current = scene->entities;
while (current != NULL)
{
move_entity(current->this, time_ms);
bounce_off_wall(current->this, &scene->size);
current = current->next;
}
}