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
|
pygame==2.6.1
|
||||||
pygamecontrols==0.1.11
|
pygamecontrols==0.1.13
|
||||||
|
23
tetris.py
23
tetris.py
@@ -10,7 +10,7 @@ from dropzone import DropZone
|
|||||||
from dropnext import DropNext
|
from dropnext import DropNext
|
||||||
from hud import Hud
|
from hud import Hud
|
||||||
|
|
||||||
__version__ = "0.1.2"
|
__version__ = "0.1.3"
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
HAT_REPEAT_DELAY = 0 # milliseconds before first repeat
|
HAT_REPEAT_DELAY = 0 # milliseconds before first repeat
|
||||||
@@ -144,6 +144,18 @@ class Tetris:
|
|||||||
|
|
||||||
case pygame.JOYBUTTONDOWN:
|
case pygame.JOYBUTTONDOWN:
|
||||||
match event.button:
|
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:
|
case self.rotate_button:
|
||||||
if self.current.direction == enums.BrickDirection.Dropped:
|
if self.current.direction == enums.BrickDirection.Dropped:
|
||||||
break
|
break
|
||||||
@@ -201,8 +213,13 @@ class Tetris:
|
|||||||
elif "A button" in self.joysticks[self.joy.get_instance_id()].controllers[0].mapping:
|
elif "A button" in self.joysticks[self.joy.get_instance_id()].controllers[0].mapping:
|
||||||
self.drop_button = self.joysticks[self.joy.get_instance_id()].controllers[0].mapping["A button"]
|
self.drop_button = self.joysticks[self.joy.get_instance_id()].controllers[0].mapping["A button"]
|
||||||
print(f"Drop button :{self.drop_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:
|
case pygame.JOYDEVICEREMOVED:
|
||||||
del self.joysticks[event.instance_id]
|
del self.joysticks[event.instance_id]
|
||||||
print(f"Joystick {event.instance_id} disconnected")
|
print(f"Joystick {event.instance_id} disconnected")
|
||||||
|
Reference in New Issue
Block a user