fix(game): grid border render

This commit is contained in:
Kristofers Solo 2024-01-04 02:15:58 +02:00
parent b5e7a7b12f
commit 5291ca5de5
3 changed files with 20 additions and 10 deletions

View File

@ -11,42 +11,53 @@ class Game:
self.rect = self.surface.get_rect(topleft=CONFIG.game.pos)
self.surface.fill(CONFIG.colors.bg_float)
self._create_grid_surface()
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)
self.draw()
def draw(self) -> None:
self._draw_grid()
self._draw_border()
self.sprites.draw(self.surface)
self._draw_border()
self._draw_grid()
def _create_grid_surface(self) -> None:
self.grid_surface = self.surface.copy()
self.grid_surface.fill("#00ff00")
self.grid_surface.set_colorkey("#00ff00")
self.grid_surface.set_alpha(100)
def _draw_grid(self) -> None:
for col in range(1, CONFIG.game.columns):
x = col * CONFIG.game.cell.width
pygame.draw.line(
self.surface,
self.grid_surface,
CONFIG.colors.border_highlight,
(x, 0),
(x, self.surface.get_height()),
(x, self.grid_surface.get_height()),
CONFIG.game.line_width,
)
for row in range(1, CONFIG.game.rows):
y = row * CONFIG.game.cell.width
pygame.draw.line(
self.surface,
self.grid_surface,
CONFIG.colors.border_highlight,
(0, y),
(self.surface.get_width(), y),
(self.grid_surface.get_width(), y),
CONFIG.game.line_width,
)
self.surface.blit(self.grid_surface, (0, 0))
def _draw_border(self) -> None:
pygame.draw.rect(
self.dispaly_surface,
CONFIG.colors.border_highlight,
self.rect,
CONFIG.game.line_width,
CONFIG.game.line_width * 2,
CONFIG.game.border_radius,
)

View File

@ -22,7 +22,6 @@ class Main:
def draw(self) -> None:
pygame.display.update()
self.game.draw()
def run(self) -> None:
while True:

View File

@ -12,12 +12,12 @@ class Game:
columns: int = 10
rows: int = 20
line_width: int = 1
border_radius: int = 2
border_radius: int = 5
padding: int = PADDING
cell: Size = Size(40, 40)
size: Size = Size(columns * cell.width, rows * cell.width)
pos: Vec2 = Vec2(padding, padding)
offset: Vec2 = Vec2(columns // 2, -1)
offset: Vec2 = Vec2(columns // 2, 5)
@define