Spike.gd 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. extends Enemy
  2. const SPIKE_BALL = preload("uid://c7il83r4ab05d")
  3. @export var can_move := false
  4. func _ready() -> void:
  5. $ThrowTimer.start()
  6. if can_move:
  7. $TurnTimer.start()
  8. func _physics_process(delta: float) -> void:
  9. if can_move:
  10. $Movement.handle_movement(delta)
  11. else:
  12. $StaticMovement.handle_movement(delta)
  13. var target_player = get_tree().get_first_node_in_group("Players")
  14. var target_direction = sign(target_player.global_position.x - global_position.x)
  15. if target_direction != 0:
  16. direction = target_direction
  17. func throw_ball() -> void:
  18. $Movement.can_move = false
  19. %Animations.play("BallSpawn")
  20. await %Animations.animation_finished
  21. summon_ball()
  22. %Animations.play("Idle")
  23. $Movement.can_move = true
  24. func summon_ball() -> void:
  25. var ball = SPIKE_BALL.instantiate()
  26. ball.global_position = %Ball.global_position
  27. add_sibling(ball)
  28. ball.velocity.x = 100 * direction
  29. func on_timeout() -> void:
  30. if not $Movement.can_move: return
  31. var target_player = get_tree().get_first_node_in_group("Players")
  32. direction = sign(target_player.global_position.x - global_position.x)