Events won't be handled if the player is dead

This commit is contained in:
Marcin Kostrzewski 2020-04-06 12:05:57 +02:00
parent 605bf55ebf
commit e3b3fdd74f
2 changed files with 31 additions and 31 deletions

View File

@ -85,11 +85,10 @@ class Player(Entity):
return self.statistics
def rotate(self, rotation):
if self.alive:
# 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
# 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
# Updates self.alive if any of the statistic reaches critical value
def determineLife(self):

View File

@ -41,33 +41,34 @@ class EventManager:
# Key names are temporary
# TODO: Load key bindings from JSON
# Picking up items
if keys[pygame.K_SPACE]:
object = self.game.map.getEntityOnCoord(self.player.getFacingCoord())
# Picked up item gets removed from the map
if type(object) is Pickupable:
object.on_interaction(self.player)
self.game.map.removeSpriteFromMap(object)
elif type(object) is Interactable:
object.on_interaction(self.player)
if self.player.alive:
# Picking up items
if keys[pygame.K_SPACE]:
object = self.game.map.getEntityOnCoord(self.player.getFacingCoord())
# Picked up item gets removed from the map
if type(object) is Pickupable:
object.on_interaction(self.player)
self.game.map.removeSpriteFromMap(object)
elif type(object) is Interactable:
object.on_interaction(self.player)
# Movement
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)
# Movement
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)