diff options
Diffstat (limited to 'scripts/actors/AI/HostileEnemyAI.cs')
| -rw-r--r-- | scripts/actors/AI/HostileEnemyAI.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/actors/AI/HostileEnemyAI.cs b/scripts/actors/AI/HostileEnemyAI.cs new file mode 100644 index 0000000..061295f --- /dev/null +++ b/scripts/actors/AI/HostileEnemyAI.cs @@ -0,0 +1,38 @@ +using Godot; + +public partial class HostileEnemyAI : BaseAI +{ + private Godot.Collections.Array<Vector2> path = []; + + public override void Perform() + { + Player target = body.Map_Data.Player; + Vector2I offset = target.GridPosition - body.GridPosition; + int distance = int.Max(int.Abs(offset.X), int.Abs(offset.Y)); + + Action action; + + if (body.Map_Data.GetTile(body.GridPosition).IsInView) { + if (distance <= 1) { + action = new MeleeAction(body, offset); + action.Perform(); + return; + } + path = GetPathTo(target.GridPosition); + GD.Print($"Arno Breker: {path}"); + path.RemoveAt(0); + } + + if (path.Count > 0) { + Vector2I destination = (Vector2I) path[0]; + GD.Print(destination); + if (body.Map_Data.GetBlockingActorAtPosition(destination) != null) { + return; + } + + action = new MovementAction(body, destination - body.GridPosition); + action.Perform(); + path.RemoveAt(0); + } + } +}
\ No newline at end of file |
