BooOnOffSwitch.gd 670 B

123456789101112131415161718192021222324252627282930313233
  1. extends Block
  2. var active := false
  3. static var has_hit := false
  4. func _ready() -> void:
  5. can_hit = true
  6. has_hit = false
  7. func on_block_hit() -> void:
  8. if can_hit == false or has_hit:
  9. return
  10. has_hit = true
  11. AudioManager.play_sfx("switch", global_position)
  12. can_hit = false
  13. get_tree().call_group("BooBlocks", "on_switch_hit")
  14. await get_tree().create_timer(0.25, false).timeout
  15. can_hit = true
  16. has_hit = false
  17. func on_switch_hit() -> void:
  18. active = not active
  19. if active:
  20. $Sprite.play("On")
  21. else:
  22. $Sprite.play("Off")
  23. func on_boo_hit() -> void:
  24. if active:
  25. return
  26. AudioManager.play_global_sfx("switch")
  27. get_tree().call_group("BooBlocks", "on_switch_hit")