From 8c1dad010139f516b7c506ab4ceb4e27408bfe52 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sat, 4 Apr 2020 21:33:24 +0200 Subject: [PATCH] Added move and rotate function --- src/entities/Player.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/entities/Player.py b/src/entities/Player.py index 84f9775..c51f272 100644 --- a/src/entities/Player.py +++ b/src/entities/Player.py @@ -16,6 +16,19 @@ class Player(Entity, pygame.sprite.Sprite): # Where the player is facing, 0 - north, 1 self.rotation = Rotations.NORTH + # Move in a desired direction + def move(self, rotation): + # 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: + self.rotate(rotation) + # Otherwise, move one tile to a given direction + else: + return 1 + + def rotate(self, rotation): + self.image = pygame.transform.rotate(self.image, (abs(self.rotation.value - rotation.value) * 90)) + self.rotation = rotation + class Rotations(Enum): NORTH = 0