WMICraft/common/helpers.py

31 lines
1.1 KiB
Python
Raw Normal View History

2022-03-09 16:59:58 +01:00
import pygame
2022-04-11 00:01:57 +02:00
from common.constants import GRID_CELL_PADDING, GRID_CELL_SIZE, COLUMNS, ROWS
2022-03-09 16:59:58 +01:00
def draw_text(text, color, surface, x, y, text_size=30, is_bold=False):
if is_bold:
font = pygame.font.Font('resources/fonts/Poppins-SemiBold.ttf', text_size)
else:
font = pygame.font.Font('resources/fonts/Poppins-Regular.ttf', text_size)
textobj = font.render(text, 1, color)
textrect = textobj.get_rect()
textrect.topleft = (x, y)
surface.blit(textobj, textrect)
2022-04-11 00:01:57 +02:00
def print_numbers():
display_surface = pygame.display.get_surface()
font = pygame.font.SysFont('Arial', 16)
for row_index in range(ROWS):
for col_index in range(COLUMNS):
x = (GRID_CELL_PADDING + GRID_CELL_SIZE) * col_index + GRID_CELL_PADDING + 7
y = (GRID_CELL_PADDING + GRID_CELL_SIZE) * row_index + GRID_CELL_PADDING + 16
display_surface.blit(font.render(f'[{col_index}, {row_index}]', True, (255, 0, 0)), (x, y))
pygame.display.update()
# parse array index to screen x or y coordinate
def parse_cord(cord):
return (GRID_CELL_PADDING + GRID_CELL_SIZE) * cord + GRID_CELL_PADDING + 7