-
Notifications
You must be signed in to change notification settings - Fork 0
/
controls.py
66 lines (54 loc) · 2.08 KB
/
controls.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
59
60
61
62
63
64
65
66
import pygame
class ControlsObject(dict):
""" A subclass of a dictionary, used to store the current state of the
user-input controls."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@property
def MouseClicked(self):
""" A property that returns a Boolean value describing whether the mouse
was clicked (not pressed down, specifically clicked) in the last
control update or not. No inputs, and it outputs a Boolean value."""
for event in self["events"]:
if event.type == pygame.MOUSEBUTTONDOWN:
return True
return False
@property
def LeftClickDown(self):
for event in self["events"]:
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
return True
return False
@property
def LeftClickRelease(self):
for event in self["events"]:
if event.type == pygame.MOUSEBUTTONUP and event.button == 1:
return True
return False
@property
def MouseHasMoved(self):
for event in self["events"]:
if event.type == pygame.MOUSEMOTION:
return True
return False
@property
def MouseHasScrolled(self):
for event in self["events"]:
if event.type == pygame.MOUSEBUTTONDOWN and 4 <= event.button <= 5:
return True
return False
def PrintIndexOfDown(self):
"""a function for dev use only, prints the indexes of keys that are pressed down."""
keys = []
for index, key in enumerate(self["keys_pressed"]):
if key:
keys.append(index)
print(keys)
def PrintNameOfKeyDown(self):
"""a function for dev use only, prints the names of keys that are pressed down."""
keys = []
for event in self["events"]:
if event.type == pygame.KEYDOWN:
keys.append(pygame.key.name(event.key))
print(keys)
controls = ControlsObject()