diff --git a/dropnext.py b/dropnext.py index f68bb14..3897901 100644 --- a/dropnext.py +++ b/dropnext.py @@ -1,4 +1,5 @@ import pygame +from enums import BrickColor class DropNext(): def __init__(self, width, height): @@ -11,5 +12,6 @@ class DropNext(): screen.blit(self.dropnext, (tile_size * 15, tile_size * 2)) def draw_block(self, brick): + self.dropnext.fill(BrickColor.Black.value) self.dropnext.blit(brick, ((self.width - brick.get_width()) / 2, (self.height - brick.get_height()) / 2)) \ No newline at end of file diff --git a/dropzone.py b/dropzone.py index cda799a..86df9f1 100644 --- a/dropzone.py +++ b/dropzone.py @@ -1,4 +1,5 @@ import pygame +from enums import BrickColor class DropZone(): def __init__(self, tile_size, width, height): @@ -6,7 +7,6 @@ class DropZone(): self.width = width self.height = height self.tile_size = tile_size - self.dropzone.fill((0, 0, 0)) # Fill with black self.grid_row = [" "] * self.width self.grid = [self.grid_row] * self.height @@ -14,5 +14,5 @@ class DropZone(): screen.blit(self.dropzone, (self.tile_size * 4, self.tile_size * 1)) def draw_brick(self, brick, location): + self.dropzone.fill(BrickColor.Black.value) self.dropzone.blit(brick, (location[0] * self.tile_size, location[1] * self.tile_size)) - \ No newline at end of file diff --git a/enums.py b/enums.py index a9dba35..7db44c4 100644 --- a/enums.py +++ b/enums.py @@ -8,6 +8,7 @@ class BrickColor(Enum): Magenta = (255, 0, 255) Yellow = (255, 255, 0) Cyan = (0, 255, 255) + Black = (0, 0, 0) class BrickState(Enum): Current = 0 diff --git a/tetris.py b/tetris.py index bc88bbb..e409f1b 100644 --- a/tetris.py +++ b/tetris.py @@ -7,7 +7,7 @@ from dropzone import DropZone from dropnext import DropNext from hud import Hud -__version__ = "0.0.2" +__version__ = "0.0.3" # Constants HAT_REPEAT_DELAY = 0 # milliseconds before first repeat @@ -21,6 +21,9 @@ class Tetris: while self.running: self.main_loop() + + if self.joysticks: + self.joysticks[self.joy.get_instance_id()].controllers[0].close() pygame.quit() @@ -105,14 +108,15 @@ class Tetris: self.current.direction = enums.BrickDirection.Left self.current.move_left() self.dropzone.draw_brick(self.current.brick, self.current.location) - case pygame.K_UP: + case pygame.K_SPACE: if self.current.direction == enums.BrickDirection.Dropped: break self.current.rotate() - case pygame.K_DOWN: + case pygame.K_RETURN: if self.current.direction == enums.BrickDirection.Dropped: break self.current.drop() + case pygame.JOYHATMOTION: self.hat_direction = event.value self.hat_x, self.hat_y = self.hat_direction @@ -129,11 +133,13 @@ class Tetris: break self.current.direction = enums.BrickDirection.Left self.current.move_left() - elif self.hat_y == 1: - if self.current.direction == enums.BrickDirection.Dropped: - break - self.current.rotate() - elif self.hat_y == -1: + + case pygame.JOYBUTTONDOWN: + if event.button == 2: + if self.current.direction == enums.BrickDirection.Dropped: + break + self.current.rotate() + elif event.button == 0: if self.current.direction == enums.BrickDirection.Dropped: break self.current.drop()