Freezer.gd 630 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. extends Node
  2. # Manage game state
  3. enum State {IDLE, GAMING}
  4. var _current_state = State.IDLE
  5. func _ready():
  6. randomize() # Plant seed for random number generation
  7. func trigger_pause():
  8. if _pausable():
  9. _toggle_pause()
  10. func _unhandled_input(event: InputEvent):
  11. if event.is_action_pressed("ui_accept"):
  12. print("Trigger pause")
  13. trigger_pause()
  14. func _pausable():
  15. return _current_state == State.GAMING
  16. func _toggle_pause():
  17. var previous := get_tree().is_paused()
  18. get_tree().set_pause(!previous)
  19. func _on_Main_game_over():
  20. _current_state = State.IDLE
  21. func _on_Main_game_started():
  22. _current_state = State.GAMING