freak-engine/src/entity/init.c

48 lines
832 B
C

#include "entity.h"
#include "layers.h"
#include <gint/display.h>
struct Entity *g_entity_grid[ENTITY_GRID_SIZE];
void
entity_init(struct Entity *e, int x, int y, int hb_x, int hb_y, int hb_w,
int hb_h, int layer, color_t hb_color)
{
static int init_grid = 1;
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->layer = layer;
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] = e;
}
void
entity_deinit(struct Entity *e)
{
int i;
/* remove from grid */
i = ENTITY_GRID_SIZE;
while (i-- > 0)
if (g_entity_grid[i] == e)
break;
g_entity_grid[i] = NULL;
}