animations update

This commit is contained in:
secret_dude 2021-04-13 18:57:48 +02:00
parent 55171b73f9
commit b3da1c6654
3 changed files with 20 additions and 9 deletions

7
animations.py Normal file
View File

@ -0,0 +1,7 @@
from constants import ANIMATION_PART
def animationsOn():
ANIMATION_PART = 11
def animationsOff():
ANIMATION_PART = 1

12
main.py
View File

@ -6,6 +6,7 @@ import drawUI
from Tractor import Tractor from Tractor import Tractor
from TractorAction import action from TractorAction import action
from TractorLoad import TillageUnit from TractorLoad import TillageUnit
from animations import animationsOn, animationsOff
from constants import * from constants import *
from manualSteering import manualSteeringDriver from manualSteering import manualSteeringDriver
@ -39,11 +40,18 @@ while working:
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
working = False working = False
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
hitchCounter, loadCounter, animationSpeed = \ hitchCounter, loadCounter = \
manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter, animationSpeed) manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter)
field = board[tractor.horizontal_index][tractor.vertical_index] field = board[tractor.horizontal_index][tractor.vertical_index]
if tractor.autodrive:
animationsOn()
else:
animationsOff()
if autoAction: if autoAction:
tractor, tillageUnit, toolCounter = TractorAction.autoAction(tractor, tillageUnit, toolCounter) tractor, tillageUnit, toolCounter = TractorAction.autoAction(tractor, tillageUnit, toolCounter)
field.state = action(field, tractor) field.state = action(field, tractor)

View File

@ -3,7 +3,7 @@ from TractorAction import action
import pygame import pygame
def manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter, animationSpeed): def manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadCounter):
if event.key == pygame.K_SPACE: if event.key == pygame.K_SPACE:
field = board[tractor.horizontal_index][tractor.vertical_index] field = board[tractor.horizontal_index][tractor.vertical_index]
field.state = action(field, tractor) field.state = action(field, tractor)
@ -31,27 +31,23 @@ def manualSteeringDriver(event, board, tractor, hitchCounter, tillageUnit, loadC
elif loadCounter == 3: elif loadCounter == 3:
tillageUnit.load = "Fertilizer" tillageUnit.load = "Fertilizer"
if event.key == pygame.K_SPACE: if event.key == pygame.K_m:
tractor.drive() tractor.drive()
if event.key == pygame.K_r: if event.key == pygame.K_r:
if tractor.engineWorking: if tractor.engineWorking:
tractor.turnOffEngine() tractor.turnOffEngine()
animationSpeed = 1
else: else:
tractor.turnOnEngine() tractor.turnOnEngine()
animationSpeed = ANIMATION_PART
if event.key == pygame.K_t: if event.key == pygame.K_t:
if tractor.autodrive: if tractor.autodrive:
tractor.autodrive = False tractor.autodrive = False
animationSpeed = 1
else: else:
tractor.autodrive = True tractor.autodrive = True
animationSpeed = ANIMATION_PART
manualTurning(event, tractor) manualTurning(event, tractor)
return hitchCounter, loadCounter, animationSpeed return hitchCounter, loadCounter
def manualTurning(event, tractor): def manualTurning(event, tractor):