forked from s452751/AI_PRO
100 lines
3.3 KiB
Python
100 lines
3.3 KiB
Python
import pygame
|
|
# wersja 1.05
|
|
from pygame import sysfont
|
|
|
|
from Main import Board, driving, drawUI
|
|
from Main.Tractor import Tractor
|
|
from Main.TractorAction import action
|
|
from Main.TractorLoad import TillageUnit
|
|
from Main.constants import *
|
|
|
|
pygame.init()
|
|
|
|
display = pygame.display.set_mode((DISPLAY_SIZE_HORIZONTAL, DISPLAY_SIZE_VERTICAL))
|
|
pygame.display.set_caption('Tractor')
|
|
|
|
working = True
|
|
cruiseControl = False
|
|
lastDirection = "RIGHT"
|
|
|
|
horizontal_change = 0
|
|
vertical_change = 0
|
|
|
|
hitchCounter = 0
|
|
loadCounter = 0
|
|
|
|
board = Board.generate()
|
|
|
|
tractor = Tractor(horizontal_index=0, vertical_index=0, hitch="nothing", header=False)
|
|
tillageUnit = TillageUnit("Nothing")
|
|
|
|
tractor.turnOnEngine()
|
|
|
|
clock = pygame.time.Clock()
|
|
|
|
while working:
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
working = False
|
|
if event.type == pygame.KEYDOWN:
|
|
if event.key == pygame.K_SPACE:
|
|
field = board[tractor.horizontal_index][tractor.vertical_index]
|
|
field.state = action(field, tractor, tillageUnit)
|
|
if event.key == pygame.K_q:
|
|
hitchCounter = (hitchCounter + 1) % 3
|
|
if hitchCounter == 0:
|
|
tractor.hitch = "Crop Trailer"
|
|
if hitchCounter == 1:
|
|
print(type(tillageUnit))
|
|
print(isinstance(tillageUnit, TillageUnit))
|
|
tractor.hitch = tillageUnit
|
|
if hitchCounter == 2:
|
|
tractor.hitch = "Nothing"
|
|
if event.key == pygame.K_w:
|
|
if tractor.header:
|
|
tractor.header = False
|
|
else:
|
|
tractor.header = True
|
|
if event.key == pygame.K_e:
|
|
loadCounter = (loadCounter+1)%4
|
|
if loadCounter == 0:
|
|
tillageUnit.load = "Nothing"
|
|
elif loadCounter == 1:
|
|
tillageUnit.load = "Seeds"
|
|
elif loadCounter == 2:
|
|
tillageUnit.load = "Water"
|
|
elif loadCounter == 3:
|
|
tillageUnit.load = "Fertilizer"
|
|
|
|
|
|
|
|
horizontal_change, vertical_change = driving.manualTurning(event, tractor.horizontal_index,
|
|
tractor.vertical_index, horizontal_change,
|
|
vertical_change)
|
|
|
|
tractor.horizontal_index += horizontal_change
|
|
tractor.vertical_index += vertical_change
|
|
|
|
horizontal_change, vertical_change = driving.cruiseControl(cruiseControl, horizontal_change, vertical_change,
|
|
tractor)
|
|
|
|
direction = driving.getDirection(horizontal_change, vertical_change)
|
|
|
|
field = board[tractor.horizontal_index][tractor.vertical_index]
|
|
|
|
if direction != "STOP":
|
|
lastDirection = direction
|
|
drawUI.drawUI(board, display, tractor, direction, tillageUnit, field)
|
|
else:
|
|
drawUI.drawUI(board, display, tractor, lastDirection, tillageUnit, field)
|
|
|
|
clock.tick(FPS)
|
|
tractor.reduce_fuel()
|
|
print(tractor.fuel_tank)
|
|
|
|
print(tractor.horizontal_index + horizontal_change, " ", tractor.vertical_index + vertical_change)
|
|
print(horizontal_change, " ", vertical_change)
|
|
|
|
pygame.quit()
|
|
quit()
|