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 return self.statistics
def rotate(self, rotation): 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 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:
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
# Updates self.alive if any of the statistic reaches critical value # Updates self.alive if any of the statistic reaches critical value
def determineLife(self): def determineLife(self):

View File

@ -41,33 +41,34 @@ class EventManager:
# Key names are temporary # Key names are temporary
# TODO: Load key bindings from JSON # TODO: Load key bindings from JSON
# Picking up items if self.player.alive:
if keys[pygame.K_SPACE]: # Picking up items
object = self.game.map.getEntityOnCoord(self.player.getFacingCoord()) if keys[pygame.K_SPACE]:
# Picked up item gets removed from the map object = self.game.map.getEntityOnCoord(self.player.getFacingCoord())
if type(object) is Pickupable: # Picked up item gets removed from the map
object.on_interaction(self.player) if type(object) is Pickupable:
self.game.map.removeSpriteFromMap(object) object.on_interaction(self.player)
elif type(object) is Interactable: self.game.map.removeSpriteFromMap(object)
object.on_interaction(self.player) elif type(object) is Interactable:
object.on_interaction(self.player)
# Movement # Movement
if keys[pygame.K_w]: if keys[pygame.K_w]:
self.player.rotate(Rotations.NORTH) self.player.rotate(Rotations.NORTH)
if not self.game.map.collision(self.player.rect.x, self.player.rect.y - self.player.rect.w): 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]: if keys[pygame.K_s]:
self.player.rotate(Rotations.SOUTH) self.player.rotate(Rotations.SOUTH)
if not self.game.map.collision(self.player.rect.x, self.player.rect.y + self.player.rect.w): 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]: if keys[pygame.K_d]:
self.player.rotate(Rotations.EAST) self.player.rotate(Rotations.EAST)
if not self.game.map.collision(self.player.rect.x + self.player.rect.w, self.player.rect.y): 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]: if keys[pygame.K_a]:
self.player.rotate(Rotations.WEST) self.player.rotate(Rotations.WEST)
if not self.game.map.collision(self.player.rect.x - self.player.rect.w, self.player.rect.y): 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)