From 29d83322afe3c1e07a6a0ad9d32dabd424568661 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Thu, 4 Jan 2024 02:02:48 +0200 Subject: [PATCH] feat(game): add `Tetramino` class --- src/game/game.py | 5 ++++- src/game/tetromino.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/game/tetromino.py diff --git a/src/game/game.py b/src/game/game.py index fa61967..09edc63 100644 --- a/src/game/game.py +++ b/src/game/game.py @@ -1,5 +1,7 @@ import pygame -from utils import CONFIG +from utils import CONFIG, Figure + +from .tetromino import Tetromino class Game: @@ -10,6 +12,7 @@ class Game: self.surface.fill(CONFIG.colors.bg_float) self.sprites = pygame.sprite.Group() + self.tetromino = Tetromino(None, group=self.sprites) def run(self) -> None: self.dispaly_surface.blit(self.surface, CONFIG.game.pos) diff --git a/src/game/tetromino.py b/src/game/tetromino.py new file mode 100644 index 0000000..acd0871 --- /dev/null +++ b/src/game/tetromino.py @@ -0,0 +1,18 @@ +from typing import Optional + +import pygame +from utils import CONFIG, Figure, FigureConfig, Size + +from .block import Block + + +class Tetromino: + def __init__(self, shape: Optional[Figure], /, group: pygame.sprite.Group) -> None: + self.figure: FigureConfig = shape.value if shape else Figure.random().value + self.block_positions: list[pygame.Vector2] = self.figure.shape + self.color: str = self.figure.color + + self.blocks = [ + Block(group=group, pos=pos, color=self.color) + for pos in self.block_positions + ]