From 976f7d51cdd0a2316dfaf8392296c1dc53c9031c Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Thu, 4 Jan 2024 03:59:37 +0200 Subject: [PATCH] feat(game): add horizontal block collision --- src/game/block.py | 4 ++-- src/game/tetromino.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game/block.py b/src/game/block.py index 9ffd441..bb2b2df 100644 --- a/src/game/block.py +++ b/src/game/block.py @@ -25,5 +25,5 @@ class Block(pygame.sprite.Sprite): def vertical_collision(self, x: int, field: np.ndarray) -> bool: return not 0 <= x < CONFIG.game.columns or field[int(self.pos.y), x] - def horizontal_collision(self, y: int) -> bool: - return y >= CONFIG.game.rows + def horizontal_collision(self, y: int, field: np.ndarray) -> bool: + return y >= CONFIG.game.rows or (y >= 0 and field[y, int(self.pos.x)]) diff --git a/src/game/tetromino.py b/src/game/tetromino.py index 6e6c1f7..a6a951d 100644 --- a/src/game/tetromino.py +++ b/src/game/tetromino.py @@ -53,6 +53,6 @@ class Tetromino: self, blocks: list[Block], direction: Direction ) -> bool: return any( - block.horizontal_collision(int(block.pos.y + direction.value)) + block.horizontal_collision(int(block.pos.y + direction.value), self.field) for block in self.blocks )