From c88965de382717ffe09f2f581b6473245859dbdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 24 May 2020 13:58:33 +0200 Subject: [PATCH] Add pausing decision tree run --- src/game/Game.py | 66 ++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/src/game/Game.py b/src/game/Game.py index 222cb5d..6f9a11f 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -244,36 +244,46 @@ class Game: self.player = Player((6, 2), self.map.tileSize, Affinities(0.3, 0.6, 0.1, 0.5)) self.map.addEntity(self.player, DONTADD=True) + pause = False + # main loop without user input - while self.running: - # Tick the timers - self.ingameTimer.updateTime(self.pgTimer.tick()) - self.screen.ui.updateTime() - - # If player is dead write information to console and break main loop - if not self.player.alive: - self.screen.ui.updateOnDeath(self.player) - self.spritesList.update() - self.spritesList.draw(self.screen.pygameScreen) - pygame.display.flip() - break - - # Choose target for player using decision tree - if self.player.movementTarget is None: - self.player.gotoToTarget(survivalDecisionTree.pickEntity(self.player, self.map), self.map) - - self.screen.ui.updateBarsBasedOnPlayerStats(self.player.statistics) - - # Call update() method for each entity - self.spritesList.update() - - # Draw all sprites - self.spritesList.draw(self.screen.pygameScreen) - - # Flip the display - pygame.display.flip() - while True: + for event in pygame.event.get(): if event.type == pygame.QUIT: exit(0) + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_SPACE: + pause = not pause + + if pause or not self.running: + pass + + else: + # Tick the timers + self.ingameTimer.updateTime(self.pgTimer.tick()) + self.screen.ui.updateTime() + + # If player is dead write information to console and break main loop + if not self.player.alive: + self.screen.ui.updateOnDeath(self.player) + self.spritesList.update() + self.spritesList.draw(self.screen.pygameScreen) + pygame.display.flip() + self.running = False + + # Choose target for player using decision tree + if self.player.movementTarget is None: + self.player.gotoToTarget(survivalDecisionTree.pickEntity(self.player, self.map), self.map) + + self.screen.ui.updateBarsBasedOnPlayerStats(self.player.statistics) + + # Call update() method for each entity + self.spritesList.update() + + # Draw all sprites + self.spritesList.draw(self.screen.pygameScreen) + + # Flip the display + pygame.display.flip() +