ufo_ast.gd 929 B

123456789101112131415161718192021222324252627282930313233343536
  1. extends UFO
  2. var speed = 200.0
  3. var damage = 0
  4. var timeout: Timer = Timer.new()
  5. var last_vector: Vector2 = Vector2(0, 0)
  6. func _ready():
  7. super()
  8. $NavigationAgent2D.set_target_desired_distance(0)
  9. $NavigationAgent2D.set_avoidance_enabled(false)
  10. timeout.set_wait_time(1000.0)
  11. add_child(timeout)
  12. timeout.start()
  13. timeout.connect("timeout", _on_timeout)
  14. func _physics_process(delta: float):
  15. if target != null:
  16. var dist = target.get_global_position() - get_global_position()
  17. if dist.length() < 60.0:
  18. target.deal_damage(dps, null)
  19. get_parent().remove_child(self)
  20. queue_free()
  21. last_vector = dist.normalized()
  22. velocity = last_vector * speed
  23. else:
  24. get_parent().remove_child(self)
  25. queue_free()
  26. $Plx/Top.rotate(delta)
  27. move_and_slide()
  28. func _on_timeout():
  29. get_parent().remove_child(self)
  30. queue_free()