-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentity.c
34 lines (29 loc) · 858 Bytes
/
entity.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
#include "entity.h"
unsigned int create_entity(struct entities *_entities)
{
unsigned int entity;
for(entity = 0; entity < ENTITY_COUNT; ++entity)
{
if(_entities->component_mask[entity] == CMP_NONE)
{
return entity;
}
}
printf("Error: no more entities.\n");
return ENTITY_COUNT;
}
void destroy_entity(struct entities *_entities, unsigned int entity)
{
_entities->component_mask[entity] = CMP_NONE;
}
unsigned int create_player(struct entities *_entities, float x, float y)
{
unsigned int entity = create_entity(_entities);
_entities->component_mask[entity] = CMP_POSITION | CMP_COLLISION | CMP_RENDER | CMP_INPUT_PLAYER;
_entities->positions[entity].x = x;
_entities->positions[entity].y = y;
_entities->collisions[entity].x = x;
_entities->collisions[entity].y = y;
_entities->renders[entity].name = "player";
return entity;
}