46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
from Main.drawUI import *
|
|
import pygame
|
|
|
|
|
|
def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor):
|
|
if cruiseControl == False or tractor.engineWorking == False:
|
|
horizontal_change = 0
|
|
vertical_change = 0
|
|
if tractor.horizontal_index <= 0 or tractor.horizontal_index >= HORIZONTAL_TILES_NUMBER - 1:
|
|
horizontal_change = 0
|
|
if tractor.vertical_index <= 0 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, vertical_change):
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
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):
|
|
direction = "STOP"
|
|
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
|