diff --git a/src/entities/Player.py b/src/entities/Player.py index b84262e..f654149 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -6,6 +6,8 @@ import pygame class Player(Entity): + statistics: Statistics + def __init__(self, spawnpoint, size): super().__init__("player.jpg", size, (spawnpoint[0] * size, spawnpoint[1] * size)) # Where the player is facing, 0 - north, 1 @@ -41,6 +43,9 @@ class Player(Entity): return self.statistics.stamina return None + def getStatistics(self): + return self.statistics + def rotate(self, rotation): # If the player is not facing given direction, it will not move the first time, it will only get rotated if self.rotation.value != rotation.value: diff --git a/src/game/EventManager.py b/src/game/EventManager.py index 540b60d..7ee55b6 100644 --- a/src/game/EventManager.py +++ b/src/game/EventManager.py @@ -25,11 +25,14 @@ class EventManager: for event in pygame.event.get(): if event.type == pygame.QUIT: self.game.running = False + self.game.screen.ui.updateBasedOnPygameEvent(event) self.keyTimeout += self.keyTimer.tick() if self.keyTimeout >= TIMEOUT: 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 diff --git a/src/game/Game.py b/src/game/Game.py index 86e1643..ddc760a 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -10,6 +10,7 @@ from game.Map import Map from src.entities.Pickupable import Pickupable from src.entities.Player import Player from src.entities.Statistics import Statistics +from src.game.Timer import Timer class Game: @@ -40,6 +41,11 @@ class Game: print("The screen cannot be in a vertical orientation. Exiting...") exit(1) + # Initialize timers + self.pgTimer = pygame.time.Clock() + self.ingameTimer = Timer() + self.ingameTimer.startClock() + self.screen = Screen(self, self.config["window"]) print("OK") @@ -49,11 +55,12 @@ class Game: self.map.addEntity(self.player) self.eventManager = EventManager(self, self.player) - self.mainLoop() def mainLoop(self): while self.running: + # Update ingame clock + self.ingameTimer.updateTime(self.pgTimer.tick()) self.eventManager.handleEvents() self.spritesList.draw(self.screen.pygameScreen) pygame.display.flip() diff --git a/src/ui/Ui.py b/src/ui/Ui.py index ec88a58..a68b3bf 100644 --- a/src/ui/Ui.py +++ b/src/ui/Ui.py @@ -2,6 +2,7 @@ from enum import Enum import pygame +from src.entities.Statistics import Statistics from src.ui.UiBar import UiBar from src.ui.UiConsole import UiConsole from src.ui.UiText import UiText @@ -50,6 +51,17 @@ class Ui(): screenHeight - self.timerTextView.rect.h - self.isDayTextView.rect.h), 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) + + def updateBasedOnPygameEvent(self, event: pygame.event): + pass + + + class Colors(Enum): RED = (255, 0, 0)