79 lines
2.9 KiB
Python
79 lines
2.9 KiB
Python
from TractorLoad import TillageUnit
|
|
from constants import *
|
|
from images import *
|
|
import pygame
|
|
|
|
|
|
def drawUI(board, display, tractor, direction, tillageUnit, field):
|
|
for i in range(1, 21):
|
|
display.fill(WHITE)
|
|
makeField(board, display)
|
|
drawTractor(display, tractor.horizontal_index, tractor.vertical_index, direction, i)
|
|
drawInfo(display, tractor, tillageUnit, field)
|
|
pygame.display.update()
|
|
|
|
|
|
def drawInfo(display, tractor, tillageUnit, field):
|
|
myfont = pygame.font.SysFont('Comic Sans MS', 30)
|
|
hitches = tractor.hitch
|
|
if isinstance(tractor.hitch, TillageUnit):
|
|
hitches = "Tillage Unit"
|
|
|
|
text = f"Fuel: {tractor.fuel_tank} \t Hitches: {hitches} \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)))
|
|
|
|
text = f"Tillage Unit Load: {tillageUnit.load}"
|
|
textsurface = myfont.render(text, False, (0, 0, 0))
|
|
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 150)))
|
|
|
|
text = f"Current field: {field.state, field.horizontal/100, field.vertical/100}"
|
|
textsurface = myfont.render(text, False, (0, 0, 0))
|
|
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 100)))
|
|
|
|
|
|
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
|
|
|
|
if field.state == "toWater":
|
|
do_podlania_rect.center = (pos_x, pos_y)
|
|
screen.blit(do_podlania, do_podlania_rect)
|
|
elif field.state == "toPlow":
|
|
do_zaorania_rect.center = (pos_x, pos_y)
|
|
screen.blit(do_zaorania, do_zaorania_rect)
|
|
elif field.state == "toSeed":
|
|
do_zasiania_rect.center = (pos_x, pos_y)
|
|
screen.blit(do_zasiania, do_zasiania_rect)
|
|
elif field.state == "toCut":
|
|
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, i):
|
|
tractor_pic = tractor_up
|
|
horizontal = tractor_horizontal_index * TILE_SIZE
|
|
vertical = tractor_vertical_index * TILE_SIZE
|
|
|
|
|
|
i = i/10
|
|
|
|
if direction == "UP":
|
|
tractor_pic = tractor_up
|
|
vertical = vertical + (TILE_SIZE * i)
|
|
if direction == "DOWN":
|
|
tractor_pic = tractor_down
|
|
vertical = vertical - (TILE_SIZE * i)
|
|
if direction == "LEFT":
|
|
tractor_pic = tractor_left
|
|
horizontal = horizontal + (TILE_SIZE * i)
|
|
if direction == "RIGHT":
|
|
tractor_pic = tractor_right
|
|
horizontal = horizontal - (TILE_SIZE * i)
|
|
|
|
screen.blit(tractor_pic, (horizontal, vertical))
|