63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
from TractorAction import changeFieldState
|
|
from constants import *
|
|
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 = changeFieldState(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):
|
|
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"
|