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:
|
||||
return not 0 <= x < CONFIG.game.columns
|
||||
|
||||
def horizontal_collision(self, y: int) -> bool:
|
||||
return y >= CONFIG.game.rows
|
||||
|
||||
@ -20,8 +20,11 @@ class Tetromino:
|
||||
]
|
||||
|
||||
def move_down(self) -> None:
|
||||
for block in self.blocks:
|
||||
block.pos.y += 1
|
||||
if not self._check_horizontal_collision(
|
||||
self.blocks, Direction.RIGHT
|
||||
): # Direction.RIGHT = 1 aka DOWN
|
||||
for block in self.blocks:
|
||||
block.pos.y += 1
|
||||
|
||||
def move_horizontal(self, direction: Direction) -> None:
|
||||
if not self._check_vertical_collision(self.blocks, direction):
|
||||
@ -35,3 +38,11 @@ class Tetromino:
|
||||
block.vertical_collision(int(block.pos.x + direction.value))
|
||||
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