extends UFO

var speed = 200.0
var damage = 0
var timeout: Timer = Timer.new()
var last_vector: Vector2 = Vector2(0, 0)

func fuck():
    return true

func _ready():
    super()
    $NavigationAgent2D.set_target_desired_distance(0)
    $NavigationAgent2D.set_avoidance_enabled(false)
    timeout.set_wait_time(1000.0)
    add_child(timeout)
    timeout.start()
    timeout.connect("timeout", _on_timeout)
   
func _physics_process(delta: float):
    super(delta)
    if target != null:
        var dist = target.get_global_position() - get_global_position()
        if dist.length() < 60.0:
            target.deal_damage(dps, null)
            get_parent().remove_child(self)
            queue_free()
        if dist.length() > 2500:
            speed = 2000.0
        else:
            speed = 200.0
        last_vector = dist.normalized()
        velocity = last_vector * speed
    else:
        call_deferred("die")

    $Plx/Top.rotate(delta)
    move_and_slide()

func _on_timeout():
    get_parent().remove_child(self)
    queue_free()
    
func die():
    get_parent().remove_child(self)
    queue_free()


