feat(game): add Block class

This commit is contained in:
Kristofers Solo 2024-01-04 01:15:34 +02:00
parent 06fa7c4cf7
commit e045779158
2 changed files with 18 additions and 2 deletions

13
src/game/block.py Normal file
View 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))

View File

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