mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
fix(game): grid border render
This commit is contained in:
parent
b5e7a7b12f
commit
5291ca5de5
@ -11,42 +11,53 @@ class Game:
|
|||||||
self.rect = self.surface.get_rect(topleft=CONFIG.game.pos)
|
self.rect = self.surface.get_rect(topleft=CONFIG.game.pos)
|
||||||
self.surface.fill(CONFIG.colors.bg_float)
|
self.surface.fill(CONFIG.colors.bg_float)
|
||||||
|
|
||||||
|
self._create_grid_surface()
|
||||||
|
|
||||||
self.sprites = pygame.sprite.Group()
|
self.sprites = pygame.sprite.Group()
|
||||||
self.tetromino = Tetromino(None, group=self.sprites)
|
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)
|
||||||
|
self.draw()
|
||||||
|
|
||||||
def draw(self) -> None:
|
def draw(self) -> None:
|
||||||
self._draw_grid()
|
|
||||||
self._draw_border()
|
|
||||||
self.sprites.draw(self.surface)
|
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:
|
def _draw_grid(self) -> None:
|
||||||
for col in range(1, CONFIG.game.columns):
|
for col in range(1, CONFIG.game.columns):
|
||||||
x = col * CONFIG.game.cell.width
|
x = col * CONFIG.game.cell.width
|
||||||
pygame.draw.line(
|
pygame.draw.line(
|
||||||
self.surface,
|
self.grid_surface,
|
||||||
CONFIG.colors.border_highlight,
|
CONFIG.colors.border_highlight,
|
||||||
(x, 0),
|
(x, 0),
|
||||||
(x, self.surface.get_height()),
|
(x, self.grid_surface.get_height()),
|
||||||
CONFIG.game.line_width,
|
CONFIG.game.line_width,
|
||||||
)
|
)
|
||||||
for row in range(1, CONFIG.game.rows):
|
for row in range(1, CONFIG.game.rows):
|
||||||
y = row * CONFIG.game.cell.width
|
y = row * CONFIG.game.cell.width
|
||||||
pygame.draw.line(
|
pygame.draw.line(
|
||||||
self.surface,
|
self.grid_surface,
|
||||||
CONFIG.colors.border_highlight,
|
CONFIG.colors.border_highlight,
|
||||||
(0, y),
|
(0, y),
|
||||||
(self.surface.get_width(), y),
|
(self.grid_surface.get_width(), y),
|
||||||
CONFIG.game.line_width,
|
CONFIG.game.line_width,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.surface.blit(self.grid_surface, (0, 0))
|
||||||
|
|
||||||
def _draw_border(self) -> None:
|
def _draw_border(self) -> None:
|
||||||
pygame.draw.rect(
|
pygame.draw.rect(
|
||||||
self.dispaly_surface,
|
self.dispaly_surface,
|
||||||
CONFIG.colors.border_highlight,
|
CONFIG.colors.border_highlight,
|
||||||
self.rect,
|
self.rect,
|
||||||
CONFIG.game.line_width,
|
CONFIG.game.line_width * 2,
|
||||||
CONFIG.game.border_radius,
|
CONFIG.game.border_radius,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -22,7 +22,6 @@ class Main:
|
|||||||
|
|
||||||
def draw(self) -> None:
|
def draw(self) -> None:
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
self.game.draw()
|
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
@ -12,12 +12,12 @@ class Game:
|
|||||||
columns: int = 10
|
columns: int = 10
|
||||||
rows: int = 20
|
rows: int = 20
|
||||||
line_width: int = 1
|
line_width: int = 1
|
||||||
border_radius: int = 2
|
border_radius: int = 5
|
||||||
padding: int = PADDING
|
padding: int = PADDING
|
||||||
cell: Size = Size(40, 40)
|
cell: Size = Size(40, 40)
|
||||||
size: Size = Size(columns * cell.width, rows * cell.width)
|
size: Size = Size(columns * cell.width, rows * cell.width)
|
||||||
pos: Vec2 = Vec2(padding, padding)
|
pos: Vec2 = Vec2(padding, padding)
|
||||||
offset: Vec2 = Vec2(columns // 2, -1)
|
offset: Vec2 = Vec2(columns // 2, 5)
|
||||||
|
|
||||||
|
|
||||||
@define
|
@define
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user