diff --git a/src/entities/Player.py b/src/entities/Player.py index abd82bb..f1f90fe 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -28,9 +28,14 @@ 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: - pass + 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): if stat.value == StatisticNames.HP: diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 3960521..d8a3bca 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 @@ -38,7 +39,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): 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 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__()