chore: change bmp font and test text gen
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
window:
|
||||
width: 800
|
||||
height: 600
|
||||
icon: "resource/image/tetris_icon.png"
|
||||
|
||||
title: "Tetris"
|
||||
|
||||
sound:
|
||||
@@ -9,6 +9,10 @@ sound:
|
||||
row-completion: "resource/sound/row_completion.wav"
|
||||
piece-set: "resource/sound/piece_set_3.wav"
|
||||
|
||||
image:
|
||||
window-icon: "resource/image/tetris_icon.png"
|
||||
font: "resource/image/press-start-2p-font.bmp"
|
||||
|
||||
engine:
|
||||
fps: 60
|
||||
tile-size: 20
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 192 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 192 KiB |
BIN
resource/image/press-start-2p-font.bmp
Normal file
BIN
resource/image/press-start-2p-font.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 192 KiB |
@@ -23,12 +23,12 @@ class Game:
|
||||
|
||||
def initialize(self) -> None:
|
||||
pygame.init()
|
||||
TextGenerator.load("resource/font/retro-font.bmp", (20, 30))
|
||||
TextGenerator.load(ConfigurationManager.get("image", "font"), (20, 20))
|
||||
|
||||
win_width = ConfigurationManager.get("window", "width")
|
||||
win_height = ConfigurationManager.get("window", "height")
|
||||
win_icon = ConfigurationManager.get("window", "icon")
|
||||
win_title = ConfigurationManager.get("window", "title")
|
||||
win_icon = ConfigurationManager.get("image", "window-icon")
|
||||
|
||||
self.fps = ConfigurationManager.get("engine", "fps")
|
||||
self.tile_size = ConfigurationManager.get("engine", "tile-size")
|
||||
@@ -121,9 +121,15 @@ class Game:
|
||||
self.stack.draw(self.screen)
|
||||
if self.current_piece:
|
||||
self.current_piece.draw(self.screen)
|
||||
|
||||
TextGenerator.draw("SCORE", (0, 0), self.screen)
|
||||
|
||||
TextGenerator.draw("Top", (80, 120), self.screen)
|
||||
TextGenerator.draw("000000", (80, 140), self.screen)
|
||||
|
||||
TextGenerator.draw("Score", (80, 180), self.screen)
|
||||
TextGenerator.draw("000000", (80, 200), self.screen)
|
||||
|
||||
TextGenerator.draw("Lines 0000", (300, 40), self.screen)
|
||||
|
||||
# update display
|
||||
pygame.display.update()
|
||||
|
||||
|
||||
@@ -22,27 +22,65 @@ class ConfigurationManager:
|
||||
else:
|
||||
return cls.configuration[key]
|
||||
|
||||
"""
|
||||
TODO description
|
||||
"""
|
||||
class TextGenerator:
|
||||
|
||||
sheet = None
|
||||
glyph_size = -1
|
||||
letters = { }
|
||||
numbers = { }
|
||||
glyph_size = (-1, -1)
|
||||
characters = { }
|
||||
|
||||
@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])
|
||||
# load character positions in bitmap into the characters dictionary
|
||||
# letters
|
||||
cls.characters["A"] = (9 * glyph_size[0], 2 * glyph_size[1])
|
||||
cls.characters["B"] = (10 * glyph_size[0], 2 * glyph_size[1])
|
||||
cls.characters["C"] = (11 * glyph_size[0], 2 * glyph_size[1])
|
||||
cls.characters["D"] = (0 * glyph_size[0], 3 * glyph_size[1])
|
||||
cls.characters["E"] = (1 * glyph_size[0], 3 * glyph_size[1])
|
||||
cls.characters["F"] = (2 * glyph_size[0], 3 * glyph_size[1])
|
||||
cls.characters["G"] = (3 * glyph_size[0], 3 * glyph_size[1])
|
||||
cls.characters["H"] = (4 * glyph_size[0], 3 * glyph_size[1])
|
||||
cls.characters["I"] = (5 * glyph_size[0], 3 * glyph_size[1])
|
||||
cls.characters["J"] = (6 * glyph_size[0], 3 * glyph_size[1])
|
||||
cls.characters["K"] = (7 * glyph_size[0], 3 * glyph_size[1])
|
||||
cls.characters["L"] = (8 * glyph_size[0], 3 * glyph_size[1])
|
||||
cls.characters["M"] = (9 * glyph_size[0], 3 * glyph_size[1])
|
||||
cls.characters["N"] = (10 * glyph_size[0], 3 * glyph_size[1])
|
||||
cls.characters["O"] = (11 * glyph_size[0], 3 * glyph_size[1])
|
||||
cls.characters["P"] = (0 * glyph_size[0], 4 * glyph_size[1])
|
||||
cls.characters["Q"] = (1 * glyph_size[0], 4 * glyph_size[1])
|
||||
cls.characters["R"] = (2 * glyph_size[0], 4 * glyph_size[1])
|
||||
cls.characters["S"] = (3 * glyph_size[0], 4 * glyph_size[1])
|
||||
cls.characters["T"] = (4 * glyph_size[0], 4 * glyph_size[1])
|
||||
cls.characters["U"] = (5 * glyph_size[0], 4 * glyph_size[1])
|
||||
cls.characters["V"] = (6 * glyph_size[0], 4 * glyph_size[1])
|
||||
cls.characters["W"] = (7 * glyph_size[0], 4 * glyph_size[1])
|
||||
cls.characters["X"] = (8 * glyph_size[0], 4 * glyph_size[1])
|
||||
cls.characters["Y"] = (9 * glyph_size[0], 4 * glyph_size[1])
|
||||
cls.characters["Z"] = (10 * glyph_size[0], 4 * glyph_size[1])
|
||||
|
||||
# numbers
|
||||
cls.characters["0"] = (4 * glyph_size[0], 1 * glyph_size[1])
|
||||
cls.characters["1"] = (5 * glyph_size[0], 1 * glyph_size[1])
|
||||
cls.characters["2"] = (6 * glyph_size[0], 1 * glyph_size[1])
|
||||
cls.characters["3"] = (7 * glyph_size[0], 1 * glyph_size[1])
|
||||
cls.characters["4"] = (8 * glyph_size[0], 1 * glyph_size[1])
|
||||
cls.characters["5"] = (9 * glyph_size[0], 1 * glyph_size[1])
|
||||
cls.characters["6"] = (10 * glyph_size[0], 1 * glyph_size[1])
|
||||
cls.characters["7"] = (11 * glyph_size[0], 1 * glyph_size[1])
|
||||
cls.characters["8"] = (0 * glyph_size[0], 2 * glyph_size[1])
|
||||
cls.characters["9"] = (1 * glyph_size[0], 2 * 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])))
|
||||
if not char_.isspace():
|
||||
surface.blit(cls.sheet, (position[0] + x_position, position[1]), pygame.Rect(cls.characters[char_.upper()], (cls.glyph_size[0], cls.glyph_size[1])))
|
||||
x_position += cls.glyph_size[0]
|
||||
Reference in New Issue
Block a user