From 30896285db0165229244046c57d44a5c71ed1ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Mon, 6 Apr 2020 00:06:19 +0200 Subject: [PATCH 1/4] Add value field in Bar class --- src/ui/UiBar.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui/UiBar.py b/src/ui/UiBar.py index 2112573..8475395 100644 --- a/src/ui/UiBar.py +++ b/src/ui/UiBar.py @@ -13,6 +13,7 @@ class UiBar(UiElement): self.outlineColor = outlineColor self.outlineThickness = outlineThickness self.filledBarColor = filledBarColor + self.value = initialFilledPercent self.__genBar__() @@ -27,4 +28,5 @@ class UiBar(UiElement): def updateFill(self, filledPercent): self.filledPercent = filledPercent / 100 + self.value = filledPercent self.__genBar__() From 679cc3f9f42348520af5fd16b802754ac57c9b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Mon, 6 Apr 2020 00:10:40 +0200 Subject: [PATCH 2/4] Add writing to console when player stats change --- src/ui/Ui.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/ui/Ui.py b/src/ui/Ui.py index 394c2e8..7c50c6f 100644 --- a/src/ui/Ui.py +++ b/src/ui/Ui.py @@ -63,10 +63,24 @@ class Ui(): font=self.font) def updateBasedOnPlayerStats(self, statistics: Statistics): - self.healthBar.updateFill(statistics.hp) - self.hungerBar.updateFill(statistics.hunger) - self.staminaBar.updateFill(statistics.stamina) - self.thirstBar.updateFill(statistics.thirst) + consoleLines = [] + if self.healthBar.value != statistics.hp: + self.healthBar.updateFill(statistics.hp) + consoleLines.append("Health: " + str(statistics.hp)) + + if self.hungerBar.value != statistics.hunger: + self.hungerBar.updateFill(statistics.hunger) + consoleLines.append("Hunger: " + str(statistics.hunger)) + + if self.staminaBar.value != statistics.stamina: + self.staminaBar.updateFill(statistics.stamina) + consoleLines.append("Stamina: " + str(statistics.stamina)) + + if self.thirstBar.value != statistics.thirst: + self.thirstBar.updateFill(statistics.thirst) + consoleLines.append("Stamina: " + str(statistics.thirst)) + + self.console.addLinesToConsoleAndScrollToDisplayThem(consoleLines) def updateBasedOnPygameEvent(self, event: pygame.event): pass From a45befd4fa2d5a8f0c015896b4f43d685379a6cf Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Mon, 6 Apr 2020 00:39:58 +0200 Subject: [PATCH 3/4] Implemented getFacingCoord method --- src/entities/Player.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/entities/Player.py b/src/entities/Player.py index f654149..e69c3f2 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -28,8 +28,13 @@ class Player(Entity): def getFacingCoord(self): if self.rotation == Rotations.NORTH: - return (0, -1) + return self.rect.x, self.rect.y - (self.rect.h) elif self.rotation == Rotations.SOUTH: + return self.rect.x, self.rect.y + (self.rect.h) + elif self.rotation == Rotations.EAST: + return self.rect.x + (self.rect.h), self.rect.y + elif self.rotation == Rotations.WEST: + return self.rect.x - (self.rect.h), self.rect.y # Returns given statistic def getStatistic(self, stat): From bc8474b4c531905eb769eab5266b003836f1614a Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Mon, 6 Apr 2020 00:40:16 +0200 Subject: [PATCH 4/4] Player can now pick up items --- src/game/EventManager.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 7ee55b6..313a0b8 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -1,5 +1,6 @@ import pygame +from src.entities.Pickupable import Pickupable from src.entities.Player import Rotations # Player can move every given milliseconds @@ -36,7 +37,11 @@ class EventManager: def handlePlayerControls(self, keys): # Key names are temporary # TODO: Load key bindings from JSON - + if keys[pygame.K_SPACE]: + object = self.game.map.getEntityOnCoord(self.player.getFacingCoord()) + if type(object) is Pickupable: + object.on_pickup(self.player) + self.game.map.removeSpriteFromMap(object) 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):