Add entity_factory
This commit is contained in:
46
game/entity_factory.c
Normal file
46
game/entity_factory.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "entity_factory.h"
|
||||
#include "unit_actions.h"
|
||||
|
||||
ecs_entity_t entityCreateEmpty() {
|
||||
ecs_entity_t e = ecs_new_id(ECS);
|
||||
ecs_add_id(ECS, e, GameEntity);
|
||||
return e;
|
||||
}
|
||||
|
||||
ecs_entity_t entityCreateWorker(const Position position, Game *game) {
|
||||
const Size size = {10.0f, 10.0f};
|
||||
BzTileset *tileset = &game->tileset;
|
||||
ecs_entity_t e = entityCreateEmpty();
|
||||
ecs_set_ptr(ECS, e, Position, &position);
|
||||
ecs_set_ptr(ECS, e, Size, &size);
|
||||
BzSpatialGridID spatialID = bzSpatialGridInsert(game->entityGrid, &e,
|
||||
position.x, position.y,
|
||||
size.x, size.y);
|
||||
ecs_set(ECS, e, SpatialGridID, { spatialID });
|
||||
ecs_set(ECS, e, Rotation, { 0.0f });
|
||||
ecs_set(ECS, e, Velocity, {});
|
||||
ecs_set(ECS, e, Steering, {});
|
||||
TextureRegion workerRegion = {
|
||||
tileset->tiles,
|
||||
bzTilesetGetTileRegion(tileset, ENTITY_WORKER)
|
||||
};
|
||||
ecs_set_ptr(ECS, e, TextureRegion, &workerRegion);
|
||||
ecs_set(ECS, e, Animation, {
|
||||
.entityType = ENTITY_WORKER,
|
||||
.animType = ANIM_IDLE,
|
||||
|
||||
.sequence = entityGetAnimationSequence(ENTITY_WORKER, ANIM_IDLE),
|
||||
.tileset = tileset,
|
||||
.curFrame = 0,
|
||||
.elapsed = 0.0f,
|
||||
});
|
||||
ecs_set(ECS, e, UnitAction, { NULL, NULL });
|
||||
ecs_add_id(ECS, e, Selectable);
|
||||
ecs_add_id(ECS, e, Unit);
|
||||
ecs_set(ECS, e, Worker, {
|
||||
.collectSpeed = 0.8f,
|
||||
.depositSpeed = 0.2f,
|
||||
.carryCapacity = 5,
|
||||
});
|
||||
return e;
|
||||
}
|
||||
Reference in New Issue
Block a user