mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
feat(game): add Block class
This commit is contained in:
parent
06fa7c4cf7
commit
e045779158
13
src/game/block.py
Normal file
13
src/game/block.py
Normal file
@ -0,0 +1,13 @@
|
||||
import pygame
|
||||
from utils import CONFIG, Position, Size
|
||||
|
||||
|
||||
class Block(pygame.sprite.Sprite):
|
||||
def __init__(
|
||||
self, /, *, group: pygame.sprite.Group, pos: Position, color: str
|
||||
) -> None:
|
||||
super().__init__(group)
|
||||
self.image = pygame.Surface(CONFIG.game.cell)
|
||||
self.image.fill(color)
|
||||
|
||||
self.rect = self.image.get_rect(topleft=(0, 0))
|
||||
@ -9,16 +9,19 @@ class Game:
|
||||
self.rect = self.surface.get_rect(topleft=CONFIG.game.pos)
|
||||
self.surface.fill(CONFIG.colors.bg_float)
|
||||
|
||||
self.sprites = pygame.sprite.Group()
|
||||
|
||||
def run(self) -> None:
|
||||
self.dispaly_surface.blit(self.surface, CONFIG.game.pos)
|
||||
|
||||
def draw(self) -> None:
|
||||
self._draw_grid()
|
||||
self._draw_border()
|
||||
self.sprites.draw(self.surface)
|
||||
|
||||
def _draw_grid(self) -> None:
|
||||
for col in range(1, CONFIG.game.columns):
|
||||
x = col * CONFIG.game.cell_size
|
||||
x = col * CONFIG.game.cell.width
|
||||
pygame.draw.line(
|
||||
self.surface,
|
||||
CONFIG.colors.border_highlight,
|
||||
@ -27,7 +30,7 @@ class Game:
|
||||
CONFIG.game.line_width,
|
||||
)
|
||||
for row in range(1, CONFIG.game.rows):
|
||||
y = row * CONFIG.game.cell_size
|
||||
y = row * CONFIG.game.cell.width
|
||||
pygame.draw.line(
|
||||
self.surface,
|
||||
CONFIG.colors.border_highlight,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user