def update(self, dt: float) -> None: """Updates the state of the game world and determines if game is over. :param dt: Time since last frame. :return: None """ if not self._paused: self._level.update(dt) # If game is over, show game-over menu. if self._is_game_over(): if self._level.is_player_alive(): title = "Victory!" else: title = "Defeat" buttons = [{ 'action': self.enter, 'text': 'Play Again', 'size': 16, 'color': cfg.WHITE }, { 'action': self._main_menu, 'text': 'Main Menu', 'size': 16, 'color': cfg.WHITE }, { 'action': sys.exit, 'text': 'Exit', 'size': 16, 'color': cfg.WHITE }] self._game.ui.make_menu(title, 24, cfg.WHITE, buttons) Timer.pause_timers() self._paused = True
def _pause(self) -> None: """Toggles the pause mode of the game.""" if self._paused: self._game.ui.pop_menu() Timer.unpause_timers() else: buttons = [{ 'action': self._pause, 'text': 'Resume', 'size': 16, 'color': cfg.WHITE }, { 'action': self.enter, 'text': 'Restart', 'size': 16, 'color': cfg.WHITE }, { 'action': self._main_menu, 'text': 'Main Menu', 'size': 16, 'color': cfg.WHITE }] self._game.ui.make_menu("Game Paused", 24, cfg.WHITE, buttons) Timer.pause_timers() self._paused = not self._paused