Merge branch 'writingInfoToConsole' of https://git.wmi.amu.edu.pl/s444409/DSZI_Survival into writingInfoToConsole
This commit is contained in:
commit
2893b4dd2c
@ -1,3 +1,5 @@
|
|||||||
|
from time import sleep
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
from src.entities.Interactable import Interactable
|
from src.entities.Interactable import Interactable
|
||||||
@ -32,8 +34,9 @@ class EventManager:
|
|||||||
self.game.screen.ui.updateBasedOnPygameEvent(event)
|
self.game.screen.ui.updateBasedOnPygameEvent(event)
|
||||||
self.keyTimeout += self.keyTimer.tick()
|
self.keyTimeout += self.keyTimer.tick()
|
||||||
if self.keyTimeout >= TIMEOUT:
|
if self.keyTimeout >= TIMEOUT:
|
||||||
self.handlePlayerControls(keys)
|
if self.player.alive:
|
||||||
self.keyTimeout = 0
|
self.handlePlayerControls(keys)
|
||||||
|
self.keyTimeout = 0
|
||||||
|
|
||||||
self.game.screen.ui.updateBarsBasedOnPlayerStats(self.player.statistics)
|
self.game.screen.ui.updateBarsBasedOnPlayerStats(self.player.statistics)
|
||||||
|
|
||||||
@ -41,36 +44,35 @@ class EventManager:
|
|||||||
# Key names are temporary
|
# Key names are temporary
|
||||||
# TODO: Load key bindings from JSON
|
# TODO: Load key bindings from JSON
|
||||||
|
|
||||||
if self.player.alive:
|
# Picking up items
|
||||||
# Picking up items
|
if keys[pygame.K_SPACE]:
|
||||||
if keys[pygame.K_SPACE]:
|
object = self.game.map.getEntityOnCoord(self.player.getFacingCoord())
|
||||||
object = self.game.map.getEntityOnCoord(self.player.getFacingCoord())
|
# Picked up item gets removed from the map
|
||||||
# Picked up item gets removed from the map
|
if type(object) is Pickupable:
|
||||||
if type(object) is Pickupable:
|
object.on_interaction(self.player)
|
||||||
object.on_interaction(self.player)
|
self.game.screen.ui.updateOnPlayerPickup(self.player.statistics, object)
|
||||||
self.game.screen.ui.updateOnPlayerPickup(self.player.statistics, object)
|
self.game.map.removeSpriteFromMap(object)
|
||||||
self.game.map.removeSpriteFromMap(object)
|
elif type(object) is Interactable:
|
||||||
elif type(object) is Interactable:
|
object.on_interaction(self.player)
|
||||||
object.on_interaction(self.player)
|
self.game.screen.ui.updateOnPlayerInteraction(self.player.statistics, object)
|
||||||
self.game.screen.ui.updateOnPlayerInteraction(self.player.statistics, object)
|
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user