-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputmanager.py
50 lines (44 loc) · 1.48 KB
/
inputmanager.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pygame
from pygame.locals import *
from newlevel import ResetLevelException
class InputManager(object):
def __init__(self):
self.left = False
self.right = False
self.up = False
self.down = False
self.z = False
self.x = False
def update(self):
for event in pygame.event.get():
if event.type == QUIT:
quit()
elif event.type == KEYDOWN:
if event.key == K_RIGHT:
self.right = True
elif event.key == K_LEFT:
self.left = True
elif event.key == K_UP:
self.up = True
elif event.key == K_DOWN:
self.down = True
elif event.key == K_z:
self.z = True
elif event.key == K_x:
self.x = True
elif event.key == K_r:
raise ResetLevelException()
elif event.type == KEYUP:
if event.key == K_RIGHT:
self.right = False
elif event.key == K_LEFT:
self.left = False
elif event.key == K_UP:
self.up = False
elif event.key == K_DOWN:
self.down = False
elif event.key == K_z:
self.z = False
elif event.key == K_x:
self.x = False
return True