AI_PRO/manualSteering.py

64 lines
2.1 KiB
Python
Raw Normal View History

2021-04-13 20:29:06 +02:00
from TractorAction import changeFieldState
2021-04-13 17:52:27 +02:00
from constants import *
import pygame
2021-04-13 18:48:24 +02:00
2021-04-13 18:57:48 +02:00
def manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter):
2021-04-13 17:52:27 +02:00
if event.key == pygame.K_SPACE:
field = board[tractor.horizontal_index][tractor.vertical_index]
2021-04-13 20:29:06 +02:00
field.state = changeFieldState(field, tractor)
2021-04-13 17:52:27 +02:00
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"
2021-04-13 18:48:24 +02:00
2021-04-13 18:57:48 +02:00
if event.key == pygame.K_m:
2021-04-13 18:48:24 +02:00
tractor.drive()
2021-04-13 17:52:27 +02:00
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)
2021-04-13 18:57:48 +02:00
return hitchCounter, loadCounter
2021-04-13 17:52:27 +02:00
2021-04-13 18:48:24 +02:00
2021-04-13 17:52:27 +02:00
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"