Merge remote-tracking branch 'origin/passingEvents' into passingEvents

This commit is contained in:
Wirus 2020-04-06 00:43:35 +02:00
commit cfd3b05981
4 changed files with 33 additions and 7 deletions

View File

@ -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:

View File

@ -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):

View File

@ -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

View File

@ -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__()