-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
33 lines (27 loc) · 841 Bytes
/
utils.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
#!/usr/bin/python
# -*- coding: utf8 -*-
import pygame
from config import CONTROL_KEY_LIST
class KeyHandler(object):
def __init__(self):
self.keyDict = {}
keyList = [pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT, pygame.K_ESCAPE,
pygame.K_z, pygame.K_s, pygame.K_q, pygame.K_d, pygame.K_SPACE, pygame.K_RETURN]
for key in keyList:
self.keyDict[key] = 0
for key in CONTROL_KEY_LIST:
self.keyDict[key] = 0
def handleEvents(self, events=[]):
for event in events:
if event.type == pygame.KEYDOWN:
self.keyDict[event.key] = 1
elif event.type == pygame.KEYUP:
self.keyDict[event.key] = 0
def getEvents(self):
events = pygame.event.get()
self.handleEvents(events)
return events
def getKey(self, key):
if key not in self.keyDict:
self.keyDict[key]=0
return self.keyDict[key]