From a60a46cc5362bd6f09f12ebe63d0795fc1a8bed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 5 Apr 2020 23:43:40 +0200 Subject: [PATCH 1/4] Add method returning stats field from Player --- src/entities/Player.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/entities/Player.py b/src/entities/Player.py index a7aba49..9a3a2d7 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 @@ -36,6 +38,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: From 0fb5f925d247afe105aa7cac188cf580e3850b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 5 Apr 2020 23:44:31 +0200 Subject: [PATCH 2/4] Add method updating ui based on player stats --- src/ui/Ui.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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) From 17125f9dd96319f80223c8c41868dde626cd8eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 5 Apr 2020 23:45:19 +0200 Subject: [PATCH 3/4] Add passing events, stats to update Ui when handling events --- src/game/EventManager.py | 3 +++ 1 file changed, 3 insertions(+) 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 From f7fb38b7ff77b186f35c26973da81cb67bb435f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 5 Apr 2020 23:51:22 +0200 Subject: [PATCH 4/4] Bring timer back to Game class --- src/game/Game.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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()