-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.py
46 lines (42 loc) · 1.41 KB
/
ui.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pygame
def event_exit() -> bool:
is_running = True
for event in pygame.event.get():
if event.type == pygame.QUIT:
is_running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
is_running = False
return is_running
_screen = None
def draw_screen(width: int, height: int, image: pygame.Surface) -> pygame.Surface:
global _screen
if _screen is None:
_screen = pygame.display.set_mode((width, height), pygame.DOUBLEBUF, 32)
# blit image on screen
_screen.blit(image, (0, 0))
return _screen
def print_fps(screen: pygame.Surface, clock: pygame.time.Clock):
font = pygame.font.SysFont("monospace", 15)
screen.blit(font.render("FPS %.2f"%(clock.get_fps()), 1, (255, 0, 0)), (0, 0))
_last_object = ""
def print_object(screen: pygame.Surface, receivedText: str) -> str:
result = ""
global _last_object
# objects from labels.txt
objects = (
"carta.class",
"empty.class",
"metallo.class",
"plastica.class",
"vetro.class"
)
font = pygame.font.SysFont("monospace", 15)
for object in objects:
if object in receivedText:
text = object.replace(".class", "")
result = text
text = text.upper()
_last_object = text
screen.blit(font.render(_last_object, 1, (255, 0, 0)), (95, 0))
return result