forked from elliott005/ninjaSouls
-
Notifications
You must be signed in to change notification settings - Fork 1
/
inputs.py
50 lines (45 loc) · 1.12 KB
/
inputs.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
from pygame.locals import *
inputs = {
"quit": [K_ESCAPE],
"moveLeft": [K_LEFT],
"moveRight": [K_RIGHT],
"moveUp": [K_UP],
"moveDown": [K_DOWN],
"attack": [K_SPACE],
"changeWeapon": [K_x],
"talk": [K_RETURN],
"useItem": [K_c],
"changeItem": [K_v]
}
inputsController = {
"quit": [9],
"moveHorizontal": [0],
"moveVertical": [1],
"attack": [1],
"changeWeapon": [6],
"talk": [0],
"useItem": [3],
"changeItem": [5]
}
deadZone = 0.1
def checkInputController(joystick, action):
if "move" in action:
for key in inputsController[action]:
if abs(joystick.get_axis(key)) > deadZone:
return joystick.get_axis(key)
return 0
else:
for key in inputsController[action]:
if joystick.get_button(key):
return True
return False
def checkInput(keysPressed, action):
for key in inputs[action]:
if keysPressed[key]:
return True
return False
def checkInputKey(p_key, action):
for key in inputs[action]:
if key == p_key:
return True
return False