AI_PRO/driving.py

46 lines
1.6 KiB
Python
Raw Normal View History

2021-03-29 02:19:55 +02:00
from Main.drawUI import *
import pygame
2021-03-29 03:41:38 +02:00
def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor):
if cruiseControl == False or tractor.engineWorking == False:
2021-03-29 02:19:55 +02:00
horizontal_change = 0
vertical_change = 0
2021-03-29 03:41:38 +02:00
if tractor.horizontal_index <= 0 or tractor.horizontal_index >= HORIZONTAL_TILES_NUMBER - 1:
2021-03-29 02:19:55 +02:00
horizontal_change = 0
2021-03-29 03:41:38 +02:00
if tractor.vertical_index <= 0 or tractor.vertical_index >= VERTICAL_TILES_NUMBER - 1:
2021-03-29 02:19:55 +02:00
vertical_change = 0
return horizontal_change, vertical_change
2021-03-29 04:17:31 +02:00
def manualTurning(event, tractor_horizontal_index, tractor_vertical_index, horizontal_change, vertical_change):
2021-03-29 02:19:55 +02:00
if event.type == pygame.KEYDOWN:
2021-03-29 04:17:31 +02:00
2021-03-29 02:19:55 +02:00
if event.key == pygame.K_LEFT and tractor_horizontal_index > 0:
vertical_change = 0
horizontal_change = -1
elif event.key == pygame.K_RIGHT and tractor_horizontal_index < HORIZONTAL_TILES_NUMBER - 1:
horizontal_change = 1
vertical_change = 0
elif event.key == pygame.K_UP and tractor_vertical_index > 0:
vertical_change = -1
horizontal_change = 0
elif event.key == pygame.K_DOWN and tractor_vertical_index < VERTICAL_TILES_NUMBER - 1:
vertical_change = 1
horizontal_change = 0
return horizontal_change, vertical_change
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