Fixed bug: not being able to rotate with specific collisions
This commit is contained in:
parent
8557eabb97
commit
c91c82d80a
@ -13,12 +13,6 @@ class Player(Entity):
|
|||||||
|
|
||||||
# Move in a desired direction
|
# Move in a desired direction
|
||||||
def move(self, rotation):
|
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:
|
|
||||||
# TODO: Collision checks "and not to events"
|
|
||||||
if rotation.value == Rotations.NORTH.value:
|
if rotation.value == Rotations.NORTH.value:
|
||||||
self.rect.y -= self.rect.w
|
self.rect.y -= self.rect.w
|
||||||
elif rotation.value == Rotations.EAST.value:
|
elif rotation.value == Rotations.EAST.value:
|
||||||
@ -29,6 +23,8 @@ class Player(Entity):
|
|||||||
self.rect.x -= self.rect.w
|
self.rect.x -= self.rect.w
|
||||||
|
|
||||||
def rotate(self, rotation):
|
def rotate(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.image = pygame.transform.rotate(self.image, ((self.rotation.value - rotation.value) * 90))
|
self.image = pygame.transform.rotate(self.image, ((self.rotation.value - rotation.value) * 90))
|
||||||
self.rotation = rotation
|
self.rotation = rotation
|
||||||
|
|
||||||
|
@ -34,13 +34,21 @@ class EventManager:
|
|||||||
# Key names are temporary
|
# Key names are temporary
|
||||||
# TODO: Load key bindings from JSON
|
# TODO: Load key bindings from JSON
|
||||||
|
|
||||||
if keys[pygame.K_w] and not self.game.map.collision(self.player.rect.x, self.player.rect.y - self.player.rect.w):
|
if keys[pygame.K_w]:
|
||||||
|
self.player.rotate(Rotations.NORTH)
|
||||||
|
if not self.game.map.collision(self.player.rect.x, self.player.rect.y - self.player.rect.w):
|
||||||
self.player.move(Rotations.NORTH)
|
self.player.move(Rotations.NORTH)
|
||||||
if keys[pygame.K_s] and not self.game.map.collision(self.player.rect.x, self.player.rect.y + self.player.rect.w):
|
if keys[pygame.K_s]:
|
||||||
|
self.player.rotate(Rotations.SOUTH)
|
||||||
|
if not self.game.map.collision(self.player.rect.x, self.player.rect.y + self.player.rect.w):
|
||||||
self.player.move(Rotations.SOUTH)
|
self.player.move(Rotations.SOUTH)
|
||||||
if keys[pygame.K_d] and not self.game.map.collision(self.player.rect.x + self.player.rect.w, self.player.rect.y):
|
if keys[pygame.K_d]:
|
||||||
|
self.player.rotate(Rotations.EAST)
|
||||||
|
if not self.game.map.collision(self.player.rect.x + self.player.rect.w, self.player.rect.y):
|
||||||
self.player.move(Rotations.EAST)
|
self.player.move(Rotations.EAST)
|
||||||
if keys[pygame.K_a] and not self.game.map.collision(self.player.rect.x - self.player.rect.w, self.player.rect.y):
|
if keys[pygame.K_a]:
|
||||||
|
self.player.rotate(Rotations.WEST)
|
||||||
|
if not self.game.map.collision(self.player.rect.x - self.player.rect.w, self.player.rect.y):
|
||||||
self.player.move(Rotations.WEST)
|
self.player.move(Rotations.WEST)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user