v. 1.20
This commit is contained in:
parent
f748251d10
commit
aa9e61f921
@ -49,7 +49,7 @@ class Tractor:
|
|||||||
self.__fuel_tank = fuel_tank
|
self.__fuel_tank = fuel_tank
|
||||||
|
|
||||||
def fill_tank(self):
|
def fill_tank(self):
|
||||||
self.__fuel_tank(100)
|
self.__fuel_tank = 100
|
||||||
|
|
||||||
def reduce_fuel(self):
|
def reduce_fuel(self):
|
||||||
if 0 < self.fuel_tank <= 100:
|
if 0 < self.fuel_tank <= 100:
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
#constants
|
#constants
|
||||||
|
|
||||||
# display size in pixels
|
# display size in pixels
|
||||||
from math import ceil
|
from math import ceil, floor
|
||||||
|
|
||||||
DISPLAY_SIZE_HORIZONTAL = 1600
|
DISPLAY_SIZE_HORIZONTAL = 1600
|
||||||
DISPLAY_SIZE_VERTICAL = 900
|
DISPLAY_SIZE_VERTICAL = 800
|
||||||
|
|
||||||
#TILE DIVIDER = TILE SIZE
|
#TILE DIVIDER = TILE SIZE
|
||||||
TILE_SIZE = 100
|
TILE_SIZE = 100
|
||||||
|
|
||||||
# number of tiles
|
# number of tiles
|
||||||
HORIZONTAL_TILES_NUMBER = ceil(DISPLAY_SIZE_HORIZONTAL/TILE_SIZE)
|
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
|
#TILE_SIZE
|
||||||
|
|
||||||
|
14
drawUI.py
14
drawUI.py
@ -3,13 +3,23 @@ from Main.images import *
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
def drawUI(board, display, tractor_horizontal_index, tractor_vertical_index, direction):
|
def drawUI(board, display, tractor, direction):
|
||||||
display.fill(WHITE)
|
display.fill(WHITE)
|
||||||
makeField(board, display)
|
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()
|
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):
|
def makeField(board, screen: pygame.Surface):
|
||||||
for i in range(int(HORIZONTAL_TILES_NUMBER)):
|
for i in range(int(HORIZONTAL_TILES_NUMBER)):
|
||||||
for j in range(int(VERTICAL_TILES_NUMBER)):
|
for j in range(int(VERTICAL_TILES_NUMBER)):
|
||||||
|
@ -13,8 +13,9 @@ def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor):
|
|||||||
return horizontal_change, vertical_change
|
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.type == pygame.KEYDOWN:
|
||||||
|
|
||||||
if event.key == pygame.K_LEFT and tractor_horizontal_index > 0:
|
if event.key == pygame.K_LEFT and tractor_horizontal_index > 0:
|
||||||
vertical_change = 0
|
vertical_change = 0
|
||||||
horizontal_change = -1
|
horizontal_change = -1
|
||||||
|
9
main.py
9
main.py
@ -1,5 +1,6 @@
|
|||||||
import pygame
|
import pygame
|
||||||
# wersja 1.05
|
# wersja 1.05
|
||||||
|
from pygame import sysfont
|
||||||
|
|
||||||
from Main import Board, driving, drawUI
|
from Main import Board, driving, drawUI
|
||||||
from Main.Tractor import Tractor
|
from Main.Tractor import Tractor
|
||||||
@ -35,7 +36,7 @@ while working:
|
|||||||
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)
|
||||||
#todo usunąć /10
|
|
||||||
tractor.horizontal_index += horizontal_change
|
tractor.horizontal_index += horizontal_change
|
||||||
tractor.vertical_index += vertical_change
|
tractor.vertical_index += vertical_change
|
||||||
|
|
||||||
@ -46,11 +47,9 @@ while working:
|
|||||||
|
|
||||||
if direction != "STOP":
|
if direction != "STOP":
|
||||||
lastDirection = direction
|
lastDirection = direction
|
||||||
drawUI.drawUI(board, display, tractor.horizontal_index, tractor.vertical_index,
|
drawUI.drawUI(board, display, tractor, direction)
|
||||||
direction)
|
|
||||||
else:
|
else:
|
||||||
drawUI.drawUI(board, display, tractor.horizontal_index, tractor.vertical_index,
|
drawUI.drawUI(board, display, tractor, lastDirection)
|
||||||
lastDirection)
|
|
||||||
|
|
||||||
clock.tick(FPS)
|
clock.tick(FPS)
|
||||||
tractor.reduce_fuel()
|
tractor.reduce_fuel()
|
||||||
|
Loading…
Reference in New Issue
Block a user