eco2d/code/game/src/entity.c

39 lines
966 B
C
Raw Normal View History

2021-05-08 09:05:15 +00:00
#include "entity.h"
2021-07-27 15:57:50 +00:00
#include "entity_view.h"
2021-05-08 09:05:15 +00:00
#include "flecs/flecs.h"
#include "flecs/flecs_meta.h"
#include "librg.h"
2021-05-12 15:50:30 +00:00
#include "world/world.h"
2021-05-08 09:05:15 +00:00
2021-07-27 12:43:26 +00:00
#include "modules/components.h"
#include "modules/systems.h"
2021-05-08 09:05:15 +00:00
#include "zpl.h"
2021-07-28 09:49:09 +00:00
uint64_t entity_spawn(uint16_t class_id) {
2021-05-08 09:05:15 +00:00
ecs_entity_t e = ecs_new(world_ecs(), 0);
2021-08-09 13:35:47 +00:00
w_ecs_set(e, Velocity, {0});
w_ecs_set(e, Classify, { .id = class_id });
w_ecs_add(e, Walking);
Position *pos = w_ecs_get_mut(e, Position, NULL);
2021-07-26 15:53:18 +00:00
#if 1
pos->x=rand() % world_dim();
pos->y=rand() % world_dim();
#else
pos->x=350;
pos->y=88;
2021-07-26 15:53:18 +00:00
#endif
2021-07-27 15:57:50 +00:00
if (class_id != EKIND_SERVER) {
librg_entity_track(world_tracker(), e);
librg_entity_chunk_set(world_tracker(), e, librg_chunk_from_realpos(world_tracker(), pos->x, pos->y, 0));
}
2021-05-08 09:05:15 +00:00
return (uint64_t)e;
}
void entity_despawn(uint64_t ent_id) {
librg_entity_untrack(world_tracker(), ent_id);
ecs_delete(world_ecs(), ent_id);
}