AI_PRO/drawUI.py

59 lines
2.4 KiB
Python
Raw Normal View History

2021-03-29 02:19:55 +02:00
from Main.constants import *
from Main.images import *
import pygame
2021-03-29 04:17:31 +02:00
def drawUI(board, display, tractor, direction):
2021-03-29 02:19:55 +02:00
display.fill(WHITE)
makeField(board, display)
2021-03-29 04:17:31 +02:00
drawTractor(display, tractor.horizontal_index, tractor.vertical_index, direction)
drawInfo(display, tractor)
2021-03-29 02:19:55 +02:00
pygame.display.update()
2021-03-29 04:17:31 +02:00
def drawInfo(display, tractor):
myfont = pygame.font.SysFont('Comic Sans MS', 30)
text = f"Fuel: {tractor.fuel_tank} \t Hitches: {tractor.hitch} \t Header: {tractor.header} \t Engine working: {tractor.engineWorking}"
textsurface = myfont.render(text, False, (0, 0, 0))
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 200)))
2021-03-29 13:06:57 +02:00
text = f""
textsurface = myfont.render(text, False, (0, 0, 0))
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 150)))
2021-03-29 04:17:31 +02:00
2021-03-29 02:19:55 +02:00
def makeField(board, screen: pygame.Surface):
for i in range(int(HORIZONTAL_TILES_NUMBER)):
for j in range(int(VERTICAL_TILES_NUMBER)):
field = board[i][j]
pos_x = i * TILE_SIZE + TILE_SIZE // 2
pos_y = j * TILE_SIZE + TILE_SIZE // 2
2021-03-29 13:06:57 +02:00
if field.state == "toWater":
2021-03-29 02:19:55 +02:00
do_podlania_rect.center = (pos_x, pos_y)
screen.blit(do_podlania, do_podlania_rect)
2021-03-29 13:06:57 +02:00
elif field.state == "toPlow":
2021-03-29 02:19:55 +02:00
do_zaorania_rect.center = (pos_x, pos_y)
screen.blit(do_zaorania, do_zaorania_rect)
2021-03-29 13:06:57 +02:00
elif field.state == "toSeed":
2021-03-29 02:19:55 +02:00
do_zasiania_rect.center = (pos_x, pos_y)
screen.blit(do_zasiania, do_zasiania_rect)
2021-03-29 13:06:57 +02:00
elif field.state == "toCut":
2021-03-29 02:19:55 +02:00
do_zebrania_rect.center = (pos_x, pos_y)
screen.blit(do_zebrania, do_zebrania_rect)
def drawTractor(screen: pygame.Surface, tractor_horizontal_index, tractor_vertical_index, direction):
if direction == "UP":
screen.blit(tractor_up, (tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE))
elif direction is "DOWN":
screen.blit(tractor_down, (tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE))
elif direction == "LEFT":
screen.blit(tractor_left, (tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE))
elif direction == "RIGHT":
screen.blit(tractor_right, (tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE))
2021-03-29 02:53:27 +02:00
else:
screen.blit(tractor_right, (tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE))