From 6cb34332591a759cb65b585122336f1757dc90cf Mon Sep 17 00:00:00 2001 From: Jan Lerking Date: Fri, 25 Apr 2025 21:37:53 +0200 Subject: [PATCH 1/2] Updated. /JL --- bricks.py | 25 +++++++++++++------------ tetris.py | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/bricks.py b/bricks.py index a34dbf5..f895d79 100644 --- a/bricks.py +++ b/bricks.py @@ -3,8 +3,6 @@ import globals import enums from random import choice - - class Brick: def __init__(self, brick, state = enums.BrickState.Next): self.shape = [] @@ -72,6 +70,7 @@ class Brick: new_x = x + col_idx new_y = y + row_idx if new_x <= 0 or new_x >= globals.GRID_WIDTH or new_y >= globals.GRID_HEIGHT: + print(f"Collision X:{new_x}, Y:{new_y}") return True if new_y >= 0 and globals.dropgrid[new_y][new_x]: return True @@ -82,18 +81,20 @@ class Brick: print(f"State set to {self.state}") def move_right(self): - if self.collision(self.shape, self.x, self.y): - return - else: - self.x += 1 - self.location = (self.x, self.y) + print(f"X: {self.x}") + if self.x != 0: + if self.collision(self.shape, self.x, self.y): + return + self.x += 1 + self.location = (self.x, self.y) def move_left(self): - if self.collision(self.shape, self.x, self.y): - return - else: - self.x -= 1 - self.location = (self.x, self.y) + print(f"X: {self.x}") + if self.x != globals.GRID_WIDTH: + if self.collision(self.shape, self.x, self.y): + return + self.x -= 1 + self.location = (self.x, self.y) def drop(self): print("Dropping") \ No newline at end of file diff --git a/tetris.py b/tetris.py index 4d1d8c5..c31eb46 100644 --- a/tetris.py +++ b/tetris.py @@ -10,7 +10,7 @@ from dropzone import DropZone from dropnext import DropNext from hud import Hud -__version__ = "0.1.0" +__version__ = "0.1.1" # Constants HAT_REPEAT_DELAY = 0 # milliseconds before first repeat -- 2.39.5 From ce48cb2936ec97b7462f15c9d069477869560c30 Mon Sep 17 00:00:00 2001 From: Jan Lerking Date: Sun, 27 Apr 2025 19:27:51 +0200 Subject: [PATCH 2/2] Switching to next brick working. /JL --- bricks.py | 3 +++ tetris.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/bricks.py b/bricks.py index f895d79..7660f04 100644 --- a/bricks.py +++ b/bricks.py @@ -47,8 +47,11 @@ class Brick: return True if self.state == enums.BrickState.Current else False def update(self): + if self.y + self.rows == globals.GRID_HEIGHT: + return False self.y += 1 self.location = (self.x, self.y) + return True def rotate_clockwise(self, shape): return [list(row)[::-1] for row in zip(*shape)] diff --git a/tetris.py b/tetris.py index c31eb46..2b25220 100644 --- a/tetris.py +++ b/tetris.py @@ -177,7 +177,9 @@ class Tetris: self.current.drop() case self.fall_timer: - self.current.update() + if not self.current.update(): + self.current = self.next + self.next = Brick(brick = randrange(0, len(BRICKS))) # Handle hotplugging case pygame.JOYDEVICEADDED: -- 2.39.5