2023-03-17 10:51:17 +01:00
|
|
|
#include "game.h"
|
2023-03-17 13:45:20 +01:00
|
|
|
#include "map.h"
|
2023-03-17 10:51:17 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
game_init(Game *this)
|
|
|
|
{
|
|
|
|
memset(this, 0, sizeof(*this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
game_deinit(Game *this)
|
|
|
|
{
|
|
|
|
(void)this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
game_update(Game *this)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < MAX_ENTITIES; i++) {
|
|
|
|
Entity *const e = &this->entities[i];
|
|
|
|
if (e->type != ET_NONE && e->update != NULL)
|
|
|
|
e->update(e, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
game_draw(Game *this)
|
|
|
|
{
|
2023-03-17 13:45:20 +01:00
|
|
|
map_draw();
|
2023-03-17 10:51:17 +01:00
|
|
|
for (int i = 0; i < MAX_ENTITIES; i++) {
|
|
|
|
Entity *const e = &this->entities[i];
|
|
|
|
if (e->type != ET_NONE && e->draw != NULL)
|
|
|
|
e->draw(e, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Entity *
|
|
|
|
game_create_entity(Game *this)
|
|
|
|
{
|
|
|
|
Entity *e = &this->entities[MAX_ENTITIES - 1];
|
|
|
|
for (int i = 0; i < MAX_ENTITIES; i++)
|
|
|
|
if (this->entities[i].type == ET_NONE) {
|
|
|
|
e = &this->entities[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
e->type = ET_NONE;
|
|
|
|
e->uuid = this->uuid;
|
|
|
|
this->uuid += 1;
|
|
|
|
return e;
|
|
|
|
}
|