From 649b61a84e22b7bf66addd868b1e739f3d87d98a Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Wed, 13 May 2020 20:17:17 +0200 Subject: [PATCH] Added pickup to move method --- src/entities/Player.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/entities/Player.py b/src/entities/Player.py index ffe48ac..4eb2cc3 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -105,9 +105,10 @@ class Player(Entity): if not self.alive: self.image, null = self.getTexture("gravestone.png", self.rect.h) - def move(self, movement): + def move(self, movement, interactableObject=None): """ Overriden function. Adds fatigue to the movement. + :param interactableObject: Object to interact with :type movement: entities.Enums.Movement :param movement: specify what movement should be done (See Movement enum) :return: Returns true, if the movement has succeeded @@ -115,14 +116,19 @@ class Player(Entity): # Can move if timeout has elapsed if self.movementTimer > self.moveTimeout: self.movementTimer = 0 - # Rotation - if movement.value != Movement.FORWARD.value: - self.updateRotation(movement) - # Else move - else: + # Movement + if movement.value == Movement.FORWARD.value: self.moveForward() - self.applyWalkingFatigue() + # Interaction + elif movement.value == Movement.PICKUP.value and interactableObject is not None: + try: + interactableObject.on_interaction(self) + except AttributeError: + pass + # Rotation + else: + self.updateRotation(movement) return True else: return False