Add chase/evade behaviour

This commit is contained in:
2024-02-13 18:27:53 +01:00
parent e6ddafd3e2
commit 24abf94faa
8 changed files with 189 additions and 59 deletions

View File

@@ -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;
}