47 lines
836 B
C
47 lines
836 B
C
#include "entity.h"
|
|
#include <gint/display.h>
|
|
|
|
struct Entity *g_entity_grid[ENTITY_GRID_SIZE];
|
|
|
|
void
|
|
entity_init(void *restrict entity, int x, int y, int hb_x, int hb_y, int hb_w,
|
|
int hb_h, color_t hb_color)
|
|
{
|
|
static int init_grid = 1;
|
|
struct Entity *const e = entity;
|
|
int i;
|
|
e->x = x;
|
|
e->y = y;
|
|
e->hb_x = hb_x;
|
|
e->hb_y = hb_y;
|
|
e->hb_w = hb_w;
|
|
e->hb_h = hb_h;
|
|
e->hb_color = hb_color;
|
|
|
|
if (init_grid) {
|
|
init_grid = 0;
|
|
i = ENTITY_GRID_SIZE;
|
|
while (i-- > 0)
|
|
g_entity_grid[i] = NULL;
|
|
}
|
|
|
|
/* add to grid */
|
|
i = ENTITY_GRID_SIZE;
|
|
while (i-- > 0)
|
|
if (g_entity_grid[i] == NULL)
|
|
break;
|
|
g_entity_grid[i] = entity;
|
|
}
|
|
|
|
void
|
|
entity_deinit(void *restrict entity)
|
|
{
|
|
int i;
|
|
/* remove from grid */
|
|
i = ENTITY_GRID_SIZE;
|
|
while (i-- > 0)
|
|
if (g_entity_grid[i] == entity)
|
|
break;
|
|
g_entity_grid[i] = NULL;
|
|
}
|