Added new movement methods
This commit is contained in:
parent
28a581bd3e
commit
d7e0b37666
@ -23,19 +23,35 @@ class Player(Entity):
|
|||||||
self.alive = True
|
self.alive = True
|
||||||
# If a player dies, the death reason is stored here
|
# If a player dies, the death reason is stored here
|
||||||
self.deathReason = None
|
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
|
self.movePoints += 1
|
||||||
# You can only move if you have enough stamina
|
# You can only move if you have enough stamina
|
||||||
if self.statistics.stamina > 1:
|
if self.statistics.stamina > 1:
|
||||||
self.applyWalkingFatigue()
|
self.applyWalkingFatigue()
|
||||||
if rotation.value == Rotations.NORTH.value:
|
if self.rotation.value == Rotations.NORTH.value:
|
||||||
self.rect.y -= self.rect.w
|
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
|
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
|
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
|
self.rect.x -= self.rect.w
|
||||||
|
|
||||||
def applyWalkingFatigue(self):
|
def applyWalkingFatigue(self):
|
||||||
@ -127,4 +143,9 @@ class StatisticNames(Enum):
|
|||||||
HP = 0
|
HP = 0
|
||||||
STAMINA = 1
|
STAMINA = 1
|
||||||
HUNGER = 2
|
HUNGER = 2
|
||||||
THIRST = 3
|
THIRST = 3
|
||||||
|
|
||||||
|
class Movement(Enum):
|
||||||
|
ROTATE_R = 0
|
||||||
|
ROTATE_L = 1
|
||||||
|
FORWARD = 2
|
Loading…
Reference in New Issue
Block a user