Merge pull request 'Added left/right controls for PlayStation 3 controller. /JL' (#9) from 0.1.3 into main
Reviewed-on: #9
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
pygame==2.6.1
|
||||
pygamecontrols==0.1.11
|
||||
pygamecontrols==0.1.13
|
||||
|
19
tetris.py
19
tetris.py
@@ -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]
|
||||
|
Reference in New Issue
Block a user