-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
38 lines (27 loc) · 1.32 KB
/
utils.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
import pygame
def scale_image(image, factor):
scaled_image = pygame.transform.scale(image, (int(image.get_width() * factor), int(image.get_height() * factor)))
return scaled_image
def blit_text(text, font, color, surface, centered_x, centered_y, x = None, y = None):
textobj = font.render(text, 1, color)
if centered_x == True and centered_y == True:
textrect = textobj.get_rect()
textrect.topleft = (surface.get_width() / 2 - textrect.w / 2, surface.get_height() / 2 - textrect.h / 2)
surface.blit(textobj, textrect)
elif centered_x == True and centered_y == False:
textrect = textobj.get_rect()
textrect.topleft = (surface.get_width() / 2 - textrect.w /2, y)
surface.blit(textobj, textrect)
elif centered_x == False and centered_y == True:
textrect = textobj.get_rect()
textrect.topleft = (x, surface.get_height() / 2 - textrect.h / 2)
surface.blit(textobj, textrect)
else:
textrect = textobj.get_rect()
textrect.topleft = (x, y)
surface.blit(textobj, textrect)
def blit_status(status_list, font, color, surface, x , y, delta_y) -> None:
for each in status_list:
status_img = font.render(each, True, color)
surface.blit(status_img, (x, y))
y += delta_y #step in px's betwen each line