forked from s452751/AI_PRO
28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
from Main.constants import *
|
|
import pygame
|
|
|
|
|
|
def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor_horizontal_index, tractor_vertical_index):
|
|
if not cruiseControl:
|
|
horizontal_change = 0
|
|
vertical_change = 0
|
|
if tractor_horizontal_index < 1 or tractor_horizontal_index >= HORIZONTAL_TILES_NUMBER - 1:
|
|
horizontal_change = 0
|
|
if tractor_vertical_index < 1 or tractor_vertical_index >= VERTICAL_TILES_NUMBER - 1:
|
|
vertical_change = 0
|
|
return horizontal_change, vertical_change
|
|
|
|
|
|
def manualTurning(event, tractor_horizontal_index, tractor_vertical_index, horizontal_change=0, vertical_change=0):
|
|
if event.type == pygame.KEYDOWN:
|
|
if event.key == pygame.K_LEFT and tractor_horizontal_index > 0:
|
|
horizontal_change = -1
|
|
elif event.key == pygame.K_RIGHT and tractor_horizontal_index < HORIZONTAL_TILES_NUMBER - 1:
|
|
horizontal_change = 1
|
|
elif event.key == pygame.K_UP and tractor_vertical_index > 0:
|
|
vertical_change = -1
|
|
elif event.key == pygame.K_DOWN and tractor_vertical_index < VERTICAL_TILES_NUMBER - 1:
|
|
vertical_change = 1
|
|
|
|
return horizontal_change, vertical_change
|