mirror of
https://github.com/kristoferssolo/2048.git
synced 2025-10-21 15:20:35 +00:00
fix(game): movement
Now all blocks don't leave gaps when moving
This commit is contained in:
parent
d2d5f9485b
commit
5f37bfea35
@ -9,8 +9,15 @@ from .utils import Direction
|
||||
|
||||
class Grid(pygame.sprite.Group):
|
||||
def move(self, direction: Direction):
|
||||
block: Block
|
||||
for block in self:
|
||||
blocks = list(self.sprites())
|
||||
|
||||
match direction:
|
||||
case Direction.DOWN:
|
||||
blocks.sort(key=lambda block: block.rect.y, reverse=True)
|
||||
case Direction.RIGHT:
|
||||
blocks.sort(key=lambda block: block.rect.x, reverse=True)
|
||||
|
||||
for block in blocks:
|
||||
block.move(direction)
|
||||
|
||||
def generate_random_block(self, count: int = 1) -> None:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user