From d7e0b376664863b9588870a95f7a81d276b0a0d1 Mon Sep 17 00:00:00 2001 From: Razrector Date: Sat, 25 Apr 2020 22:02:08 +0200 Subject: [PATCH] Added new movement methods --- src/entities/Player.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/entities/Player.py b/src/entities/Player.py index 1a2d160..c13f6da 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -23,19 +23,35 @@ class Player(Entity): self.alive = True # If a player dies, the death reason is stored here self.deathReason = None - # Move in a desired direction - def move(self, rotation): + + # Update player's rotation + def updateRotation(self, movement): + if movement == Movement.ROTATE_L: + self.rotate(Rotations((self.rotation.value + 1) % 4)) + elif movement == Movement.ROTATE_R: + self.rotate(Rotations((self.rotation.value - 1) % 4)) + + # Move; movement - Enum + def move(self, movement): + # Rotation + if movement.value != Movement.FORWARD.value: + self.updateRotation(movement) + # Else move + else: + self.moveForward() + + def moveForward(self): self.movePoints += 1 # You can only move if you have enough stamina if self.statistics.stamina > 1: self.applyWalkingFatigue() - if rotation.value == Rotations.NORTH.value: + if self.rotation.value == Rotations.NORTH.value: self.rect.y -= self.rect.w - elif rotation.value == Rotations.EAST.value: + elif self.rotation.value == Rotations.EAST.value: self.rect.x += self.rect.w - elif rotation.value == Rotations.SOUTH.value: + elif self.rotation.value == Rotations.SOUTH.value: self.rect.y += self.rect.w - elif rotation.value == Rotations.WEST.value: + elif self.rotation.value == Rotations.WEST.value: self.rect.x -= self.rect.w def applyWalkingFatigue(self): @@ -127,4 +143,9 @@ class StatisticNames(Enum): HP = 0 STAMINA = 1 HUNGER = 2 - THIRST = 3 \ No newline at end of file + THIRST = 3 + +class Movement(Enum): + ROTATE_R = 0 + ROTATE_L = 1 + FORWARD = 2 \ No newline at end of file