This commit is contained in:
v7eZ3t 2021-03-29 01:40:51 +02:00
parent f0c13cb6ea
commit 4165c16818
16 changed files with 0 additions and 299 deletions

View File

@ -1,13 +0,0 @@
import random
from Main.Field import Field
from Main.constants import *
def generate():
board = []
for i in range(0, int(HORIZONTAL_TILES_NUMBER)):
board.append([])
for j in range(0, int(VERTICAL_TILES_NUMBER)):
board[i].append(Field(int(i * TILE_SIZE), int(j * TILE_SIZE), random.randint(0, 3)))
return board

View File

@ -1,13 +0,0 @@
class Field:
def __init__(self, __horizontal, __vertical, __state):
self.horizontal = __horizontal
self.vertical = __vertical
self.__state = __state
@property
def state(self):
return self.__state
@state.setter
def state(self, state):
self.__state = state

View File

@ -1,62 +0,0 @@
from Main.TractorLoad import TractorTrailer
from Main.constants import HORIZONTAL_TILES_NUMBER, VERTICAL_TILES_NUMBER
class Tractor:
def __init__(self, __horizontal_index, __vertical_index, __hitch, __header, __fuel_tank):
self.__horizontal_index = __horizontal_index
self.__vertical_index = __vertical_index
self.__hitch = __hitch
self.__header = __header
self.__fuel_tank = __fuel_tank
@property
def horizontal_index(self):
return self.__horizontal_index
@horizontal_index.setter
def horizontal_index(self, horizontal_index):
if self.__horizontal_index < 1 or self.__horizontal_index >= HORIZONTAL_TILES_NUMBER - 1:
self.__horizontal_index = horizontal_index
@property
def vertical_index(self):
return self.__vertical_index
@vertical_index.setter
def vertical_index(self, vertical_index):
if self.__vertical_index < 1 or self.__vertical_index >= VERTICAL_TILES_NUMBER - 1:
self.__vertical_index = vertical_index
@property
def hitch(self):
return self.__hitch
@hitch.setter
def hitch(self, hitch):
if hitch is "Tillage unit" or "Crop Trailer" or TractorTrailer or "Nothing":
self.__hitch = hitch
@property
def fuel_tank(self):
return self.__fuel_tank
def __fuel_tank(self, fuel_tank):
if 0 < fuel_tank < 100:
self.__fuel_tank = fuel_tank
def fill_tank(self):
self.__fuel_tank(100)
def reduce_fuel(self):
if 0 < self.fuel_tank < 100:
self.__fuel_tank = self.__fuel_tank - 1
@property
def header(self):
return self.__header
@header.setter
def header(self, header):
if header is True or False:
self.__header = header

View File

@ -1,59 +0,0 @@
#constants
# display size in pixels
DISPLAY_SIZE_HORIZONTAL = 600
DISPLAY_SIZE_VERTICAL = 600
#TILE DIVIDER = TILE SIZE
TILE_SIZE = 30
# number of tiles
HORIZONTAL_TILES_NUMBER = DISPLAY_SIZE_HORIZONTAL/TILE_SIZE
VERTICAL_TILES_NUMBER = DISPLAY_SIZE_VERTICAL/TILE_SIZE
#TILE_SIZE
#colors
WHITE = (255, 255, 255) #SUPER UPRAWA
BLACK = (0, 0, 0)
RED = (255, 0, 0) #DO ZASIANIA
YELLOW = (255, 255, 0) #DO PODLANIA
GREEN = (0, 255, 0) #DO SCIECIA
#tractor const
TRACTOR_WIDTH = TILE_SIZE
TRACTOR_HEIGHT = TILE_SIZE
#FRAMES PER SECOND
FPS = 5

View File

@ -1,36 +0,0 @@
from Main.constants import *
from Main.images import *
import pygame
def drawUI(board, display, tractor_horizontal_index, tractor_vertical_index):
display.fill(WHITE)
makeField(board, display)
drawTractor(display, tractor_right, tractor_horizontal_index, tractor_vertical_index)
pygame.display.update()
def makeField(board, screen: pygame.Surface):
for i in range(int(HORIZONTAL_TILES_NUMBER)):
for j in range(int(VERTICAL_TILES_NUMBER)):
field = board[i][j]
pos_x = i * TILE_SIZE + TILE_SIZE // 2
pos_y = j * TILE_SIZE + TILE_SIZE // 2
if field.state == 0:
do_podlania_rect.center = (pos_x, pos_y)
screen.blit(do_podlania, do_podlania_rect)
elif field.state == 1:
do_zaorania_rect.center = (pos_x, pos_y)
screen.blit(do_zaorania, do_zaorania_rect)
elif field.state == 2:
do_zasiania_rect.center = (pos_x, pos_y)
screen.blit(do_zasiania, do_zasiania_rect)
elif field.state == 3:
do_zebrania_rect.center = (pos_x, pos_y)
screen.blit(do_zebrania, do_zebrania_rect)
def drawTractor(screen: pygame.Surface, tractor_image, tractor_horizontal_index, tractor_vertical_index):
screen.blit(tractor_image, (tractor_horizontal_index * TILE_SIZE,tractor_vertical_index * TILE_SIZE))

