-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.py
executable file
·30 lines (23 loc) · 976 Bytes
/
text.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import pygame
TEXT_SIZE = 8
class TextRenderer:
def __init__(self):
letters = str(''' !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ÀàÂâÆæÇçÉéÈèÊêËëÎîÏïÔôŒœÙùÛûÜüŸÿ''')
# TODO: "'
self.letters = {}
for letter in letters:
self.letters[letter] = pygame.image.load(os.path.join('assets', 'tiles', 'font', str(ord(letter)) + '.bmp'))
def render(self, screen, rect: tuple[int, int, int, int], text: str):
x = rect[0]
y = rect[1]
for letter in text:
if letter not in '\n ':
screen.blit(self.letters[letter], (x, y))
elif letter == ' ':
x += TEXT_SIZE
if letter != '\n':
x += self.letters[letter].get_width()
if x >= rect[0] + rect[2] or letter == '\n':
x = rect[0]
y += TEXT_SIZE