AI_PRO/main.py
2021-04-14 00:05:16 +02:00

66 lines
1.7 KiB
Python

import pygame
import Board
import TractorAction
import drawUI
from FindPath import graphsearch
from Tractor import Tractor
from TractorLoad import TillageUnit
from animations import animationsOn, animationsOff
from constants import *
from manualSteering import manualSteeringDriver
from queue import Queue
pygame.init()
display = pygame.display.set_mode((DISPLAY_SIZE_HORIZONTAL, DISPLAY_SIZE_VERTICAL))
pygame.display.set_caption('Tractor')
working = True
autoAction = True
animationSpeed = ANIMATION_PART
hitchCounter = 0
loadCounter = 0
toolCounter = - 1
board = Board.generate()
tractor = Tractor(horizontal_index=-0, vertical_index=0, hitch="nothing", header=False, autodrive=False,
direction='RIGHT')
tillageUnit = TillageUnit("Nothing")
tractor.turnOnEngine()
clock = pygame.time.Clock()
while working:
for event in pygame.event.get():
if event.type == pygame.QUIT:
working = False
if event.type == pygame.KEYDOWN:
hitchCounter, loadCounter = \
manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter)
field = board[tractor.horizontal_index][tractor.vertical_index]
if tractor.autodrive and tractor.engineWorking:
animationSpeed = ANIMATION_PART
else:
animationSpeed = 1
print(ANIMATION_PART)
if tractor.autodrive:
tractor, tillageUnit, toolCounter = TractorAction.autoToolsChange(tractor, tillageUnit, toolCounter)
field.state = TractorAction.changeFieldState(field, tractor)
drawUI.drawUI(board, display, tractor, tractor.direction, tillageUnit, field, animationSpeed)
clock.tick(FPS)
graphsearch(tractor, board, TillageUnit, Queue(), list())
pygame.quit()
quit()