aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZoltan Szabatin <[email protected]>2025-03-06 16:28:59 -0800
committerZoltan Szabatin <[email protected]>2025-03-06 16:28:59 -0800
commit974226122a9cf288b1ab4eef6006cb9fd29b6c83 (patch)
tree38abbc33a26ac63fbe1334c4530e054a2513b8ff /src
parentfix(Input): Controller game input (diff)
downloadsplitscreen-duo-974226122a9cf288b1ab4eef6006cb9fd29b6c83.tar.xz
splitscreen-duo-974226122a9cf288b1ab4eef6006cb9fd29b6c83.zip
fix(Input): Controller analogue stick previous state
Diffstat (limited to 'src')
-rw-r--r--src/splitscreen_duo/input.py35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/splitscreen_duo/input.py b/src/splitscreen_duo/input.py
index a947315..29f97cb 100644
--- a/src/splitscreen_duo/input.py
+++ b/src/splitscreen_duo/input.py
@@ -48,24 +48,29 @@ class Input:
return None
- def _get_controller_input(self, event):
- # Analog stick
- if event.type == pygame.JOYAXISMOTION:
- if event.axis == 0: # X-axis
- curr_x = event.value
+ def _get_analog_state(self):
+ if self.controller:
+ x = self.controller.get_axis(0) # X-axis
+ y = self.controller.get_axis(1) # Y-axis
- if curr_x <= -0.1:
- return "RIGHT"
- if curr_x >= 0.1:
- return "LEFT"
+ if x <= -0.1:
+ return "RIGHT"
- elif event.axis == 1: # Y-axis
- curr_y = event.value
+ if x >= 0.1:
+ return "LEFT"
- if curr_y <= -0.1:
- return "UP"
- if curr_y >= 0.1:
- return "DOWN"
+ if y <= -0.1:
+ return "UP"
+
+ if y >= 0.1:
+ return "DOWN"
+
+ return None
+
+ def _get_controller_input(self, event):
+ # Analog stick
+ if event.type == pygame.JOYAXISMOTION:
+ return self._get_analog_state()
# D-pad
elif event.type == pygame.JOYHATMOTION:
prev_hat = self.prev_hat_states