feat(game): add vertical borders

style(game): rename method

style(game): wrong method name

style(game): fix wrong method name
This commit is contained in:
Kristofers Solo 2024-01-04 03:05:26 +02:00
parent 684f5ba196
commit d28f24cf0a
2 changed files with 13 additions and 5 deletions

View File

@ -15,3 +15,6 @@ class Block(pygame.sprite.Sprite):
def update(self) -> None: def update(self) -> None:
self.rect.topleft = self.pos * CONFIG.game.cell.width self.rect.topleft = self.pos * CONFIG.game.cell.width
def vertical_collision(self, x: int) -> bool:
return not 0 <= x < CONFIG.game.columns

View File

@ -24,9 +24,14 @@ class Tetromino:
block.pos.y += 1 block.pos.y += 1
def move_horizontal(self, direction: Direction) -> None: def move_horizontal(self, direction: Direction) -> None:
for block in self.blocks: if not self._check_vertical_collision(self.blocks, direction):
block.pos.x += direction.value for block in self.blocks:
block.pos.x += direction.value
def next_move_horizontal_collide(self, block: Block, direction: Direction) -> None: def _check_vertical_collision(
for block in self.blocks: self, blocks: list[Block], direction: Direction
block.pos.x += direction.value ) -> bool:
return any(
block.vertical_collision(int(block.pos.x + direction.value))
for block in self.blocks
)