feat(game): display text

This commit is contained in:
Kristofers Solo 2024-01-04 05:57:39 +02:00
parent 99f316d35a
commit ee179036e2

View File

@ -9,7 +9,37 @@ class Score:
self.rect = self.surface.get_rect( self.rect = self.surface.get_rect(
bottomright=CONFIG.window.size.sub(CONFIG.window.padding) bottomright=CONFIG.window.size.sub(CONFIG.window.padding)
) )
self.surface.fill(CONFIG.colors.bg_sidebar)
self.font = pygame.font.Font(CONFIG.font.family, CONFIG.font.size)
self.text = ["Score", "Level", "Lines"]
self.increment_height = self.surface.get_height() / 3
def run(self) -> None: def run(self) -> None:
self.dispaly_surface.blit(self.surface, self.rect) self.dispaly_surface.blit(self.surface, self.rect)
self.draw()
def draw(self) -> None:
self.surface.fill(CONFIG.colors.bg_sidebar)
self._draw_text()
self._draw_border()
def _draw_text(self) -> None:
for idx, text in enumerate(self.text):
x = self.surface.get_width() / 2
y = self.increment_height / 2 + idx * self.increment_height
self._display_text(text, (x, y))
def _display_text(self, text: str, pos: tuple[int, int]) -> None:
text_surface = self.font.render(text, True, CONFIG.colors.fg_sidebar)
text_rect = text_surface.get_rect(center=pos)
self.surface.blit(text_surface, text_rect)
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,
)