-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.py
More file actions
26 lines (21 loc) · 910 Bytes
/
input.py
File metadata and controls
26 lines (21 loc) · 910 Bytes
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
from functools import partial
class Input:
keysPressed = []
def __init__(self, upkey, downkey, paddle, window):
self.upkey = upkey
self.downkey = downkey
self.paddle = paddle
window.onkeypress(partial(self.handleInputs, self.upkey), self.upkey)
window.onkeypress(partial(self.handleInputs, self.downkey), self.downkey)
window.onkeyrelease(partial(self.resetInput, self.upkey), self.upkey)
window.onkeyrelease(partial(self.resetInput, self.downkey), self.downkey)
def run(self):
if Input.keysPressed.count(self.upkey) == 1:
self.paddle.up()
elif Input.keysPressed.count(self.downkey) == 1:
self.paddle.down()
def handleInputs(self, key):
if Input.keysPressed.count(key) == 0:
Input.keysPressed.append(key)
def resetInput(self, key):
Input.keysPressed.remove(key)