extends Node2D

export var speed := 230

var _fly := true
var _pin_angle := 0

func _ready() -> void:
  GameState.connect("player_just_died", self,"queue_free")
  seed(self.get_instance_id())
  var options = range(-30, 30, 5)
  options.shuffle()
  _pin_angle = options[0]

func _physics_process(delta: float) -> void:
  if _fly:
	  position.x += speed * scale.x * delta

func _on_HitZone_body_entered(body:Node) -> void:
  remove_child($HitZone)
  if body.name == "Player":
	  body.die()
  _fly = false
  $AnimationPlayer.play("fade_out")

  pass

func _on_PinZone_body_entered(body:Node) -> void:
  remove_child($HitZone)
  rotation_degrees = _pin_angle
  print(rotation_degrees)
  _fly = false
  yield(get_tree().create_timer(5), "timeout")
  $AnimationPlayer.play("fade_out")
  pass
