from drawUI import * import pygame def cruiseControl(tractor, direction, cruiseControl): if cruiseControl == False or tractor.engineWorking == False: direction = "STOP" return direction def manualTurning(event, tractor): direction = "STOP" if event.type == pygame.KEYDOWN: 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" # tractor.drive(direction) return direction 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 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