From 01511757a0fe0bdebb4ac0cc33d3d5accf5022b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Mon, 6 Apr 2020 13:13:28 +0200 Subject: [PATCH 1/7] Change console updates Added updateOnPlayerPickup method and modified updateBasedOnPlayerStats so that is used in former method. Now info is written only on player pickup so that there is no spam. --- src/ui/Ui.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ui/Ui.py b/src/ui/Ui.py index dcdfd31..7d9f6dd 100644 --- a/src/ui/Ui.py +++ b/src/ui/Ui.py @@ -64,24 +64,20 @@ class Ui(): def updateBasedOnPlayerStats(self, statistics: Statistics): consoleLines = [] - if self.healthBar.value != statistics.hp: - self.healthBar.updateFill(statistics.hp) - consoleLines.append(self.timer.getPrettyTime() + " - Health: " + str(statistics.hp)) - if self.hungerBar.value != statistics.hunger: - self.hungerBar.updateFill(statistics.hunger) - consoleLines.append(self.timer.getPrettyTime() + " - Hunger: " + str(statistics.hunger)) + self.healthBar.updateFill(statistics.hp) + consoleLines.append("Health: " + str(statistics.hp)) - if self.staminaBar.value != statistics.stamina: - self.staminaBar.updateFill(statistics.stamina) - consoleLines.append(self.timer.getPrettyTime() + " - Stamina: " + str(statistics.stamina)) + self.hungerBar.updateFill(statistics.hunger) + consoleLines.append("Hunger: " + str(statistics.hunger)) - if self.thirstBar.value != statistics.thirst: - self.thirstBar.updateFill(statistics.thirst) - consoleLines.append(self.timer.getPrettyTime() + " - Thirst: " + str(statistics.thirst)) + self.staminaBar.updateFill(statistics.stamina) + consoleLines.append("Stamina: " + str(statistics.stamina)) - if len(consoleLines) > 0: - self.console.addLinesToConsoleAndScrollToDisplayThem(consoleLines) + self.thirstBar.updateFill(statistics.thirst) + consoleLines.append("Thirst: " + str(statistics.thirst)) + + self.console.addLinesToConsoleAndScrollToDisplayThem(consoleLines) def updateBasedOnPygameEvent(self, event: pygame.event): if event.type == pygame.MOUSEBUTTONDOWN: @@ -91,6 +87,10 @@ class Ui(): elif event.button == 5: console.writeConsoleLines(console.topWrittenLineInd - 1) + def updateOnPlayerPickup(self, playerStats, pickedObject): + self.console.addLinesToConsoleAndScrollToDisplayThem([self.timer.getPrettyTime() + " - Picked object " + str(pickedObject.id) + ":"]) + self.updateBasedOnPlayerStats(playerStats) + def updateTime(self): self.timerTextView.changeText(self.timer.getPrettyTime()) if self.timer.isItDay(): From 156f9977e07fe68cc0f9f72c229c0a8e4c10cead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Mon, 6 Apr 2020 13:13:47 +0200 Subject: [PATCH 2/7] Add ui updates on player pickup in EventManager --- src/game/EventManager.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 7975494..508dc06 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -35,8 +35,6 @@ class EventManager: self.handlePlayerControls(keys) self.keyTimeout = 0 - self.game.screen.ui.updateBasedOnPlayerStats(self.player.statistics) - def handlePlayerControls(self, keys): # Key names are temporary # TODO: Load key bindings from JSON @@ -48,6 +46,7 @@ class EventManager: # Picked up item gets removed from the map if type(object) is Pickupable: object.on_interaction(self.player) + self.game.screen.ui.updateOnPlayerPickup(self.player.statistics, object) self.game.map.removeSpriteFromMap(object) elif type(object) is Interactable: object.on_interaction(self.player) From 178115cc4d7fba01914c2be2cd7c6bc2f6ddf5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Mon, 6 Apr 2020 13:20:04 +0200 Subject: [PATCH 3/7] Add method updating console on player interaction in Ui and fix bar updating --- src/ui/Ui.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/ui/Ui.py b/src/ui/Ui.py index 7d9f6dd..f75b6b8 100644 --- a/src/ui/Ui.py +++ b/src/ui/Ui.py @@ -62,23 +62,17 @@ class Ui(): screenHeight - self.timerTextView.rect.h - self.isDayTextView.rect.h), font=self.font) - def updateBasedOnPlayerStats(self, statistics: Statistics): - consoleLines = [] - - self.healthBar.updateFill(statistics.hp) - consoleLines.append("Health: " + str(statistics.hp)) - - self.hungerBar.updateFill(statistics.hunger) - consoleLines.append("Hunger: " + str(statistics.hunger)) - - self.staminaBar.updateFill(statistics.stamina) - consoleLines.append("Stamina: " + str(statistics.stamina)) - - self.thirstBar.updateFill(statistics.thirst) - consoleLines.append("Thirst: " + str(statistics.thirst)) - + def updateConsoleBasedOnPlayerStats(self, statistics: Statistics): + consoleLines = ["Health: " + str(statistics.hp), "Hunger: " + str(statistics.hunger), + "Stamina: " + str(statistics.stamina), "Thirst: " + str(statistics.thirst)] self.console.addLinesToConsoleAndScrollToDisplayThem(consoleLines) + def updateBarsBasedOnPlayerStats(self, statistics: Statistics): + self.healthBar.updateFill(statistics.hp) + self.hungerBar.updateFill(statistics.hunger) + self.staminaBar.updateFill(statistics.stamina) + self.thirstBar.updateFill(statistics.thirst) + def updateBasedOnPygameEvent(self, event: pygame.event): if event.type == pygame.MOUSEBUTTONDOWN: console = self.console @@ -89,7 +83,11 @@ class Ui(): def updateOnPlayerPickup(self, playerStats, pickedObject): self.console.addLinesToConsoleAndScrollToDisplayThem([self.timer.getPrettyTime() + " - Picked object " + str(pickedObject.id) + ":"]) - self.updateBasedOnPlayerStats(playerStats) + self.updateConsoleBasedOnPlayerStats(playerStats) + + def updateOnPlayerInteraction(self, playerStats, interactedObject): + self.console.addLinesToConsoleAndScrollToDisplayThem([self.timer.getPrettyTime() + " - Player interacted with " + str(interactedObject.id) + ":"]) + self.updateConsoleBasedOnPlayerStats(playerStats) def updateTime(self): self.timerTextView.changeText(self.timer.getPrettyTime()) From b22e69712cceaa877d8e4592af512a8859792b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Mon, 6 Apr 2020 13:20:28 +0200 Subject: [PATCH 4/7] Add updating ui bars and updating console on interaction in EventManager --- src/game/EventManager.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 508dc06..66e8023 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -35,6 +35,8 @@ class EventManager: self.handlePlayerControls(keys) self.keyTimeout = 0 + self.game.screen.ui.updateBarsBasedOnPlayerStats(self.player.statistics) + def handlePlayerControls(self, keys): # Key names are temporary # TODO: Load key bindings from JSON @@ -50,6 +52,7 @@ class EventManager: self.game.map.removeSpriteFromMap(object) elif type(object) is Interactable: object.on_interaction(self.player) + self.game.screen.ui.updateOnPlayerInteraction(self.player.statistics, object) # Movement if keys[pygame.K_w]: From 9d8768cb1540782182328cc656c576a83ce97473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Mon, 6 Apr 2020 13:41:33 +0200 Subject: [PATCH 5/7] Add method updating console on player's death --- src/ui/Ui.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/ui/Ui.py b/src/ui/Ui.py index f75b6b8..4a87745 100644 --- a/src/ui/Ui.py +++ b/src/ui/Ui.py @@ -2,6 +2,7 @@ from enum import Enum import pygame +from src.entities.Player import StatisticNames from src.entities.Statistics import Statistics from src.ui.UiBar import UiBar from src.ui.UiConsole import UiConsole @@ -89,6 +90,28 @@ class Ui(): self.console.addLinesToConsoleAndScrollToDisplayThem([self.timer.getPrettyTime() + " - Player interacted with " + str(interactedObject.id) + ":"]) self.updateConsoleBasedOnPlayerStats(playerStats) + def updateOnDeath(self, player): + consoleLines = [] + + deathReason: StatisticNames = player.deathReason + + consoleLines.append(self.timer.getPrettyTime() + " - Game Over") + deathReasonString = "" + if deathReason is StatisticNames.HP: + deathReasonString = "Health issues" + elif deathReason is StatisticNames.HUNGER: + deathReasonString = "Hunger" + elif deathReason is StatisticNames.STAMINA: + deathReasonString = "Exhaustion" + elif deathReason is StatisticNames.THIRST: + deathReasonString = "Dehydration" + + consoleLines.append("Death reason: " + deathReasonString) + + consoleLines.append("Time alive: " + str(player.timeAlive / 1000)) + + self.console.addLinesToConsoleAndScrollToDisplayThem(consoleLines) + def updateTime(self): self.timerTextView.changeText(self.timer.getPrettyTime()) if self.timer.isItDay(): From deec08cec7a8ddb8bb09fea1ed5ae465d255c823 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Mon, 6 Apr 2020 13:42:56 +0200 Subject: [PATCH 6/7] Changed alive checking --- src/game/EventManager.py | 64 +++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 66e8023..0a9cb43 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -1,3 +1,5 @@ +from time import sleep + import pygame from src.entities.Interactable import Interactable @@ -32,8 +34,9 @@ class EventManager: self.game.screen.ui.updateBasedOnPygameEvent(event) self.keyTimeout += self.keyTimer.tick() if self.keyTimeout >= TIMEOUT: - self.handlePlayerControls(keys) - self.keyTimeout = 0 + if self.player.alive: + self.handlePlayerControls(keys) + self.keyTimeout = 0 self.game.screen.ui.updateBarsBasedOnPlayerStats(self.player.statistics) @@ -41,36 +44,35 @@ class EventManager: # Key names are temporary # TODO: Load key bindings from JSON - if self.player.alive: - # Picking up items - if keys[pygame.K_SPACE]: - object = self.game.map.getEntityOnCoord(self.player.getFacingCoord()) - # Picked up item gets removed from the map - if type(object) is Pickupable: - object.on_interaction(self.player) - self.game.screen.ui.updateOnPlayerPickup(self.player.statistics, object) - self.game.map.removeSpriteFromMap(object) - elif type(object) is Interactable: - object.on_interaction(self.player) - self.game.screen.ui.updateOnPlayerInteraction(self.player.statistics, object) + # Picking up items + if keys[pygame.K_SPACE]: + object = self.game.map.getEntityOnCoord(self.player.getFacingCoord()) + # Picked up item gets removed from the map + if type(object) is Pickupable: + object.on_interaction(self.player) + self.game.screen.ui.updateOnPlayerPickup(self.player.statistics, object) + self.game.map.removeSpriteFromMap(object) + elif type(object) is Interactable: + object.on_interaction(self.player) + self.game.screen.ui.updateOnPlayerInteraction(self.player.statistics, object) - # Movement - if keys[pygame.K_w]: - self.player.rotate(Rotations.NORTH) - if not self.game.map.collision(self.player.rect.x, self.player.rect.y - self.player.rect.w): - self.player.move(Rotations.NORTH) - if keys[pygame.K_s]: - self.player.rotate(Rotations.SOUTH) - if not self.game.map.collision(self.player.rect.x, self.player.rect.y + self.player.rect.w): - self.player.move(Rotations.SOUTH) - if keys[pygame.K_d]: - self.player.rotate(Rotations.EAST) - if not self.game.map.collision(self.player.rect.x + self.player.rect.w, self.player.rect.y): - self.player.move(Rotations.EAST) - if keys[pygame.K_a]: - self.player.rotate(Rotations.WEST) - if not self.game.map.collision(self.player.rect.x - self.player.rect.w, self.player.rect.y): - self.player.move(Rotations.WEST) + # Movement + if keys[pygame.K_w]: + self.player.rotate(Rotations.NORTH) + if not self.game.map.collision(self.player.rect.x, self.player.rect.y - self.player.rect.w): + self.player.move(Rotations.NORTH) + if keys[pygame.K_s]: + self.player.rotate(Rotations.SOUTH) + if not self.game.map.collision(self.player.rect.x, self.player.rect.y + self.player.rect.w): + self.player.move(Rotations.SOUTH) + if keys[pygame.K_d]: + self.player.rotate(Rotations.EAST) + if not self.game.map.collision(self.player.rect.x + self.player.rect.w, self.player.rect.y): + self.player.move(Rotations.EAST) + if keys[pygame.K_a]: + self.player.rotate(Rotations.WEST) + if not self.game.map.collision(self.player.rect.x - self.player.rect.w, self.player.rect.y): + self.player.move(Rotations.WEST) From 3f7ed1e4b3173a82b19b449dc110b93b9d57f39c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Mon, 6 Apr 2020 13:48:36 +0200 Subject: [PATCH 7/7] Add updating console on players death and closing game after time delay --- src/game/EventManager.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 0a9cb43..ef84a55 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -16,6 +16,8 @@ class EventManager: self.game = gameObject self.player = player self.keyTimer = pygame.time.Clock() + + self.turnOff = False # Player controls # TODO @@ -25,6 +27,10 @@ class EventManager: def handleEvents(self): pygame.event.pump() + if self.turnOff: + sleep(5) + exit(0) + self.game.screen.ui.updateTime() keys = pygame.key.get_pressed() @@ -37,6 +43,9 @@ class EventManager: if self.player.alive: self.handlePlayerControls(keys) self.keyTimeout = 0 + else: + self.game.screen.ui.updateOnDeath(self.player) + self.turnOff = True self.game.screen.ui.updateBarsBasedOnPlayerStats(self.player.statistics)