chocolate.gd 961 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. class_name Chocolate
  2. extends Node3D
  3. const COLLECT_ANIM := "collection"
  4. const COLLECT_DURATION := 2.0
  5. @onready var chocolateAnimation: AnimationPlayer = $ChocolateAnimation
  6. @onready var pickupSound: AudioStreamPlayer3D = $ChocolatePickupSound
  7. var _collected := false
  8. func _on_chocolate_tablet_body_entered(body: Node3D) -> void:
  9. if _collected:
  10. return
  11. if body is Walker:
  12. _give_chocolate_to(body)
  13. _collected = true
  14. func _give_chocolate_to(walker: Walker) -> void:
  15. walker.give_chocolate()
  16. _go_to.call_deferred(walker)
  17. chocolateAnimation.play(COLLECT_ANIM)
  18. chocolateAnimation.animation_finished.connect(_finish)
  19. pickupSound.play()
  20. func _go_to(walker: Walker) -> void:
  21. reparent(walker)
  22. var center_tween = create_tween()
  23. center_tween.tween_property(self, "position", walker.get_pocket_position(), COLLECT_DURATION)
  24. func _finish(animation_name: String) -> void:
  25. if COLLECT_ANIM == animation_name:
  26. # Collection is finished
  27. queue_free()