AI_PRO/main.py
2021-04-13 20:29:06 +02:00

62 lines
1.6 KiB
Python

import pygame
import Board
import TractorAction
import drawUI
from Tractor import Tractor
from TractorLoad import TillageUnit
from animations import animationsOn, animationsOff
from constants import *
from manualSteering import manualSteeringDriver
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=True,
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 = 11
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)
pygame.quit()
quit()