forked from s452751/AI_PRO
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
from constants import *
|
|
from TractorAction import action
|
|
import pygame
|
|
|
|
|
|
def manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter):
|
|
if event.key == pygame.K_SPACE:
|
|
field = board[tractor.horizontal_index][tractor.vertical_index]
|
|
field.state = action(field, tractor)
|
|
if event.key == pygame.K_q:
|
|
hitchCounter = (hitchCounter + 1) % 3
|
|
if hitchCounter == 0:
|
|
tractor.hitch = "Crop Trailer"
|
|
if hitchCounter == 1:
|
|
tractor.hitch = tillageUnit
|
|
if hitchCounter == 2:
|
|
tractor.hitch = "Nothing"
|
|
if event.key == pygame.K_w:
|
|
if tractor.header:
|
|
tractor.header = False
|
|
else:
|
|
tractor.header = True
|
|
if event.key == pygame.K_e:
|
|
loadCounter = (loadCounter + 1) % 4
|
|
if loadCounter == 0:
|
|
tillageUnit.load = "Nothing"
|
|
elif loadCounter == 1:
|
|
tillageUnit.load = "Seeds"
|
|
elif loadCounter == 2:
|
|
tillageUnit.load = "Water"
|
|
elif loadCounter == 3:
|
|
tillageUnit.load = "Fertilizer"
|
|
|
|
if event.key == pygame.K_m:
|
|
tractor.drive()
|
|
|
|
if event.key == pygame.K_r:
|
|
if tractor.engineWorking:
|
|
tractor.turnOffEngine()
|
|
else:
|
|
tractor.turnOnEngine()
|
|
if event.key == pygame.K_t:
|
|
if tractor.autodrive:
|
|
tractor.autodrive = False
|
|
|
|
else:
|
|
tractor.autodrive = True
|
|
|
|
manualTurning(event, tractor)
|
|
return hitchCounter, loadCounter
|
|
|
|
|
|
def manualTurning(event, tractor):
|
|
tractor.direction = "STOP"
|
|
if event.type == pygame.KEYDOWN:
|
|
if event.key == pygame.K_LEFT and tractor.horizontal_index > 0:
|
|
tractor.direction = "LEFT"
|
|
elif event.key == pygame.K_RIGHT and tractor.horizontal_index < HORIZONTAL_TILES_NUMBER - 1:
|
|
tractor.direction = "RIGHT"
|
|
elif event.key == pygame.K_UP and tractor.vertical_index > 0:
|
|
tractor.direction = "UP"
|
|
elif event.key == pygame.K_DOWN and tractor.vertical_index < VERTICAL_TILES_NUMBER - 1:
|
|
tractor.direction = "DOWN"
|