diff --git a/resource/font/retro-font.bmp b/resource/font/retro-font.bmp new file mode 100644 index 0000000..3cd2d48 Binary files /dev/null and b/resource/font/retro-font.bmp differ diff --git a/tetris/game.py b/tetris/game.py index d58f60d..dc8e6be 100644 --- a/tetris/game.py +++ b/tetris/game.py @@ -1,7 +1,9 @@ import sys +from typing import Text import pygame from pygame import mixer from tetris.util import ConfigurationManager +from tetris.util import TextGenerator from tetris.entity import PieceGenerator from tetris.entity import Well from tetris.entity import Stack @@ -21,6 +23,7 @@ class Game: def initialize(self) -> None: pygame.init() + TextGenerator.load("resource/font/retro-font.bmp", (20, 30)) win_width = ConfigurationManager.get("window", "width") win_height = ConfigurationManager.get("window", "height") @@ -119,9 +122,8 @@ class Game: if self.current_piece: self.current_piece.draw(self.screen) - self.sheet = pygame.image.load("resource/font/gravity-font.bmp").convert() - self.screen.blit(self.sheet, (0, 0), pygame.Rect(30, 30, 30, 30)) - + TextGenerator.draw("SCORE", (0, 0), self.screen) + # update display pygame.display.update() diff --git a/tetris/util.py b/tetris/util.py index 52b94d1..3f54741 100644 --- a/tetris/util.py +++ b/tetris/util.py @@ -1,5 +1,5 @@ -import random import yaml +import pygame from typing import Tuple """ @@ -20,4 +20,29 @@ class ConfigurationManager: if sub_key: return cls.configuration[key][sub_key] else: - return cls.configuration[key] \ No newline at end of file + return cls.configuration[key] + +class TextGenerator: + + sheet = None + glyph_size = -1 + letters = { } + numbers = { } + + @classmethod + def load(cls, file: str, glyph_size: Tuple) -> None: + cls.sheet = pygame.image.load(file) + cls.glyph_size = glyph_size + + cls.letters["S"] = (3 * glyph_size[0], 6 * glyph_size[1]) + cls.letters["C"] = (3 * glyph_size[0], 4 * glyph_size[1]) + cls.letters["O"] = (7 * glyph_size[0], 5 * glyph_size[1]) + cls.letters["R"] = (2 * glyph_size[0], 6 * glyph_size[1]) + cls.letters["E"] = (5 * glyph_size[0], 4 * glyph_size[1]) + + @classmethod + def draw(cls, text: str, position: Tuple, surface: pygame.Surface) -> None: + x_position = 0 + for char_ in text: + surface.blit(cls.sheet, (position[0] + x_position, position[1]), pygame.Rect(cls.letters[char_.upper()], (cls.glyph_size[0], cls.glyph_size[1]))) + x_position += cls.glyph_size[0] \ No newline at end of file