Merge remote-tracking branch 'origin/passingEvents' into passingEvents
This commit is contained in:
commit
05ce54933d
@ -6,6 +6,8 @@ import pygame
|
|||||||
|
|
||||||
|
|
||||||
class Player(Entity):
|
class Player(Entity):
|
||||||
|
statistics: Statistics
|
||||||
|
|
||||||
def __init__(self, spawnpoint, size):
|
def __init__(self, spawnpoint, size):
|
||||||
super().__init__("player.jpg", size, (spawnpoint[0] * size, spawnpoint[1] * size))
|
super().__init__("player.jpg", size, (spawnpoint[0] * size, spawnpoint[1] * size))
|
||||||
# Where the player is facing, 0 - north, 1
|
# Where the player is facing, 0 - north, 1
|
||||||
@ -41,6 +43,9 @@ class Player(Entity):
|
|||||||
return self.statistics.stamina
|
return self.statistics.stamina
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def getStatistics(self):
|
||||||
|
return self.statistics
|
||||||
|
|
||||||
def rotate(self, rotation):
|
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 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:
|
if self.rotation.value != rotation.value:
|
||||||
|
@ -25,11 +25,14 @@ class EventManager:
|
|||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
self.game.running = False
|
self.game.running = False
|
||||||
|
self.game.screen.ui.updateBasedOnPygameEvent(event)
|
||||||
self.keyTimeout += self.keyTimer.tick()
|
self.keyTimeout += self.keyTimer.tick()
|
||||||
if self.keyTimeout >= TIMEOUT:
|
if self.keyTimeout >= TIMEOUT:
|
||||||
self.handlePlayerControls(keys)
|
self.handlePlayerControls(keys)
|
||||||
self.keyTimeout = 0
|
self.keyTimeout = 0
|
||||||
|
|
||||||
|
self.game.screen.ui.updateBasedOnPlayerStats(self.player.statistics)
|
||||||
|
|
||||||
def handlePlayerControls(self, keys):
|
def handlePlayerControls(self, keys):
|
||||||
# Key names are temporary
|
# Key names are temporary
|
||||||
# TODO: Load key bindings from JSON
|
# TODO: Load key bindings from JSON
|
||||||
|
@ -10,6 +10,7 @@ from game.Map import Map
|
|||||||
from src.entities.Pickupable import Pickupable
|
from src.entities.Pickupable import Pickupable
|
||||||
from src.entities.Player import Player
|
from src.entities.Player import Player
|
||||||
from src.entities.Statistics import Statistics
|
from src.entities.Statistics import Statistics
|
||||||
|
from src.game.Timer import Timer
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
@ -40,6 +41,11 @@ class Game:
|
|||||||
print("The screen cannot be in a vertical orientation. Exiting...")
|
print("The screen cannot be in a vertical orientation. Exiting...")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
# Initialize timers
|
||||||
|
self.pgTimer = pygame.time.Clock()
|
||||||
|
self.ingameTimer = Timer()
|
||||||
|
self.ingameTimer.startClock()
|
||||||
|
|
||||||
self.screen = Screen(self, self.config["window"])
|
self.screen = Screen(self, self.config["window"])
|
||||||
print("OK")
|
print("OK")
|
||||||
|
|
||||||
@ -49,11 +55,12 @@ class Game:
|
|||||||
self.map.addEntity(self.player)
|
self.map.addEntity(self.player)
|
||||||
self.eventManager = EventManager(self, self.player)
|
self.eventManager = EventManager(self, self.player)
|
||||||
|
|
||||||
|
|
||||||
self.mainLoop()
|
self.mainLoop()
|
||||||
|
|
||||||
def mainLoop(self):
|
def mainLoop(self):
|
||||||
while self.running:
|
while self.running:
|
||||||
|
# Update ingame clock
|
||||||
|
self.ingameTimer.updateTime(self.pgTimer.tick())
|
||||||
self.eventManager.handleEvents()
|
self.eventManager.handleEvents()
|
||||||
self.spritesList.draw(self.screen.pygameScreen)
|
self.spritesList.draw(self.screen.pygameScreen)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
12
src/ui/Ui.py
12
src/ui/Ui.py
@ -2,6 +2,7 @@ from enum import Enum
|
|||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
from src.entities.Statistics import Statistics
|
||||||
from src.ui.UiBar import UiBar
|
from src.ui.UiBar import UiBar
|
||||||
from src.ui.UiConsole import UiConsole
|
from src.ui.UiConsole import UiConsole
|
||||||
from src.ui.UiText import UiText
|
from src.ui.UiText import UiText
|
||||||
@ -50,6 +51,17 @@ class Ui():
|
|||||||
screenHeight - self.timerTextView.rect.h - self.isDayTextView.rect.h),
|
screenHeight - self.timerTextView.rect.h - self.isDayTextView.rect.h),
|
||||||
font=self.font)
|
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):
|
class Colors(Enum):
|
||||||
RED = (255, 0, 0)
|
RED = (255, 0, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user