mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
feat(game): add horizontal block collision
This commit is contained in:
parent
e68abf8f94
commit
976f7d51cd
@ -25,5 +25,5 @@ class Block(pygame.sprite.Sprite):
|
|||||||
def vertical_collision(self, x: int, field: np.ndarray) -> bool:
|
def vertical_collision(self, x: int, field: np.ndarray) -> bool:
|
||||||
return not 0 <= x < CONFIG.game.columns or field[int(self.pos.y), x]
|
return not 0 <= x < CONFIG.game.columns or field[int(self.pos.y), x]
|
||||||
|
|
||||||
def horizontal_collision(self, y: int) -> bool:
|
def horizontal_collision(self, y: int, field: np.ndarray) -> bool:
|
||||||
return y >= CONFIG.game.rows
|
return y >= CONFIG.game.rows or (y >= 0 and field[y, int(self.pos.x)])
|
||||||
|
|||||||
@ -53,6 +53,6 @@ class Tetromino:
|
|||||||
self, blocks: list[Block], direction: Direction
|
self, blocks: list[Block], direction: Direction
|
||||||
) -> bool:
|
) -> bool:
|
||||||
return any(
|
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
|
for block in self.blocks
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user