AI_PRO/main.py

60 lines
1.8 KiB
Python
Raw Normal View History

2021-03-17 00:57:06 +01:00
import pygame
2021-03-17 01:54:26 +01:00
# wersja 1.05
2021-03-17 00:57:06 +01:00
2021-03-28 22:42:36 +02:00
from Main import Board, driving, drawUI
2021-03-17 00:57:06 +01:00
from Main.constants import *
2021-03-28 22:42:36 +02:00
from Main.Field import Field
2021-03-17 00:57:06 +01:00
pygame.init()
# display size in pixels
display = pygame.display.set_mode((DISPLAY_SIZE_HORIZONTAL, DISPLAY_SIZE_VERTICAL))
# program name
2021-03-17 14:48:50 +01:00
pygame.display.set_caption('Tractor')
2021-03-17 00:57:06 +01:00
2021-03-17 01:02:20 +01:00
working = True
2021-03-28 22:42:36 +02:00
cruiseControl = True
2021-03-17 00:57:06 +01:00
horizontal_change = 0
vertical_change = 0
change_tile = False
board = Board.generate()
color = BLACK
clock = pygame.time.Clock()
2021-03-28 22:42:36 +02:00
tractor_horizontal_index = 0
tractor_vertical_index = 0
2021-03-17 01:02:20 +01:00
while working:
2021-03-17 00:57:06 +01:00
for event in pygame.event.get():
2021-03-28 22:42:36 +02:00
2021-03-17 00:57:06 +01:00
if event.type == pygame.QUIT:
2021-03-17 01:02:20 +01:00
working = False
2021-03-17 00:57:06 +01:00
if event.type == pygame.KEYDOWN:
2021-03-28 22:42:36 +02:00
if event.key == pygame.K_SPACE:
field = board[tractor_horizontal_index][tractor_vertical_index]
field.state = 4
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
2021-03-17 00:57:06 +01:00
display.fill(WHITE)
2021-03-28 22:42:36 +02:00
drawUI.makeField(board, display)
2021-03-17 00:57:06 +01:00
2021-03-28 22:42:36 +02:00
drawUI.drawTractor(board, display, tractor_horizontal_index, tractor_vertical_index)
2021-03-17 00:57:06 +01:00
pygame.display.update()
clock.tick(FPS)
2021-03-28 22:42:36 +02:00
horizontal_change, vertical_change = driving.cruiseControl(cruiseControl, horizontal_change, vertical_change,
tractor_horizontal_index, tractor_vertical_index)
print(tractor_horizontal_index + horizontal_change, " ", tractor_vertical_index + vertical_change)
print(horizontal_change, " ", vertical_change)
2021-03-17 00:57:06 +01:00
pygame.quit()
quit()