2021-03-29 20:51:47 +02:00
|
|
|
from TractorLoad import TillageUnit
|
|
|
|
from constants import *
|
|
|
|
from images import *
|
2021-03-29 02:19:55 +02:00
|
|
|
import pygame
|
|
|
|
|
|
|
|
|
2021-05-19 04:45:37 +02:00
|
|
|
def drawUI(board, display, tractor, direction, tillageUnit, field, animationSpeed, weather, day_time, temperature, wind, humidy, decision):
|
2021-03-30 00:54:29 +02:00
|
|
|
if animationSpeed == 1:
|
|
|
|
display.fill(WHITE)
|
|
|
|
makeField(board, display)
|
|
|
|
drawTractor(display, tractor.horizontal_index, tractor.vertical_index, direction, 0)
|
2021-05-19 04:45:37 +02:00
|
|
|
drawInfo(display, tractor, tillageUnit, field, direction, weather, day_time, temperature, wind, humidy, decision)
|
2021-03-30 00:54:29 +02:00
|
|
|
pygame.display.update()
|
|
|
|
for i in range(1, animationSpeed):
|
2021-03-29 21:59:19 +02:00
|
|
|
display.fill(WHITE)
|
|
|
|
makeField(board, display)
|
|
|
|
drawTractor(display, tractor.horizontal_index, tractor.vertical_index, direction, i)
|
2021-03-30 00:54:29 +02:00
|
|
|
drawInfo(display, tractor, tillageUnit, field, direction)
|
2021-03-29 21:59:19 +02:00
|
|
|
pygame.display.update()
|
2021-03-29 02:19:55 +02:00
|
|
|
|
|
|
|
|
2021-05-19 04:45:37 +02:00
|
|
|
def drawInfo(display, tractor, tillageUnit, field, direction, weather, day_time, temperature, wind, humidy, decision):
|
2021-03-29 04:17:31 +02:00
|
|
|
myfont = pygame.font.SysFont('Comic Sans MS', 30)
|
2021-03-29 14:36:28 +02:00
|
|
|
hitches = tractor.hitch
|
|
|
|
if isinstance(tractor.hitch, TillageUnit):
|
|
|
|
hitches = "Tillage Unit"
|
2021-05-19 05:12:42 +02:00
|
|
|
if decision == [0]:
|
|
|
|
decision = "Wait"
|
|
|
|
else:
|
|
|
|
decision = "Make Action"
|
2021-03-29 14:36:28 +02:00
|
|
|
|
2021-03-30 00:54:29 +02:00
|
|
|
text = f"(Q)Hitches: {hitches} (W)Header: {tractor.header} (R)Engine working: {tractor.engineWorking} (T)Autodrive: {tractor.autodrive} Fuel: {tractor.fuel_tank}"
|
2021-03-29 04:17:31 +02:00
|
|
|
textsurface = myfont.render(text, False, (0, 0, 0))
|
|
|
|
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 200)))
|
|
|
|
|
2021-03-30 00:54:29 +02:00
|
|
|
text = f"(E)Tillage Unit Load: {tillageUnit.load} (^) Direction: {direction}"
|
2021-03-29 13:06:57 +02:00
|
|
|
textsurface = myfont.render(text, False, (0, 0, 0))
|
|
|
|
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 150)))
|
|
|
|
|
2021-05-19 04:45:37 +02:00
|
|
|
text = f"Current field: {field.horizontal_index/100, field.vertical_index/100, field.state} Action: {decision}"
|
2021-03-29 14:33:16 +02:00
|
|
|
textsurface = myfont.render(text, False, (0, 0, 0))
|
|
|
|
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 100)))
|
|
|
|
|
2021-05-19 04:45:37 +02:00
|
|
|
text = f"Weather: {weather} Day Time: {day_time} Temperature: {temperature} Wind: {wind} Humidy: {humidy}"
|
|
|
|
textsurface = myfont.render(text, False, (0, 0, 0))
|
|
|
|
display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 50)))
|
|
|
|
|
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 21:40:55 +02:00
|
|
|
to_water_rect.center = (pos_x, pos_y)
|
|
|
|
screen.blit(to_water, to_water_rect)
|
2021-03-29 13:06:57 +02:00
|
|
|
elif field.state == "toPlow":
|
2021-03-29 21:40:55 +02:00
|
|
|
to_plow_rect.center = (pos_x, pos_y)
|
|
|
|
screen.blit(to_plow, to_plow_rect)
|
2021-03-29 13:06:57 +02:00
|
|
|
elif field.state == "toSeed":
|
2021-03-29 21:40:55 +02:00
|
|
|
to_seed_rect.center = (pos_x, pos_y)
|
|
|
|
screen.blit(to_seed, to_seed_rect)
|
2021-03-29 13:06:57 +02:00
|
|
|
elif field.state == "toCut":
|
2021-03-29 21:40:55 +02:00
|
|
|
to_cut_rect.center = (pos_x, pos_y)
|
|
|
|
screen.blit(to_cut, to_cut_rect)
|
|
|
|
elif field.state == "toFertilize":
|
|
|
|
to_fertilizer_rect.center = (pos_x, pos_y)
|
|
|
|
screen.blit(to_fertilizer, to_fertilizer_rect)
|
2021-03-29 02:19:55 +02:00
|
|
|
|
2021-03-30 00:54:29 +02:00
|
|
|
elif field.state == "TOOLS_FIELD":
|
|
|
|
tools_rect.center = (pos_x, pos_y)
|
|
|
|
screen.blit(tools, tools_rect)
|
|
|
|
|
|
|
|
elif field.state == "FUEL_FIELD":
|
|
|
|
fuel_rect.center = (pos_x, pos_y)
|
|
|
|
screen.blit(fuel, fuel_rect)
|
|
|
|
|
2021-03-29 02:19:55 +02:00
|
|
|
|
2021-03-29 21:59:19 +02:00
|
|
|
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
|
|
|
|
|
2021-03-30 00:54:29 +02:00
|
|
|
i = i/ANIMATION_PART
|
2021-03-29 21:59:19 +02:00
|
|
|
|
2021-03-29 02:19:55 +02:00
|
|
|
if direction == "UP":
|
2021-03-29 21:59:19 +02:00
|
|
|
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))
|