View File

@ -1,31 +0,0 @@
from Main.drawUI import *
import pygame
def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor_horizontal_index, tractor_vertical_index):
if not cruiseControl:
horizontal_change = 0
vertical_change = 0
if tractor_horizontal_index < 1 or tractor_horizontal_index >= HORIZONTAL_TILES_NUMBER - 1:
horizontal_change = 0
if tractor_vertical_index < 1 or tractor_vertical_index >= VERTICAL_TILES_NUMBER - 1:
vertical_change = 0
return horizontal_change, vertical_change
def manualTurning(event, tractor_horizontal_index, tractor_vertical_index, horizontal_change=0, vertical_change=0):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT and tractor_horizontal_index > 0:
vertical_change = 0
horizontal_change = -1
elif event.key == pygame.K_RIGHT and tractor_horizontal_index < HORIZONTAL_TILES_NUMBER - 1:
horizontal_change = 1
vertical_change = 0
elif event.key == pygame.K_UP and tractor_vertical_index > 0:
vertical_change = -1
horizontal_change = 0
elif event.key == pygame.K_DOWN and tractor_vertical_index < VERTICAL_TILES_NUMBER - 1:
vertical_change = 1
horizontal_change = 0
return horizontal_change, vertical_change

View File

@ -1,35 +0,0 @@
import pygame
from constants import *
tractor_up_image = pygame.image.load("resources/traktor_up.png")
tractor_up = pygame.transform.scale(tractor_up_image, (TILE_SIZE, TILE_SIZE))
tractor_right_image = pygame.image.load("resources/traktor_right.png")
tractor_right = pygame.transform.scale(tractor_right_image, (TILE_SIZE, TILE_SIZE))
tractor_down_image = pygame.image.load("resources/traktor_down.png")
tractor_down = pygame.transform.scale(tractor_down_image, (TILE_SIZE, TILE_SIZE))
tractor_left_image = pygame.image.load("resources/traktor_left.png")
tractor_left = pygame.transform.scale(tractor_left_image, (TILE_SIZE, TILE_SIZE))
do_podlania_image = pygame.image.load("resources/do_podlania.png")
do_podlania = pygame.transform.scale(do_podlania_image, (TILE_SIZE, TILE_SIZE))
do_zaorania_image = pygame.image.load("resources/do_zaorania.png")
do_zaorania = pygame.transform.scale(do_zaorania_image, (TILE_SIZE, TILE_SIZE))
do_zasiania_image = pygame.image.load("resources/do_zasiania.png")
do_zasiania = pygame.transform.scale(do_zasiania_image, (TILE_SIZE, TILE_SIZE))
do_zebrania_image = pygame.image.load("resources/do_zebrania.png")
do_zebrania = pygame.transform.scale(do_zebrania_image, (TILE_SIZE, TILE_SIZE))
tractor_up_rect = tractor_up.get_rect()
tractor_right_rect = tractor_right.get_rect()
tractor_down_rect = tractor_down.get_rect()
tractor_left_rect = tractor_left.get_rect()
do_podlania_rect = do_podlania.get_rect()
do_zaorania_rect = do_zaorania.get_rect()
do_zasiania_rect = do_zasiania.get_rect()
do_zebrania_rect = do_zebrania.get_rect()

View File

@ -1,50 +0,0 @@
import pygame
# wersja 1.05
from Main import Board, driving, drawUI
from Main.Tractor import Tractor
from Main.constants import *
pygame.init()
display = pygame.display.set_mode((DISPLAY_SIZE_HORIZONTAL, DISPLAY_SIZE_VERTICAL))
pygame.display.set_caption('Tractor')
working = True
cruiseControl = True
horizontal_change = 0
vertical_change = 0
board = Board.generate()
tractor = Tractor(horizontal_index=0, vertical_index=0, hitch="nothing", header=False, fuel_tank=100)
clock = pygame.time.Clock()
while working:
for event in pygame.event.get():
if event.type == pygame.QUIT:
working = False
if event.type == pygame.KEYDOWN:
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
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)
clock.tick(FPS)
print(tractor.horizontal_index + horizontal_change, " ", tractor.vertical_index + vertical_change)
print(horizontal_change, " ", vertical_change)
pygame.quit()
quit()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 KiB