summaryrefslogtreecommitdiff
path: root/Scripts/Enemy AI/ShoreAI.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts/Enemy AI/ShoreAI.gd')
-rw-r--r--Scripts/Enemy AI/ShoreAI.gd68
1 files changed, 68 insertions, 0 deletions
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