TimedBooBlock.gd 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. class_name TimedBooBlock
  2. extends Block
  3. var time := 3
  4. var active := false
  5. static var main_block = null
  6. static var can_tick := true:
  7. set(value):
  8. can_tick = value
  9. func _ready() -> void:
  10. main_block = self
  11. $Timer.start()
  12. func on_timeout() -> void:
  13. if can_tick == false or BooRaceHandler.countdown_active: return
  14. time = clamp(time - 1, 0, 3)
  15. if main_block == self:
  16. if time <= 0:
  17. get_tree().call_group("BooBlocks", "on_switch_hit")
  18. elif time < 3:
  19. AudioManager.play_global_sfx("timer_beep")
  20. if active:
  21. $Sprite.play("On" + str(time))
  22. else:
  23. $Sprite.play("Off" + str(time))
  24. func block_hit() -> void:
  25. if not can_hit:
  26. return
  27. can_hit = false
  28. get_tree().call_group("BooBlocks", "on_switch_hit")
  29. await get_tree().create_timer(0.25, false).timeout
  30. can_hit = true
  31. func _exit_tree() -> void:
  32. can_tick = true
  33. func on_switch_hit() -> void:
  34. AudioManager.play_global_sfx("switch")
  35. $Timer.stop()
  36. time = 4
  37. active = not active
  38. if active:
  39. $Sprite.play("BlueToRed")
  40. else:
  41. $Sprite.play("RedToBlue")
  42. await $Sprite.animation_finished
  43. $Timer.start()
  44. time = 4
  45. on_timeout()