summaryrefslogtreecommitdiff
path: root/Scripts/Enemy AI
diff options
context:
space:
mode:
authoraltaf-creator <dev@altafcreator.com>2025-10-20 01:43:48 +0800
committeraltaf-creator <dev@altafcreator.com>2025-10-20 01:43:48 +0800
commit466bec0b724632f6dd2e1555a7bd58ffc1dd0458 (patch)
treed6645ea11914edeec645299fa497a9e542dbaec7 /Scripts/Enemy AI
Jam version.
Diffstat (limited to 'Scripts/Enemy AI')
-rw-r--r--Scripts/Enemy AI/JungleAI.gd48
-rw-r--r--Scripts/Enemy AI/JungleAI.gd.uid1
-rw-r--r--Scripts/Enemy AI/ShoreAI.gd68
-rw-r--r--Scripts/Enemy AI/ShoreAI.gd.uid1
4 files changed, 118 insertions, 0 deletions
diff --git a/Scripts/Enemy AI/JungleAI.gd b/Scripts/Enemy AI/JungleAI.gd
new file mode 100644
index 0000000..cedb028
--- /dev/null
+++ b/Scripts/Enemy AI/JungleAI.gd
@@ -0,0 +1,48 @@
+extends Node
+
+var player : Entity = null
+
+@export var weapon : Node2D
+@export var pivot : Node2D
+@export var sprite : Node2D
+
+var delta_pos : Vector2
+
+var can_attack : bool = true
+
+func _on_detect_area_body_entered(body:Node2D) -> void:
+ print(body)
+ if body is Entity:
+ if body.is_player:
+ player = body
+
+var parent : Entity
+
+func _process(_delta: float) -> void:
+ parent = get_node("..")
+
+ if !player:
+ return
+
+ delta_pos = player.global_position - parent.global_position
+
+ var angle = rad_to_deg(atan2(delta_pos.y, delta_pos.x)) - 90
+ pivot.rotation_degrees = angle
+
+ if delta_pos.x < 0:
+ if pivot.position.x > 0: pivot.position.x *= -1
+ if pivot.scale.x > 0: pivot.scale.x *= -1
+ if sprite.scale.x > 0: sprite.scale.x *= -1
+ else:
+ if pivot.position.x < 0: pivot.position.x *= -1
+ if pivot.scale.x < 0: pivot.scale.x *= -1
+ if sprite.scale.x < 0: sprite.scale.x *= -1
+
+ if can_attack:
+ weapon.action()
+ $"AttackCooldown".start()
+ can_attack = false
+
+
+func _on_attack_cooldown_timeout() -> void:
+ can_attack = true
diff --git a/Scripts/Enemy AI/JungleAI.gd.uid b/Scripts/Enemy AI/JungleAI.gd.uid
new file mode 100644
index 0000000..dc5e0f4
--- /dev/null
+++ b/Scripts/Enemy AI/JungleAI.gd.uid
@@ -0,0 +1 @@
+uid://cahhmhibcdjcd
diff --git a/Scripts/Enemy AI/ShoreAI.gd b/Scripts/Enemy AI/ShoreAI.gd
new file mode 100644
index 0000000..16a3e04
--- /dev/null
+++ b/Scripts/Enemy AI/ShoreAI.gd
@@ -0,0 +1,68 @@
+extends Node
+
+var player : Entity = null
+var parent : Entity
+
+@export var weapon : Node2D
+@export var sprite : Node2D
+@export var animator : AnimationPlayer
+@export var walk_speed : float = 200
+
+var in_range : bool = false
+var can_attack : bool = true
+
+func _ready() -> void:
+ parent = get_node("..")
+ walk_speed = randf_range(walk_speed - 50, walk_speed + 50)
+
+var delta_pos : Vector2
+
+func _process(delta: float) -> void:
+ if !player:
+ return
+
+ delta_pos = player.global_position - parent.global_position
+
+ if delta_pos.x < 0:
+ if weapon.position.x > 0: weapon.position.x = -weapon.position.x
+ if weapon.scale.x > 0: weapon.scale.x = -1
+ if sprite.scale.x > 0: sprite.scale.x = -1
+ else:
+ if weapon.position.x < 0: weapon.position.x = -weapon.position.x
+ if weapon.scale.x < 0: weapon.scale.x = 1
+ if sprite.scale.x < 0: sprite.scale.x = 1
+
+ if in_range && can_attack:
+ weapon.action()
+ parent.linear_velocity.y = 2000
+ can_attack = false
+
+func _physics_process(delta: float) -> void:
+ if !in_range && parent.linear_velocity.y == 0 && player:
+ if delta_pos.x < 0:
+ parent.linear_velocity.x = -walk_speed
+ else:
+ parent.linear_velocity.x = walk_speed
+ animator.play("walk")
+ elif in_range:
+ animator.stop()
+
+func _on_area_2d_body_entered(body:Node2D) -> void:
+ print(body)
+ if body is Entity:
+ if body.is_player:
+ player = body
+ $"AttackCooldown".start()
+
+func _on_attack_area_body_entered(body: Node2D) -> void:
+ if body is Entity:
+ if body.is_player:
+ in_range = true
+
+func _on_attack_area_body_exited(body: Node2D) -> void:
+ if body is Entity:
+ if body.is_player:
+ in_range = false
+
+func _on_attack_cooldown_timeout() -> void:
+ can_attack = true
diff --git a/Scripts/Enemy AI/ShoreAI.gd.uid b/Scripts/Enemy AI/ShoreAI.gd.uid
new file mode 100644
index 0000000..2f42db4
--- /dev/null
+++ b/Scripts/Enemy AI/ShoreAI.gd.uid
@@ -0,0 +1 @@
+uid://n2vodoxhopnr