feat(game): preview next figure images

This commit is contained in:
Kristofers Solo 2024-01-04 05:22:02 +02:00
parent 738627d409
commit e5475e6e5f
3 changed files with 25 additions and 6 deletions

View File

@ -34,7 +34,7 @@ class Main:
self.game.run() self.game.run()
self.score.run() self.score.run()
self.preview.run() self.preview.run(self.next_figures)
pygame.display.update() pygame.display.update()
self.clock.tick(CONFIG.fps) self.clock.tick(CONFIG.fps)

View File

@ -1,5 +1,5 @@
import pygame import pygame
from utils import CONFIG, Size from utils import CONFIG, Figure, Size
class Preview: class Preview:
@ -12,7 +12,26 @@ class Preview:
) )
) )
self.dispaly_surface = pygame.display.get_surface() self.dispaly_surface = pygame.display.get_surface()
self.surface.fill(CONFIG.colors.bg_sidebar)
def run(self) -> None: def run(self, next_figures: list[Figure]) -> None:
self.dispaly_surface.blit(self.surface, self.rect) self.dispaly_surface.blit(self.surface, self.rect)
self.draw(next_figures)
def draw(self, next_figures: list[Figure]) -> None:
self.surface.fill(CONFIG.colors.bg_sidebar)
self._draw_border()
self._draw_figures(next_figures)
def _draw_border(self) -> None:
pygame.draw.rect(
self.dispaly_surface,
CONFIG.colors.border_highlight,
self.rect,
CONFIG.game.line_width * 2,
CONFIG.game.border_radius,
)
def _draw_figures(self, figures: list[Figure]) -> None:
for figure in figures:
figure_surface = figure.value.image
self.surface.blit(figure_surface, (0, 0))

View File

@ -94,6 +94,6 @@ class Figure(Enum):
_load_image("L.png"), _load_image("L.png"),
) )
@staticmethod @classmethod
def random() -> "Figure": def random(cls) -> "Figure":
return random.choice(list(Figure)) return random.choice(list(Figure))