-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
33 lines (29 loc) · 1.34 KB
/
controller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pygame
import model
from eventmanager import *
class Keyboard(object):
def __init__(self, evManager, model):
self.evManager = evManager
evManager.RegisterListener(self)
self.model = model
def notify(self, event):
if isinstance(event, TickEvent):
for event in pygame.event.get():
if event.type == pygame.USEREVENT:
self.evManager.Post(ClockEvent())
if event.type == pygame.QUIT:
self.evManager.Post(QuitEvent())
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
self.evManager.Post(QuitEvent())
else:
if event.key == pygame.K_LEFT:
self.evManager.Post(InputEvent('L',None))
elif event.key == pygame.K_RIGHT:
self.evManager.Post(InputEvent('R',None))
elif event.key == pygame.K_UP:
self.evManager.Post(InputEvent('W',None))
elif event.key == pygame.K_DOWN:
self.evManager.Post(InputEvent('D',None))
elif event.key == pygame.K_SPACE:
self.evManager.Post(InputEvent('SPACE',None))