mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
feat(game): allow rotation near borders
feat(game): limit loop size
This commit is contained in:
parent
6e5a7f3d61
commit
82d26ddc03
@ -69,7 +69,7 @@ class Tetromino:
|
|||||||
|
|
||||||
def rotate(self, rotation: Rotation = Rotation.CLOCKWISE) -> None:
|
def rotate(self, rotation: Rotation = Rotation.CLOCKWISE) -> None:
|
||||||
"""
|
"""
|
||||||
Rotates the Tetromino clockwise.
|
Rotates the Tetromino.
|
||||||
|
|
||||||
Does not rotate if the Tetromino is an O-shaped (square) figure.
|
Does not rotate if the Tetromino is an O-shaped (square) figure.
|
||||||
|
|
||||||
@ -81,12 +81,19 @@ class Tetromino:
|
|||||||
|
|
||||||
pivot: pygame.Vector2 = self.blocks[0].pos
|
pivot: pygame.Vector2 = self.blocks[0].pos
|
||||||
|
|
||||||
new_positions: list[pygame.Vector2] = [
|
for _ in range(3):
|
||||||
block.rotate(pivot, rotation) for block in self.blocks
|
new_positions: list[pygame.Vector2] = [
|
||||||
]
|
block.rotate(pivot, rotation) for block in self.blocks
|
||||||
|
]
|
||||||
|
|
||||||
if self._are_new_positions_valid(new_positions):
|
if self._are_new_positions_valid(new_positions):
|
||||||
self._update_block_positions(new_positions)
|
self._update_block_positions(new_positions)
|
||||||
|
return
|
||||||
|
|
||||||
|
if any(pos.x < 0 for pos in new_positions):
|
||||||
|
self.move_horizontal(Direction.RIGHT)
|
||||||
|
else:
|
||||||
|
self.move_horizontal(Direction.LEFT)
|
||||||
|
|
||||||
def drop(self) -> None:
|
def drop(self) -> None:
|
||||||
"""Drops the Tetromino to the bottom of the game field."""
|
"""Drops the Tetromino to the bottom of the game field."""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user