From 6c7e2ac133986efa57b43df52a5498c6f7efcf75 Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 26 Aug 2025 22:59:57 -0300 Subject: AI --- scripts/actors/AI/HostileEnemyAI.cs | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 scripts/actors/AI/HostileEnemyAI.cs (limited to 'scripts/actors/AI/HostileEnemyAI.cs') 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 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 -- cgit v1.2.3