Merge remote-tracking branch 'origin/passingEvents' into passingEvents
# Conflicts: # src/entities/Player.py
This commit is contained in:
commit
9a5556ff7b
BIN
data/images/entities/bush.jpg
Normal file
BIN
data/images/entities/bush.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.4 KiB |
BIN
data/images/entities/rabbit.jpg
Normal file
BIN
data/images/entities/rabbit.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 630 B |
BIN
data/images/entities/rock.jpg
Normal file
BIN
data/images/entities/rock.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 78 KiB |
Binary file not shown.
Before Width: | Height: | Size: 7.7 KiB |
@ -13,6 +13,7 @@
|
|||||||
"hunger" : 20
|
"hunger" : 20
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"name" : "cranberry",
|
"name" : "cranberry",
|
||||||
"position" : {
|
"position" : {
|
||||||
@ -26,5 +27,37 @@
|
|||||||
"thirst" : 2,
|
"thirst" : 2,
|
||||||
"hunger" : 10
|
"hunger" : 10
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name" : "rabbit",
|
||||||
|
"position" : {
|
||||||
|
"x": 12,
|
||||||
|
"y": 16
|
||||||
|
},
|
||||||
|
"isPickupable" : true,
|
||||||
|
"effect" : {
|
||||||
|
"hp": 30,
|
||||||
|
"stamina": -5,
|
||||||
|
"thirst": -5,
|
||||||
|
"hunger": 40
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name" : "bush",
|
||||||
|
"position" : {
|
||||||
|
"x": 15,
|
||||||
|
"y": 9
|
||||||
|
},
|
||||||
|
"isPickupable" : false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "rock",
|
||||||
|
"position" : {
|
||||||
|
"x": 13,
|
||||||
|
"y": 1
|
||||||
|
},
|
||||||
|
"isPickupable" : false
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -8,6 +8,7 @@ class Entity(pygame.sprite.Sprite):
|
|||||||
def __init__(self, texture, size, pos):
|
def __init__(self, texture, size, pos):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.image, self.rect = self.getTexture(texture, size)
|
self.image, self.rect = self.getTexture(texture, size)
|
||||||
|
self.image.set_colorkey((255, 255, 255))
|
||||||
self.rect.x = pos[0]
|
self.rect.x = pos[0]
|
||||||
self.rect.y = pos[1]
|
self.rect.y = pos[1]
|
||||||
self.id = self.getId()
|
self.id = self.getId()
|
||||||
|
@ -22,6 +22,8 @@ class EventManager:
|
|||||||
def handleEvents(self):
|
def handleEvents(self):
|
||||||
pygame.event.pump()
|
pygame.event.pump()
|
||||||
|
|
||||||
|
self.game.screen.ui.timerTextView.changeText(self.game.ingameTimer.getPrettyTime())
|
||||||
|
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
|
43
src/ui/Ui.py
43
src/ui/Ui.py
@ -26,25 +26,36 @@ class Ui():
|
|||||||
self.timerTextView = UiText(pygame.Rect(0, 0, leftUiWidth, self.barHeight), font=self.font,
|
self.timerTextView = UiText(pygame.Rect(0, 0, leftUiWidth, self.barHeight), font=self.font,
|
||||||
text=timer.getPrettyTime(), textColor=Colors.WHITE.value,
|
text=timer.getPrettyTime(), textColor=Colors.WHITE.value,
|
||||||
backgroundColor=Colors.GRAY.value)
|
backgroundColor=Colors.GRAY.value)
|
||||||
self.isDayTextView = UiText(pygame.Rect(0, self.timerTextView.rect.y + self.barHeight, leftUiWidth, self.barHeight), text="Day",
|
self.isDayTextView = UiText(
|
||||||
|
pygame.Rect(0, self.timerTextView.rect.y + self.barHeight, leftUiWidth, self.barHeight), text="Day",
|
||||||
font=self.font, backgroundColor=Colors.GRAY.value, textColor=Colors.WHITE.value)
|
font=self.font, backgroundColor=Colors.GRAY.value, textColor=Colors.WHITE.value)
|
||||||
|
|
||||||
self.healthTextView = UiText(pygame.Rect(0, 0, rightUiWidth, self.barHeight), text="Health points",
|
self.healthTextView = UiText(pygame.Rect(0, 0, rightUiWidth, self.barHeight), text="Health points",
|
||||||
font=self.font, textColor=Colors.WHITE.value)
|
font=self.font, textColor=Colors.WHITE.value)
|
||||||
self.healthBar = UiBar(pygame.Rect(0, self.healthTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight))
|
self.healthBar = UiBar(
|
||||||
|
pygame.Rect(0, self.healthTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight))
|
||||||
|
|
||||||
self.hungerTextView = UiText(pygame.Rect(0, self.healthBar.rect.y + self.barHeight, rightUiWidth, self.barHeight),
|
self.hungerTextView = UiText(
|
||||||
|
pygame.Rect(0, self.healthBar.rect.y + self.barHeight, rightUiWidth, self.barHeight),
|
||||||
text="Hunger", font=self.font, textColor=Colors.WHITE.value)
|
text="Hunger", font=self.font, textColor=Colors.WHITE.value)
|
||||||
self.hungerBar = UiBar(pygame.Rect(0, self.hungerTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight), initialFilledPercent=0,
|
self.hungerBar = UiBar(
|
||||||
|
pygame.Rect(0, self.hungerTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight),
|
||||||
|
initialFilledPercent=0,
|
||||||
filledBarColor=Colors.YELLOW.value)
|
filledBarColor=Colors.YELLOW.value)
|
||||||
|
|
||||||
self.staminaTextView = UiText(pygame.Rect(0, self.hungerBar.rect.y + self.barHeight, rightUiWidth, self.barHeight), text="Stamina",
|
self.staminaTextView = UiText(
|
||||||
|
pygame.Rect(0, self.hungerBar.rect.y + self.barHeight, rightUiWidth, self.barHeight), text="Stamina",
|
||||||
font=self.font, textColor=Colors.WHITE.value)
|
font=self.font, textColor=Colors.WHITE.value)
|
||||||
self.staminaBar = UiBar(pygame.Rect(0, self.staminaTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight), filledBarColor=Colors.GREEN.value)
|
self.staminaBar = UiBar(
|
||||||
|
pygame.Rect(0, self.staminaTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight),
|
||||||
|
filledBarColor=Colors.GREEN.value)
|
||||||
|
|
||||||
self.thirstTextView = UiText(pygame.Rect(0, self.staminaBar.rect.y + self.barHeight, rightUiWidth, self.barHeight), text="Thirst",
|
self.thirstTextView = UiText(
|
||||||
|
pygame.Rect(0, self.staminaBar.rect.y + self.barHeight, rightUiWidth, self.barHeight), text="Thirst",
|
||||||
font=self.font, textColor=Colors.WHITE.value)
|
font=self.font, textColor=Colors.WHITE.value)
|
||||||
self.thirstBar = UiBar(pygame.Rect(0, self.thirstTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight), initialFilledPercent=0,
|
self.thirstBar = UiBar(
|
||||||
|
pygame.Rect(0, self.thirstTextView.rect.y + self.barHeight, rightUiWidth, self.barHeight),
|
||||||
|
initialFilledPercent=0,
|
||||||
filledBarColor=Colors.BLUE.value)
|
filledBarColor=Colors.BLUE.value)
|
||||||
|
|
||||||
self.console = UiConsole(pygame.Rect(0, self.timerTextView.rect.h + self.isDayTextView.rect.h, leftUiWidth,
|
self.console = UiConsole(pygame.Rect(0, self.timerTextView.rect.h + self.isDayTextView.rect.h, leftUiWidth,
|
||||||
@ -52,17 +63,29 @@ class Ui():
|
|||||||
font=self.font)
|
font=self.font)
|
||||||
|
|
||||||
def updateBasedOnPlayerStats(self, statistics: Statistics):
|
def updateBasedOnPlayerStats(self, statistics: Statistics):
|
||||||
|
consoleLines = []
|
||||||
|
if self.healthBar.value != statistics.hp:
|
||||||
self.healthBar.updateFill(statistics.hp)
|
self.healthBar.updateFill(statistics.hp)
|
||||||
|
consoleLines.append("Health: " + str(statistics.hp))
|
||||||
|
|
||||||
|
if self.hungerBar.value != statistics.hunger:
|
||||||
self.hungerBar.updateFill(statistics.hunger)
|
self.hungerBar.updateFill(statistics.hunger)
|
||||||
|
consoleLines.append("Hunger: " + str(statistics.hunger))
|
||||||
|
|
||||||
|
if self.staminaBar.value != statistics.stamina:
|
||||||
self.staminaBar.updateFill(statistics.stamina)
|
self.staminaBar.updateFill(statistics.stamina)
|
||||||
|
consoleLines.append("Stamina: " + str(statistics.stamina))
|
||||||
|
|
||||||
|
if self.thirstBar.value != statistics.thirst:
|
||||||
self.thirstBar.updateFill(statistics.thirst)
|
self.thirstBar.updateFill(statistics.thirst)
|
||||||
|
consoleLines.append("Stamina: " + str(statistics.thirst))
|
||||||
|
|
||||||
|
self.console.addLinesToConsoleAndScrollToDisplayThem(consoleLines)
|
||||||
|
|
||||||
def updateBasedOnPygameEvent(self, event: pygame.event):
|
def updateBasedOnPygameEvent(self, event: pygame.event):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Colors(Enum):
|
class Colors(Enum):
|
||||||
RED = (255, 0, 0)
|
RED = (255, 0, 0)
|
||||||
GREEN = (0, 255, 0)
|
GREEN = (0, 255, 0)
|
||||||
|
@ -13,6 +13,7 @@ class UiBar(UiElement):
|
|||||||
self.outlineColor = outlineColor
|
self.outlineColor = outlineColor
|
||||||
self.outlineThickness = outlineThickness
|
self.outlineThickness = outlineThickness
|
||||||
self.filledBarColor = filledBarColor
|
self.filledBarColor = filledBarColor
|
||||||
|
self.value = initialFilledPercent
|
||||||
|
|
||||||
self.__genBar__()
|
self.__genBar__()
|
||||||
|
|
||||||
@ -27,4 +28,5 @@ class UiBar(UiElement):
|
|||||||
|
|
||||||
def updateFill(self, filledPercent):
|
def updateFill(self, filledPercent):
|
||||||
self.filledPercent = filledPercent / 100
|
self.filledPercent = filledPercent / 100
|
||||||
|
self.value = filledPercent
|
||||||
self.__genBar__()
|
self.__genBar__()
|
||||||
|
@ -24,3 +24,11 @@ class UiText(UiElement):
|
|||||||
self.image.fill(backgroundColor)
|
self.image.fill(backgroundColor)
|
||||||
wordImage = self.font.render(text, antialias, textColor)
|
wordImage = self.font.render(text, antialias, textColor)
|
||||||
self.image.blit(wordImage, (0, 0))
|
self.image.blit(wordImage, (0, 0))
|
||||||
|
|
||||||
|
def changeText(self, newText):
|
||||||
|
self.text = newText
|
||||||
|
|
||||||
|
if self.backgroundColor is not None:
|
||||||
|
self.image.fill(self.backgroundColor)
|
||||||
|
wordImage = self.font.render(self.text, self.antialias, self.textColor)
|
||||||
|
self.image.blit(wordImage, (0, 0))
|
||||||
|
Loading…
Reference in New Issue
Block a user