AI_PRO/manualSteering.py

68 lines
2.3 KiB
Python
Raw Normal View History

2021-04-13 17:52:27 +02:00
from constants import *
from TractorAction import action
import pygame
2021-04-13 18:48:24 +02:00
2021-04-13 18:09:27 +02:00
def manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter, animationSpeed):
2021-04-13 17:52:27 +02:00
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"
2021-04-13 18:48:24 +02:00
if event.key == pygame.K_SPACE:
tractor.drive()
2021-04-13 17:52:27 +02:00
if event.key == pygame.K_r:
if tractor.engineWorking:
tractor.turnOffEngine()
2021-04-13 18:40:58 +02:00
animationSpeed = 1
2021-04-13 17:52:27 +02:00
else:
tractor.turnOnEngine()
2021-04-13 18:40:58 +02:00
animationSpeed = ANIMATION_PART
2021-04-13 17:52:27 +02:00
if event.key == pygame.K_t:
if tractor.autodrive:
tractor.autodrive = False
animationSpeed = 1
else:
tractor.autodrive = True
animationSpeed = ANIMATION_PART
manualTurning(event, tractor)
2021-04-13 18:09:27 +02:00
return hitchCounter, loadCounter, animationSpeed
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"