aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZoltan Szabatin <[email protected]>2025-03-02 20:10:40 -0800
committerZoltan Szabatin <[email protected]>2025-03-02 20:10:40 -0800
commitb30cd99942e2601d1d35a3b6c0e8125e0a0b3cc2 (patch)
tree65dbdc7eaff51ec928cb7b7e48cfec0e40562772 /src
parentrefactor: Generic game handling (diff)
downloadsplitscreen-duo-b30cd99942e2601d1d35a3b6c0e8125e0a0b3cc2.tar.xz
splitscreen-duo-b30cd99942e2601d1d35a3b6c0e8125e0a0b3cc2.zip
feat(input): Add extra controller inputs
Diffstat (limited to 'src')
-rw-r--r--src/splitscreen_duo/input.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/splitscreen_duo/input.py b/src/splitscreen_duo/input.py
index 1a1e5d0..a9c13c3 100644
--- a/src/splitscreen_duo/input.py
+++ b/src/splitscreen_duo/input.py
@@ -23,10 +23,19 @@ class Input:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
return "UP"
+
if event.key == pygame.K_DOWN:
return "DOWN"
+
+ if event.key == pygame.K_LEFT:
+ return "LEFT"
+
+ if event.key == pygame.K_RIGHT:
+ return "RIGHT"
+
if event.key == pygame.K_RETURN:
return "SELECT"
+
if event.key == pygame.K_ESCAPE:
return "QUIT"
@@ -37,14 +46,34 @@ class Input:
return None
if event.type == pygame.JOYAXISMOTION:
- if event.axis == 1: # Y-axis
+ if event.axis == 0: # X-axis (left/right)
+ if event.value < -0.5: # Joystick left
+ return "LEFT"
+
+ if event.value > 0.5: # Joystick right
+ return "RIGHT"
+ elif event.axis == 1: # Y-axis (up/down)
if event.value < -0.5: # Joystick up
return "UP"
+
if event.value > 0.5: # Joystick down
return "DOWN"
+ elif event.type == pygame.JOYHATMOTION:
+ if event.value[0] == -1: # D-pad left
+ return "LEFT"
+
+ if event.value[0] == 1: # D-pad right
+ return "RIGHT"
+
+ if event.value[1] == 1: # D-pad up
+ return "UP"
+
+ if event.value[1] == -1: # D-pad down
+ return "DOWN"
elif event.type == pygame.JOYBUTTONDOWN:
if event.button == 0: # Button A or select
return "SELECT"
+
if event.button == 1: # Button B
return "QUIT"