AI_PRO/driving.py

67 lines
2.1 KiB
Python
Raw Normal View History

2021-03-29 02:19:55 +02:00
from Main.drawUI import *
import pygame
2021-03-29 17:18:14 +02:00
def cruiseControl(tractor, direction, cruiseControl):
2021-03-29 03:41:38 +02:00
if cruiseControl == False or tractor.engineWorking == False:
2021-03-29 17:18:14 +02:00
direction = "STOP"
return direction
2021-03-29 02:19:55 +02:00
2021-03-29 17:18:14 +02:00
def manualTurning(event, tractor):
2021-03-29 19:15:36 +02:00
direction = "STOP"
2021-03-29 02:19:55 +02:00
if event.type == pygame.KEYDOWN:
2021-03-29 17:18:14 +02:00
if event.key == pygame.K_LEFT and tractor.horizontal_index > 0:
direction = "LEFT"
elif event.key == pygame.K_RIGHT and tractor.horizontal_index < HORIZONTAL_TILES_NUMBER - 1:
direction = "RIGHT"
elif event.key == pygame.K_UP and tractor.vertical_index > 0:
direction = "UP"
elif event.key == pygame.K_DOWN and tractor.vertical_index < VERTICAL_TILES_NUMBER - 1:
direction = "DOWN"
2021-03-29 20:30:21 +02:00
# tractor.drive(direction)
2021-03-29 04:17:31 +02:00
2021-03-29 17:18:14 +02:00
return direction
2021-03-29 02:19:55 +02:00
def getDirection(horizontal_change, vertical_change):
2021-03-29 02:53:27 +02:00
direction = "STOP"
2021-03-29 02:19:55 +02:00
if vertical_change == -1:
direction = "UP"
elif vertical_change == 1:
direction = "DOWN"
elif horizontal_change == 1:
direction = "RIGHT"
elif horizontal_change == -1:
direction = "LEFT"
return direction
2021-03-29 19:15:36 +02:00
def autodrive(tractor, autonomousDrive, direction, comeback):
if autonomousDrive:
if not comeback:
if direction == "RIGHT" and tractor.horizontal_index == HORIZONTAL_TILES_NUMBER - 1:
direction = "DOWN"
elif direction == "DOWN" and tractor.horizontal_index == HORIZONTAL_TILES_NUMBER - 1:
direction = "LEFT"
elif direction == "LEFT" and tractor.horizontal_index == 0:
direction = "DOWN"
elif direction == "DOWN" and tractor.horizontal_index == 0:
direction = "RIGHT"
else:
direction = "UP"
return direction
def isComebackTime(tractor, direction, comeback):
if tractor.vertical_index == 5 and tractor.horizontal_index == 0:
comeback = True
print(comeback)
direction = "UP"
if tractor.vertical_index == 0 and tractor.horizontal_index == 0:
comeback = False
print(comeback)
direction = "RIGHT"
return comeback, direction