Cleanup code. /JL
This commit is contained in:
@@ -57,7 +57,6 @@ class Brick:
|
||||
|
||||
def rotate(self):
|
||||
new_shape = self.rotate_clockwise(self.shape)
|
||||
print(new_shape)
|
||||
if not self.collision(new_shape, self.x, self.y):
|
||||
self.shape = new_shape
|
||||
self.rows = len(self.shape)
|
||||
@@ -65,7 +64,6 @@ class Brick:
|
||||
self.width = self.cols * globals.TILE_SIZE
|
||||
self.height = self.rows * globals.TILE_SIZE
|
||||
self.draw_brick()
|
||||
print(self.shape)
|
||||
|
||||
def collision(self, shape, x, y):
|
||||
for row_idx, row in enumerate(shape):
|
||||
|
@@ -7,7 +7,6 @@ class DropZone():
|
||||
self.dropzone = pygame.Surface((width * globals.TILE_SIZE, height * globals.TILE_SIZE))
|
||||
self.width = width
|
||||
self.height = height
|
||||
print(globals.dropgrid)
|
||||
|
||||
def draw(self, screen):
|
||||
screen.blit(self.dropzone, (globals.TILE_SIZE * 4, globals.TILE_SIZE * 1))
|
||||
|
@@ -1,2 +1,2 @@
|
||||
pygame==2.6.1
|
||||
pygamecontrols==0.1.9
|
||||
pygamecontrols==0.1.11
|
||||
|
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