2023-05-06 13:53:01 +02:00
|
|
|
import ekran
|
2023-05-06 14:54:04 +02:00
|
|
|
import pygame,math
|
|
|
|
from packageList import listOfPackages
|
2023-03-27 12:10:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Wozek():
|
|
|
|
def __init__(self):
|
2023-05-06 13:53:01 +02:00
|
|
|
self.obecnyStan = None
|
2023-05-06 14:54:04 +02:00
|
|
|
# self.x = 55
|
|
|
|
# self.y = 55
|
2023-03-27 12:10:08 +02:00
|
|
|
self.x_change = 0
|
|
|
|
self.y_change = 0
|
|
|
|
self.height = 64
|
|
|
|
self.width = 64
|
|
|
|
self.image = pygame.image.load("images/pusty_wozek.png")
|
|
|
|
# Credit: Forklift icons created by Smashicons - Flaticon
|
|
|
|
# https://www.flaticon.com/free-icons/forklift
|
2023-04-20 20:54:58 +02:00
|
|
|
self.__zainicjuj_stan_poczatkowy()
|
2023-03-27 12:10:08 +02:00
|
|
|
|
|
|
|
def draw(self):
|
2023-05-06 13:53:01 +02:00
|
|
|
ekran.screen.blit(self.image, (self.obecnyStan.x, self.obecnyStan.y))
|
2023-03-27 12:10:08 +02:00
|
|
|
|
2023-05-06 14:54:04 +02:00
|
|
|
#storage = ["none"] * 10
|
2023-03-27 12:10:08 +02:00
|
|
|
storage = []
|
|
|
|
max_size = 10
|
2023-05-06 14:54:04 +02:00
|
|
|
ln = len(storage)
|
2023-03-27 12:10:08 +02:00
|
|
|
|
2023-05-06 14:54:04 +02:00
|
|
|
def add_element(self, element):
|
|
|
|
if self.ln < self.max_size:
|
|
|
|
self.storage.append(element)
|
|
|
|
self.ln=self.ln+1
|
2023-03-27 12:10:08 +02:00
|
|
|
else:
|
|
|
|
print("I'm full!")
|
2023-05-06 14:54:04 +02:00
|
|
|
def remove_element(self):
|
|
|
|
if self.ln > 0:
|
|
|
|
element = self.storage.pop()
|
|
|
|
self.ln=self.ln-1
|
|
|
|
return element
|
2023-03-27 12:10:08 +02:00
|
|
|
else:
|
|
|
|
print("I'm empty!")
|
|
|
|
|
2023-05-06 14:54:04 +02:00
|
|
|
def dynamic_wozek_picture(self):
|
|
|
|
if self.ln == 0:
|
|
|
|
self.image = pygame.image.load("images/pusty_wozek.png")
|
|
|
|
elif ((self.ln > 0) and (self.ln < 4)):
|
|
|
|
self.image = pygame.image.load("images/pelny_wozek_1_crate.png")
|
|
|
|
elif ((self.ln > 3) and (self.ln < 10)):
|
|
|
|
self.image = pygame.image.load("images/pelny_wozek_2_crates.png")
|
|
|
|
elif (self.ln == 10):
|
|
|
|
self.image = pygame.image.load("images/pelny_wozek_full_3_crates.png")
|
|
|
|
|
|
|
|
|
|
|
|
def load_package(self):
|
|
|
|
for package in listOfPackages.list:
|
|
|
|
dist = math.sqrt((self.obecnyStan.x - package.x)**2 + (self.obecnyStan.y - package.y)**2)
|
|
|
|
if dist <= 50:
|
|
|
|
self.add_element(package)
|
|
|
|
listOfPackages.list.pop()
|
|
|
|
def drop_package(self):
|
|
|
|
package = self.remove_element()
|
|
|
|
if package is not None:
|
|
|
|
listOfPackages.list.append(package)
|
|
|
|
package.x = self.obecnyStan.x+50
|
|
|
|
package.y = self.obecnyStan.y
|
2023-04-20 20:54:58 +02:00
|
|
|
|
|
|
|
def __zainicjuj_stan_poczatkowy(self):
|
|
|
|
from wyszukiwanie import Stan
|
2023-05-06 13:53:01 +02:00
|
|
|
self.obecnyStan = Stan(70, 70, 1)
|
2023-04-20 20:54:58 +02:00
|
|
|
|
2023-05-06 13:53:01 +02:00
|
|
|
def przemiesc_wozek_po_sciezce(self, sciezka):
|
|
|
|
kierunek_poprzedni = self.obecnyStan.kierunek
|
|
|
|
for wezel in sciezka:
|
|
|
|
self.obecnyStan = wezel.stan
|
|
|
|
kierunek_obecny = self.obecnyStan.kierunek
|
|
|
|
self.ustaw_wozek_w_kierunku(kierunek_obecny, kierunek_poprzedni)
|
|
|
|
kierunek_poprzedni = kierunek_obecny
|
|
|
|
ekran.odswiez_ekran(self)
|
|
|
|
pygame.time.wait(500)
|
|
|
|
|
|
|
|
def ustaw_wozek_w_kierunku(self, kierunek_obecny, kierunek_poprzedni):
|
2023-05-06 14:54:04 +02:00
|
|
|
if kierunek_poprzedni < kierunek_obecny:
|
|
|
|
# obrot w lewo
|
|
|
|
if kierunek_poprzedni == 0 and kierunek_obecny == 3:
|
|
|
|
self.image = pygame.transform.rotate(self.image, 90)
|
|
|
|
# obrot w prawo
|
|
|
|
else:
|
|
|
|
self.image = pygame.transform.rotate(self.image, -90)
|
|
|
|
elif kierunek_poprzedni > kierunek_obecny:
|
|
|
|
# obrot w prawo
|
|
|
|
if kierunek_poprzedni == 3 and kierunek_obecny == 0:
|
|
|
|
self.image = pygame.transform.rotate(self.image, -90)
|
|
|
|
# obrot w lewo
|
|
|
|
else:
|
|
|
|
self.image = pygame.transform.rotate(self.image, 90)
|
2023-04-20 20:54:58 +02:00
|
|
|
|