This commit is contained in:
v7eZ3t 2021-03-28 23:18:29 +02:00
parent ba1f2d96b6
commit c981921fbd
2 changed files with 17 additions and 19 deletions

4
Tractor.py Normal file
View File

@ -0,0 +1,4 @@
class Tractor:
def __init__(self, horizontal_index, vertical_index):
self.horizontal_index = horizontal_index
self.vertical_index = vertical_index

32
main.py
View File

@ -2,14 +2,12 @@ import pygame
# wersja 1.05 # wersja 1.05
from Main import Board, driving, drawUI from Main import Board, driving, drawUI
from Main.Tractor import Tractor
from Main.constants import * from Main.constants import *
from Main.Field import Field
pygame.init() pygame.init()
# display size in pixels
display = pygame.display.set_mode((DISPLAY_SIZE_HORIZONTAL, DISPLAY_SIZE_VERTICAL)) display = pygame.display.set_mode((DISPLAY_SIZE_HORIZONTAL, DISPLAY_SIZE_VERTICAL))
# program name
pygame.display.set_caption('Tractor') pygame.display.set_caption('Tractor')
working = True working = True
@ -18,13 +16,11 @@ cruiseControl = True
horizontal_change = 0 horizontal_change = 0
vertical_change = 0 vertical_change = 0
change_tile = False
board = Board.generate() board = Board.generate()
color = BLACK
clock = pygame.time.Clock()
tractor_horizontal_index = 0 tractor = Tractor(horizontal_index=0, vertical_index=0)
tractor_vertical_index = 0
clock = pygame.time.Clock()
while working: while working:
for event in pygame.event.get(): for event in pygame.event.get():
@ -32,24 +28,22 @@ while working:
working = False working = False
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
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 = 4 field.state = 4
horizontal_change, vertical_change = driving.manualTurning(event, tractor_horizontal_index, horizontal_change, vertical_change = driving.manualTurning(event, tractor.horizontal_index,
tractor_vertical_index, horizontal_change, tractor.vertical_index, horizontal_change,
vertical_change) vertical_change)
tractor_horizontal_index += horizontal_change tractor.horizontal_index += horizontal_change
tractor_vertical_index += vertical_change tractor.vertical_index += vertical_change
horizontal_change, vertical_change = driving.cruiseControl(cruiseControl, horizontal_change, vertical_change,
tractor.horizontal_index, tractor.vertical_index)
drawUI.drawUI(board, display, tractor_horizontal_index, tractor_vertical_index) drawUI.drawUI(board, display, tractor.horizontal_index, tractor.vertical_index)
clock.tick(FPS) clock.tick(FPS)
horizontal_change, vertical_change = driving.cruiseControl(cruiseControl, horizontal_change, vertical_change, print(tractor.horizontal_index + horizontal_change, " ", tractor.vertical_index + vertical_change)
tractor_horizontal_index, tractor_vertical_index)
print(tractor_horizontal_index + horizontal_change, " ", tractor_vertical_index + vertical_change)
print(horizontal_change, " ", vertical_change) print(horizontal_change, " ", vertical_change)
pygame.quit() pygame.quit()