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

This commit is contained in:
jonspacz 2020-04-05 23:43:26 +02:00
commit a7d7ff840a

View File

@ -10,9 +10,11 @@ class Player(Entity):
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
self.rotation = Rotations.NORTH self.rotation = Rotations.NORTH
self.statistics = Statistics(100, 0, 0, 100)
# Move in a desired direction # Move in a desired direction
def move(self, rotation): def move(self, rotation):
self.statistics.set_stamina(-1)
if rotation.value == Rotations.NORTH.value: if rotation.value == Rotations.NORTH.value:
self.rect.y -= self.rect.w self.rect.y -= self.rect.w
elif rotation.value == Rotations.EAST.value: elif rotation.value == Rotations.EAST.value:
@ -22,14 +24,34 @@ class Player(Entity):
elif rotation.value == Rotations.WEST.value: elif rotation.value == Rotations.WEST.value:
self.rect.x -= self.rect.w self.rect.x -= self.rect.w
# Returns given statistic
def getStatistic(self, stat):
if stat.value == StatisticNames.HP:
return self.statistics.hp
elif stat.value == StatisticNames.HUNGER:
return self.statistics.hunger
elif stat.value == StatisticNames.THIRST:
return self.statistics.thirst
elif stat.value == StatisticNames.STAMINA:
return self.statistics.stamina
return None
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:
self.image = pygame.transform.rotate(self.image, ((self.rotation.value - rotation.value) * 90)) self.image = pygame.transform.rotate(self.image, ((self.rotation.value - rotation.value) * 90))
self.rotation = rotation self.rotation = rotation
class Rotations(Enum): class Rotations(Enum):
NORTH = 0 NORTH = 0
EAST = 1 EAST = 1
SOUTH = 2 SOUTH = 2
WEST = 3 WEST = 3
class StatisticNames(Enum):
HP = 0
STAMINA = 1
HUNGER = 2
THIRST = 3