Add chase/evade behaviour
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "entity_factory.h"
|
||||
|
||||
#include "ai_actions.h"
|
||||
#include "systems/systems.h"
|
||||
|
||||
ecs_entity_t entityCreateEmpty() {
|
||||
ecs_entity_t e = ecs_new_id(ECS);
|
||||
@@ -18,7 +19,10 @@ ecs_entity_t entityCreateBaseUnit(const Position position, f32 size, Player play
|
||||
};
|
||||
HitBox hitbox = getEntityHitBoxRec(tileID);
|
||||
ecs_entity_t e = entityCreateEmpty();
|
||||
ecs_set_ptr(ECS, e, Position, &position);
|
||||
ecs_set(ECS, e, Position, {
|
||||
position.x - size * 0.5f,
|
||||
position.y + size * 0.5f,
|
||||
});
|
||||
f32 scl = size / region.rec.width;
|
||||
ecs_set(ECS, e, Size, {region.rec.width * scl, region.rec.height * scl});
|
||||
hitbox.x *= scl;
|
||||
@@ -86,6 +90,9 @@ ecs_entity_t entityCreateSoldier(const Position position, Player player, Game *g
|
||||
unit.maxDamage = 10.0f;
|
||||
unit.attackCooldown = 1.0f;
|
||||
ecs_set_ptr(ECS, e, Unit, &unit);
|
||||
setAIBehaviour(e, game->BTs.unit, &(AIBlackboard) {
|
||||
.moveToPos = position,
|
||||
});
|
||||
return e;
|
||||
}
|
||||
ecs_entity_t entityCreateWarrior(const Position position, Player player, Game *game) {
|
||||
@@ -100,6 +107,9 @@ ecs_entity_t entityCreateWarrior(const Position position, Player player, Game *g
|
||||
unit.maxDamage = 22.0f;
|
||||
unit.attackCooldown = 1.8f;
|
||||
ecs_set_ptr(ECS, e, Unit, &unit);
|
||||
setAIBehaviour(e, game->BTs.unit, &(AIBlackboard) {
|
||||
.moveToPos = position,
|
||||
});
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -118,6 +128,10 @@ ecs_entity_t entityCreateWorker(const Position position, Player player, Game *ga
|
||||
.lastChanged = -1000.0f
|
||||
});
|
||||
|
||||
setAIBehaviour(e, game->BTs.unit, &(AIBlackboard) {
|
||||
.moveToPos = position,
|
||||
});
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user