This commit is contained in:
v7eZ3t 2021-03-29 04:17:31 +02:00
parent f748251d10
commit aa9e61f921
5 changed files with 22 additions and 12 deletions

View File

@ -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:

View File

@ -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

View File

@ -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)):

View File

@ -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

View File

@ -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()