From 052e56836b6974ee4b62d80938171f96307e9989 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Mon, 6 Apr 2020 10:25:01 +0200 Subject: [PATCH] Player now passively looses stats --- src/entities/Player.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/entities/Player.py b/src/entities/Player.py index 4b6b86b..e789c8b 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -13,12 +13,16 @@ class Player(Entity): self.statistics = Statistics(100, 0, 0, 100) # How many steps has the player taken through its lifetime self.movePoints = 0 + # Tracks how much time has passed since the player is alive + self.timer = pygame.time.Clock() + self.timeAlive = 1 + # Used to determine fatigue + self.fatigueTimeout = 0 # Move in a desired direction def move(self, rotation): self.movePoints += 1 - # Player gets tired aswell! - self.applyFatigue() + self.applyWalkingFatigue() if rotation.value == Rotations.NORTH.value: self.rect.y -= self.rect.w elif rotation.value == Rotations.EAST.value: @@ -28,7 +32,7 @@ class Player(Entity): elif rotation.value == Rotations.WEST.value: self.rect.x -= self.rect.w - def applyFatigue(self): + def applyWalkingFatigue(self): # looses hunger every 10 steps taken if self.movePoints % 10 == 0: self.statistics.set_hunger(10) @@ -38,6 +42,14 @@ class Player(Entity): # gets tired every step self.statistics.set_stamina(-2) + def applyTimeFatigue(self, tickTime): + self.fatigueTimeout += tickTime + if self.fatigueTimeout >= 700: + self.statistics.set_thirst(5) + self.statistics.set_hunger(3) + self.fatigueTimeout = 0 + + def getFacingCoord(self): if self.rotation == Rotations.NORTH: return self.rect.x, self.rect.y - (self.rect.h) @@ -69,6 +81,13 @@ class Player(Entity): self.image = pygame.transform.rotate(self.image, ((self.rotation.value - rotation.value) * 90)) self.rotation = rotation + # Called every frame + def update(self): + self.timeAlive += self.timer.get_time() + # Player gets tired every once in a while + self.applyTimeFatigue(self.timer.get_time()) + self.timer.tick() + class Rotations(Enum): NORTH = 0