mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
feat(game): add horizontal border
This commit is contained in:
parent
d28f24cf0a
commit
dbc445b323
@ -18,3 +18,6 @@ class Block(pygame.sprite.Sprite):
|
|||||||
|
|
||||||
def vertical_collision(self, x: int) -> bool:
|
def vertical_collision(self, x: int) -> bool:
|
||||||
return not 0 <= x < CONFIG.game.columns
|
return not 0 <= x < CONFIG.game.columns
|
||||||
|
|
||||||
|
def horizontal_collision(self, y: int) -> bool:
|
||||||
|
return y >= CONFIG.game.rows
|
||||||
|
|||||||
@ -20,6 +20,9 @@ class Tetromino:
|
|||||||
]
|
]
|
||||||
|
|
||||||
def move_down(self) -> None:
|
def move_down(self) -> None:
|
||||||
|
if not self._check_horizontal_collision(
|
||||||
|
self.blocks, Direction.RIGHT
|
||||||
|
): # Direction.RIGHT = 1 aka DOWN
|
||||||
for block in self.blocks:
|
for block in self.blocks:
|
||||||
block.pos.y += 1
|
block.pos.y += 1
|
||||||
|
|
||||||
@ -35,3 +38,11 @@ class Tetromino:
|
|||||||
block.vertical_collision(int(block.pos.x + direction.value))
|
block.vertical_collision(int(block.pos.x + direction.value))
|
||||||
for block in self.blocks
|
for block in self.blocks
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _check_horizontal_collision(
|
||||||
|
self, blocks: list[Block], direction: Direction
|
||||||
|
) -> bool:
|
||||||
|
return any(
|
||||||
|
block.horizontal_collision(int(block.pos.y + direction.value))
|
||||||
|
for block in self.blocks
|
||||||
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user