Add pausing decision tree run

This commit is contained in:
Michał Czekański 2020-05-24 13:58:33 +02:00
parent 5f7cd0dce7
commit c88965de38

View File

@ -244,36 +244,46 @@ class Game:
self.player = Player((6, 2), self.map.tileSize, Affinities(0.3, 0.6, 0.1, 0.5)) self.player = Player((6, 2), self.map.tileSize, Affinities(0.3, 0.6, 0.1, 0.5))
self.map.addEntity(self.player, DONTADD=True) self.map.addEntity(self.player, DONTADD=True)
pause = False
# main loop without user input # 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: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
exit(0) 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()