AI_PRO/manualSteering.py

69 lines
2.2 KiB
Python
Raw Normal View History

2021-04-13 17:52:27 +02:00
import driving
from constants import *
from TractorAction import action
import pygame
def manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter, ANIMATION_PART):
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_r:
if tractor.engineWorking:
tractor.turnOffEngine()
else:
tractor.turnOnEngine()
if event.key == pygame.K_t:
if tractor.autodrive:
tractor.autodrive = False
cruiseControl = False
autoAction = False
animationSpeed = 1
else:
tractor.autodrive = True
animationSpeed = ANIMATION_PART
cruiseControl = True
autoAction = True
manualTurning(event, tractor)
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"