mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
feat(game): add Tetramino class
This commit is contained in:
parent
54b5aa5774
commit
29d83322af
@ -1,5 +1,7 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from utils import CONFIG
|
from utils import CONFIG, Figure
|
||||||
|
|
||||||
|
from .tetromino import Tetromino
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
@ -10,6 +12,7 @@ class Game:
|
|||||||
self.surface.fill(CONFIG.colors.bg_float)
|
self.surface.fill(CONFIG.colors.bg_float)
|
||||||
|
|
||||||
self.sprites = pygame.sprite.Group()
|
self.sprites = pygame.sprite.Group()
|
||||||
|
self.tetromino = Tetromino(None, group=self.sprites)
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self.dispaly_surface.blit(self.surface, CONFIG.game.pos)
|
self.dispaly_surface.blit(self.surface, CONFIG.game.pos)
|
||||||
|
|||||||
18
src/game/tetromino.py
Normal file
18
src/game/tetromino.py
Normal 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
|
||||||
|
]
|
||||||
Loading…
Reference in New Issue
Block a user