Added left/right controls for PlayStation 3 controller. /JL

This commit is contained in:
2025-05-04 14:49:05 +02:00
parent 89e55ab3b0
commit 431dfcc4d7
2 changed files with 21 additions and 4 deletions

View File

@@ -1,2 +1,2 @@
pygame==2.6.1
pygamecontrols==0.1.11
pygamecontrols==0.1.13

View File

@@ -10,7 +10,7 @@ from dropzone import DropZone
from dropnext import DropNext
from hud import Hud
__version__ = "0.1.2"
__version__ = "0.1.3"
# Constants
HAT_REPEAT_DELAY = 0 # milliseconds before first repeat
@@ -144,6 +144,18 @@ class Tetris:
case pygame.JOYBUTTONDOWN:
match event.button:
case self.left_button:
if self.current.direction == enums.BrickDirection.Dropped:
break
self.current.direction = enums.BrickDirection.Left
self.current.move_left()
self.dropzone.draw_brick(self.current.brick, self.current.location)
case self.right_button:
if self.current.direction == enums.BrickDirection.Dropped:
break
self.current.direction = enums.BrickDirection.Right
self.current.move_right()
self.dropzone.draw_brick(self.current.brick, self.current.location)
case self.rotate_button:
if self.current.direction == enums.BrickDirection.Dropped:
break
@@ -202,6 +214,11 @@ class Tetris:
self.drop_button = self.joysticks[self.joy.get_instance_id()].controllers[0].mapping["A button"]
print(f"Drop button :{self.drop_button}")
if "left button" in self.joysticks[self.joy.get_instance_id()].controllers[0].mapping:
self.left_button = self.joysticks[self.joy.get_instance_id()].controllers[0].mapping["left button"]
if "right button" in self.joysticks[self.joy.get_instance_id()].controllers[0].mapping:
self.right_button = self.joysticks[self.joy.get_instance_id()].controllers[0].mapping["right button"]
case pygame.JOYDEVICEREMOVED:
del self.joysticks[event.instance_id]