-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.py
58 lines (48 loc) · 1.59 KB
/
state.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
51
52
53
54
55
56
57
58
import pygame, sys
from pygame.locals import *
import constants
class State(object):
def __init__(self, screen, content):
self.screen = screen
self.content = content
self.dt = 0
self.keys = []
self.cooltime = constants.COOLTIME
self.keysDown = []
self.events = []
def update(self, clock):
self.keysDown = []
self.events = []
self.dt = clock.get_time()
for event in pygame.event.get():
if hasattr(event, 'key'):
if event.type == KEYDOWN:
self.keysDown.append(event.key)
self.keys.append([event.key, constants.ICOOLTIME])
elif event.type == KEYUP:
self.keyreleased(event.key)
elif event.type == USEREVENT+1:
self.events.append(event)
def draw(self):
# for i in xrange(len(self.keys)):
# if self.keys[i][0] == key:
# self.keys.pop(i)
# break
pass
def keyreleased(self, key):
for i in xrange(len(self.keys)):
if self.keys[i][0] == key:
self.keys.pop(i)
break
def check_cool(self, index):
cool = self.cooltime
if index >= len(self.keys):
return False
if self.keys[index][0] == K_BACKSPACE:
cool = 25
if self.keys[index][1] <= 0:
self.keys[index][1] = cool
return True
else:
self.keys[index][1] -= self.dt
return False