Added move and rotate function

This commit is contained in:
Marcin Kostrzewski 2020-04-04 21:33:24 +02:00
parent d16711068a
commit 8c1dad0101

View File

@ -16,6 +16,19 @@ class Player(Entity, pygame.sprite.Sprite):
# Where the player is facing, 0 - north, 1 # Where the player is facing, 0 - north, 1
self.rotation = Rotations.NORTH 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): class Rotations(Enum):
NORTH = 0 NORTH = 0