2020-04-02 17:30:25 +02:00
|
|
|
import pygame
|
|
|
|
|
2020-04-04 21:33:39 +02:00
|
|
|
from src.entities.Player import Rotations
|
|
|
|
|
2020-04-02 17:30:25 +02:00
|
|
|
|
2020-03-31 21:47:09 +02:00
|
|
|
class EventManager:
|
2020-04-04 21:33:39 +02:00
|
|
|
def __init__(self, gameObject, player):
|
2020-04-02 17:30:25 +02:00
|
|
|
self.game = gameObject
|
2020-04-04 21:33:39 +02:00
|
|
|
self.player = player
|
|
|
|
|
|
|
|
# Player controls
|
|
|
|
|
|
|
|
# TODO
|
|
|
|
def loadKeyboardSettings(self):
|
|
|
|
pass
|
2020-04-02 17:30:25 +02:00
|
|
|
|
|
|
|
def handleEvents(self):
|
2020-04-04 21:33:39 +02:00
|
|
|
pygame.event.pump()
|
|
|
|
|
|
|
|
keys = pygame.key.get_pressed()
|
2020-04-02 17:30:25 +02:00
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
self.game.running = False
|
2020-04-04 21:33:39 +02:00
|
|
|
|
|
|
|
self.handlePlayerControls(keys)
|
|
|
|
|
|
|
|
def handlePlayerControls(self, keys):
|
|
|
|
# Key names are temporary
|
|
|
|
# TODO: Load key bindings from JSON
|
|
|
|
if keys[pygame.K_w]:
|
|
|
|
self.player.move(Rotations.NORTH)
|
|
|
|
if keys[pygame.K_s]:
|
|
|
|
self.player.move(Rotations.SOUTH)
|
|
|
|
if keys[pygame.K_d]:
|
|
|
|
self.player.move(Rotations.EAST)
|
|
|
|
if keys[pygame.K_a]:
|
|
|
|
self.player.move(Rotations.WEST)
|
|
|
|
|