feat(game): add Tetramino class

This commit is contained in:
Kristofers Solo 2024-01-04 02:02:48 +02:00
parent 54b5aa5774
commit 29d83322af
2 changed files with 22 additions and 1 deletions

View File

@ -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)

18
src/game/tetromino.py Normal file
View File

@ -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
]