diff options
Diffstat (limited to 'Scripts/Enemy AI/JungleAI.gd')
-rw-r--r-- | Scripts/Enemy AI/JungleAI.gd | 48 |
1 files changed, 48 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 |