Fixed bug: not being able to rotate with specific collisions
This commit is contained in:
parent
8557eabb97
commit
c91c82d80a
@ -13,24 +13,20 @@ class Player(Entity):
|
||||
|
||||
# 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:
|
||||
# TODO: Collision checks "and not to events"
|
||||
if rotation.value == Rotations.NORTH.value:
|
||||
self.rect.y -= self.rect.w
|
||||
elif rotation.value == Rotations.EAST.value:
|
||||
self.rect.x += self.rect.w
|
||||
elif rotation.value == Rotations.SOUTH.value:
|
||||
self.rect.y += self.rect.w
|
||||
elif rotation.value == Rotations.WEST.value:
|
||||
self.rect.x -= self.rect.w
|
||||
if rotation.value == Rotations.NORTH.value:
|
||||
self.rect.y -= self.rect.w
|
||||
elif rotation.value == Rotations.EAST.value:
|
||||
self.rect.x += self.rect.w
|
||||
elif rotation.value == Rotations.SOUTH.value:
|
||||
self.rect.y += self.rect.w
|
||||
elif rotation.value == Rotations.WEST.value:
|
||||
self.rect.x -= self.rect.w
|
||||
|
||||
def rotate(self, rotation):
|
||||
self.image = pygame.transform.rotate(self.image, ((self.rotation.value - rotation.value) * 90))
|
||||
self.rotation = 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.rotation = rotation
|
||||
|
||||
class Rotations(Enum):
|
||||
NORTH = 0
|
||||
|
@ -34,14 +34,22 @@ class EventManager:
|
||||
# Key names are temporary
|
||||
# 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):
|
||||
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):
|
||||
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):
|
||||
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):
|
||||
self.player.move(Rotations.WEST)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user