summaryrefslogtreecommitdiff
path: root/scripts/actors/AI
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/actors/AI')
-rw-r--r--scripts/actors/AI/BaseAI.cs20
-rw-r--r--scripts/actors/AI/BaseAI.cs.uid1
-rw-r--r--scripts/actors/AI/HostileEnemyAI.cs38
-rw-r--r--scripts/actors/AI/HostileEnemyAI.cs.uid1
4 files changed, 60 insertions, 0 deletions
diff --git a/scripts/actors/AI/BaseAI.cs b/scripts/actors/AI/BaseAI.cs
new file mode 100644
index 0000000..f9b5387
--- /dev/null
+++ b/scripts/actors/AI/BaseAI.cs
@@ -0,0 +1,20 @@
+using Godot;
+
+public abstract partial class BaseAI : Node {
+ protected Actor body;
+
+ public override void _Ready()
+ {
+ base._Ready();
+ body = GetParent<Actor>();
+ }
+
+ public abstract void Perform();
+
+ public Godot.Collections.Array<Vector2> GetPathTo(Vector2I destination) {
+ Godot.Collections.Array<Vector2> list = [];
+ Vector2[] path = body.Map_Data.Pathfinder.GetPointPath(body.GridPosition, destination);
+ list.AddRange(path);
+ return list;
+ }
+} \ No newline at end of file
diff --git a/scripts/actors/AI/BaseAI.cs.uid b/scripts/actors/AI/BaseAI.cs.uid
new file mode 100644
index 0000000..b23724c
--- /dev/null
+++ b/scripts/actors/AI/BaseAI.cs.uid
@@ -0,0 +1 @@
+uid://jgm5qk02hism
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
diff --git a/scripts/actors/AI/HostileEnemyAI.cs.uid b/scripts/actors/AI/HostileEnemyAI.cs.uid
new file mode 100644
index 0000000..0fa2c32
--- /dev/null
+++ b/scripts/actors/AI/HostileEnemyAI.cs.uid
@@ -0,0 +1 @@
+uid://db28cxff4pl3t