Cleanup code. /JL
This commit is contained in:
33
tetris.py
33
tetris.py
@@ -10,7 +10,7 @@ from dropzone import DropZone
|
||||
from dropnext import DropNext
|
||||
from hud import Hud
|
||||
|
||||
__version__ = "0.0.5"
|
||||
__version__ = "0.1.0"
|
||||
|
||||
# Constants
|
||||
HAT_REPEAT_DELAY = 0 # milliseconds before first repeat
|
||||
@@ -46,11 +46,7 @@ class Tetris:
|
||||
self.dropnext = DropNext(width = TILE_SIZE * 4, height = TILE_SIZE * 4)
|
||||
|
||||
self.current = Brick(brick = randrange(0, len(BRICKS)), state = enums.BrickState.Current)
|
||||
print(self.current.shape)
|
||||
print(self.current.color)
|
||||
self.next = Brick(brick = randrange(0, len(BRICKS)))
|
||||
print(self.next.shape)
|
||||
print(self.next.color)
|
||||
|
||||
self.clock = pygame.time.Clock()
|
||||
self.rumble_timer = pygame.time.get_ticks()
|
||||
@@ -147,12 +143,13 @@ class Tetris:
|
||||
self.dropzone.draw_brick(self.current.brick, self.current.location)
|
||||
|
||||
case pygame.JOYBUTTONDOWN:
|
||||
if event.button == 2:
|
||||
if self.current.direction == enums.BrickDirection.Dropped:
|
||||
break
|
||||
self.current.rotate()
|
||||
self.dropzone.draw_brick(self.current.brick, self.current.location)
|
||||
elif event.button == 0:
|
||||
match event.button:
|
||||
case self.rotate_button:
|
||||
if self.current.direction == enums.BrickDirection.Dropped:
|
||||
break
|
||||
self.current.rotate()
|
||||
self.dropzone.draw_brick(self.current.brick, self.current.location)
|
||||
case self.drop_button:
|
||||
if self.current.direction == enums.BrickDirection.Dropped:
|
||||
break
|
||||
self.current.drop()
|
||||
@@ -188,6 +185,20 @@ class Tetris:
|
||||
# joystick, filling up the list without needing to create them manually.
|
||||
self.joy = pygame.joystick.Joystick(event.device_index)
|
||||
self.joysticks[self.joy.get_instance_id()] = PC.controller.Controllers(self.joy)
|
||||
|
||||
# Get joypad mappings
|
||||
if "triangle button" in self.joysticks[self.joy.get_instance_id()].controllers[0].mapping:
|
||||
self.rotate_button = self.joysticks[self.joy.get_instance_id()].controllers[0].mapping["triangle button"]
|
||||
elif "Y button" in self.joysticks[self.joy.get_instance_id()].controllers[0].mapping:
|
||||
self.rotate_button = self.joysticks[self.joy.get_instance_id()].controllers[0].mapping["Y button"]
|
||||
print(f"Rotate button :{self.rotate_button}")
|
||||
|
||||
if "cross 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["cross button"]
|
||||
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"]
|
||||
print(f"Drop button :{self.drop_button}")
|
||||
|
||||
|
||||
case pygame.JOYDEVICEREMOVED:
|
||||
del self.joysticks[event.instance_id]
|
||||
|
||||
Reference in New Issue
Block a user