feat(game): add horizontal block collision

This commit is contained in:
Kristofers Solo 2024-01-04 03:59:37 +02:00
parent e68abf8f94
commit 976f7d51cd
2 changed files with 3 additions and 3 deletions

View File

@ -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)])

View File

@ -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
)