diff --git a/Tractor.py b/Tractor.py index f305a31..02a9f29 100644 --- a/Tractor.py +++ b/Tractor.py @@ -49,7 +49,7 @@ class Tractor: self.__fuel_tank = fuel_tank def fill_tank(self): - self.__fuel_tank(100) + self.__fuel_tank = 100 def reduce_fuel(self): if 0 < self.fuel_tank <= 100: diff --git a/constants.py b/constants.py index 09a50e2..a0d4a4d 100644 --- a/constants.py +++ b/constants.py @@ -1,17 +1,17 @@ #constants # display size in pixels -from math import ceil +from math import ceil, floor DISPLAY_SIZE_HORIZONTAL = 1600 -DISPLAY_SIZE_VERTICAL = 900 +DISPLAY_SIZE_VERTICAL = 800 #TILE DIVIDER = TILE SIZE TILE_SIZE = 100 # number of tiles HORIZONTAL_TILES_NUMBER = ceil(DISPLAY_SIZE_HORIZONTAL/TILE_SIZE) -VERTICAL_TILES_NUMBER = ceil(DISPLAY_SIZE_VERTICAL/TILE_SIZE) +VERTICAL_TILES_NUMBER = floor((DISPLAY_SIZE_VERTICAL-200)/TILE_SIZE) #TILE_SIZE diff --git a/drawUI.py b/drawUI.py index 2551bd1..0d8e6ce 100644 --- a/drawUI.py +++ b/drawUI.py @@ -3,13 +3,23 @@ from Main.images import * import pygame -def drawUI(board, display, tractor_horizontal_index, tractor_vertical_index, direction): +def drawUI(board, display, tractor, direction): display.fill(WHITE) makeField(board, display) - drawTractor(display, tractor_horizontal_index, tractor_vertical_index, direction) + drawTractor(display, tractor.horizontal_index, tractor.vertical_index, direction) + drawInfo(display, tractor) + pygame.display.update() +def drawInfo(display, tractor): + myfont = pygame.font.SysFont('Comic Sans MS', 30) + text = f"Fuel: {tractor.fuel_tank} \t Hitches: {tractor.hitch} \t Header: {tractor.header} \t Engine working: {tractor.engineWorking}" + + textsurface = myfont.render(text, False, (0, 0, 0)) + display.blit(textsurface, (50, (DISPLAY_SIZE_VERTICAL - 200))) + + def makeField(board, screen: pygame.Surface): for i in range(int(HORIZONTAL_TILES_NUMBER)): for j in range(int(VERTICAL_TILES_NUMBER)): diff --git a/driving.py b/driving.py index 610c6f4..becf653 100644 --- a/driving.py +++ b/driving.py @@ -13,8 +13,9 @@ def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor): return horizontal_change, vertical_change -def manualTurning(event, tractor_horizontal_index, tractor_vertical_index, horizontal_change=0, vertical_change=0): +def manualTurning(event, tractor_horizontal_index, tractor_vertical_index, horizontal_change, vertical_change): if event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT and tractor_horizontal_index > 0: vertical_change = 0 horizontal_change = -1 diff --git a/main.py b/main.py index 461c682..d1aa75b 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ import pygame # wersja 1.05 +from pygame import sysfont from Main import Board, driving, drawUI from Main.Tractor import Tractor @@ -35,7 +36,7 @@ while working: horizontal_change, vertical_change = driving.manualTurning(event, tractor.horizontal_index, tractor.vertical_index, horizontal_change, vertical_change) - #todo usunąć /10 + tractor.horizontal_index += horizontal_change tractor.vertical_index += vertical_change @@ -46,11 +47,9 @@ while working: if direction != "STOP": lastDirection = direction - drawUI.drawUI(board, display, tractor.horizontal_index, tractor.vertical_index, - direction) + drawUI.drawUI(board, display, tractor, direction) else: - drawUI.drawUI(board, display, tractor.horizontal_index, tractor.vertical_index, - lastDirection) + drawUI.drawUI(board, display, tractor, lastDirection) clock.tick(FPS) tractor.reduce_fuel()