tool
extends Node2D
var triggerd = false

export(int, -360, 360) var direction = 1 setget set_direction
export(float, 0, 120) var cooldown_timeout = 2


func _on_DamageArea_body_entered(body: Node) -> void:
  if body.name == "Player":
    body.die()
    body.boost(Vector2(150, 0))

func _on_TriggerArea_body_entered(body: Node) -> void:
  if body.name == "Player" and not triggerd:
    AudioManager.play_sfx(AudioManager.Sfx.SPIKE_TRAP)
    triggerd = true
    $AnimationPlayer.play("emit")
    yield($AnimationPlayer, "animation_finished")
    yield(get_tree().create_timer(.3), "timeout")
    $AnimationPlayer.play_backwards("emit")
    $CoolDownTimer.start(cooldown_timeout)
func set_direction(new_direction):
  self.rotation_degrees = new_direction

func _on_CoolDownTimer_timeout():
  triggerd = false
