-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity_array.c
150 lines (131 loc) · 4.34 KB
/
entity_array.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "arena.c"
#include "control_group.c"
#include "entity.c"
#include <assert.h>
#include <raylib.h>
#include <stddef.h>
#include <stdio.h>
typedef struct {
Entity *items;
size_t length;
size_t capacity;
} EntityArray;
void EntityArray_ADD(EntityArray *array, Entity entity) {
assert(array->length < array->capacity && "EntityArray is full!");
array->items[array->length++] = entity;
}
void EntityArray_SETUP(EntityArray *array) {
Entity entity1 = {.id = 1,
.x = 256,
.y = 144,
.radius = 30.0,
.color = RED,
.moveSpeed = 400,
.direction = {.x = 20.0, .y = 20.0}};
Entity entity2 = {.id = 2,
.x = 540,
.y = 200,
.radius = 30.0,
.color = RED,
.moveSpeed = 400,
.direction = {.x = 20.0, .y = 20.0}};
Entity entity3 = {.id = 3,
.x = 868,
.y = 400,
.radius = 30.0,
.color = RED,
.moveSpeed = 400,
.direction = {.x = 20.0, .y = 20.0}};
Entity entity4 = {.id = 4,
.x = 1000,
.y = 666,
.radius = 30.0,
.color = RED,
.moveSpeed = 400,
.direction = {.x = 20.0, .y = 20.0}};
Entity entity5 = {.id = 5,
.x = 1280,
.y = 420,
.radius = 30.0,
.color = RED,
.moveSpeed = 400,
.direction = {.x = 20.0, .y = 20.0}};
Entity entity6 = {.id = 6,
.x = 1423,
.y = 864,
.radius = 30.0,
.color = RED,
.moveSpeed = 400,
.direction = {.x = 20.0, .y = 20.0}};
Entity entity7 = {.id = 7,
.x = 1792,
.y = 1008,
.radius = 30.0,
.color = RED,
.moveSpeed = 400,
.direction = {.x = 20.0, .y = 20.0}};
Entity entity8 = {.id = 8,
.x = 2048,
.y = 1159,
.radius = 30.0,
.color = RED,
.moveSpeed = 400,
.direction = {.x = 20.0, .y = 20.0}};
Entity entity9 = {.id = 9,
.x = 2304,
.y = 1296,
.radius = 30.0,
.color = RED,
.moveSpeed = 400,
.direction = {.x = 20.0, .y = 20.0}};
Entity entity10 = {.id = 10,
.x = 2200,
.y = 237,
.radius = 30.0,
.color = RED,
.moveSpeed = 400,
.direction = {.x = 20.0, .y = 20.0}};
EntityArray_ADD(array, entity1);
EntityArray_ADD(array, entity2);
EntityArray_ADD(array, entity3);
EntityArray_ADD(array, entity4);
EntityArray_ADD(array, entity5);
EntityArray_ADD(array, entity6);
EntityArray_ADD(array, entity7);
EntityArray_ADD(array, entity8);
EntityArray_ADD(array, entity9);
EntityArray_ADD(array, entity10);
}
void EntityArray_INIT(EntityArray *array, Arena *arena, size_t capacity) {
array->items = (Entity *)ArenaAllocate(arena, capacity * sizeof(Entity));
array->length = 0;
array->capacity = capacity;
}
Entity EntityArray_GET(EntityArray *array, int32_t index) {
assert(index >= 0 && index < array->length);
if (index >= 0 && index < array->length) {
return array->items[index];
}
Entity invalidEntity = {};
return invalidEntity;
}
void HandleEntityClick(EntityArray *array, ControlGroup *group) {
for (int32_t i = 0; i < array->length; i++) {
Entity item = EntityArray_GET(array, i);
if (IsEntityClicked(item)) {
ControlGroupToggleUnit(group, (uint8_t)i);
};
}
}
void DrawEntities(EntityArray *array, ControlGroup *group) {
for (int32_t i = 0; i < array->length; i++) {
Entity item = EntityArray_GET(array, i);
DrawEntity(item, i, group);
}
}
void PrintEntities(EntityArray *array) {
for (int32_t i = 0; i < array->length; i++) {
Entity item = EntityArray_GET(array, i);
printf("%d\n", item.id);
}
}