diff --git a/Tractor.py b/Tractor.py index 48e053e..33d77f8 100644 --- a/Tractor.py +++ b/Tractor.py @@ -110,3 +110,4 @@ class Tractor: self.__horizontal_index += mRange elif self.__direction == "LEFT" and self.horizontal_index > 0: self.__horizontal_index += -mRange + self.reduce_fuel() diff --git a/TractorAction.py b/TractorAction.py index 8121559..2ee9f64 100644 --- a/TractorAction.py +++ b/TractorAction.py @@ -1,7 +1,7 @@ from TractorLoad import TillageUnit -def action(field, tractor): +def changeFieldState(field, tractor): if tractor.header and tractor.hitch == "Crop Trailer" and field.state == "toCut": return "toPlow" @@ -18,7 +18,7 @@ def action(field, tractor): return "toCut" -def autoAction(tractor, tillageUnit, toolCounter): +def autoToolsChange(tractor, tillageUnit, toolCounter): if tractor.horizontal_index == 0 and tractor.vertical_index == 0: toolCounter = (toolCounter + 1) % 5 tractor, tillageUnit = chooseToolset(tractor, tillageUnit, toolCounter) diff --git a/main.py b/main.py index 15c992c..1136815 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,6 @@ import Board import TractorAction import drawUI from Tractor import Tractor -from TractorAction import action from TractorLoad import TillageUnit from animations import animationsOn, animationsOff from constants import * @@ -20,7 +19,6 @@ autoAction = True animationSpeed = ANIMATION_PART - hitchCounter = 0 loadCounter = 0 toolCounter = - 1 @@ -45,23 +43,19 @@ while working: field = board[tractor.horizontal_index][tractor.vertical_index] - if tractor.autodrive: - animationsOn() + if tractor.autodrive and tractor.engineWorking: + animationSpeed = 11 else: - animationsOff() + animationSpeed = 1 + print(ANIMATION_PART) - - - if autoAction: - tractor, tillageUnit, toolCounter = TractorAction.autoAction(tractor, tillageUnit, toolCounter) - field.state = action(field, tractor) - if tractor.engineWorking: - tractor.reduce_fuel() + if tractor.autodrive: + tractor, tillageUnit, toolCounter = TractorAction.autoToolsChange(tractor, tillageUnit, toolCounter) + field.state = TractorAction.changeFieldState(field, tractor) drawUI.drawUI(board, display, tractor, tractor.direction, tillageUnit, field, animationSpeed) clock.tick(FPS) - pygame.quit() quit() diff --git a/manualSteering.py b/manualSteering.py index 740c27c..6dde77e 100644 --- a/manualSteering.py +++ b/manualSteering.py @@ -1,12 +1,12 @@ +from TractorAction import changeFieldState from constants import * -from TractorAction import action import pygame def manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter): if event.key == pygame.K_SPACE: field = board[tractor.horizontal_index][tractor.vertical_index] - field.state = action(field, tractor) + field.state = changeFieldState(field, tractor) if event.key == pygame.K_q: hitchCounter = (hitchCounter + 1) % 3 if hitchCounter == 0: