139 lines
5.0 KiB
Python
139 lines
5.0 KiB
Python
import ekran
|
|
import pygame,math
|
|
# from packageList import listOfPackages
|
|
from ekran import lista_paczek
|
|
|
|
listOfPackages = lista_paczek
|
|
|
|
class Wozek(pygame.sprite.Sprite):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.obecnyStan = None
|
|
# self.x = 55
|
|
# self.y = 55
|
|
self.x_change = 0
|
|
self.y_change = 0
|
|
self.height = 64
|
|
self.width = 64
|
|
self.image = pygame.image.load("images/pusty_wozek.png")
|
|
self.rect = self.image.get_rect()
|
|
# Credit: Forklift icons created by Smashicons - Flaticon
|
|
# https://www.flaticon.com/free-icons/forklift
|
|
self.__zainicjuj_stan_poczatkowy()
|
|
|
|
def draw(self):
|
|
ekran.screen.blit(self.image, (self.obecnyStan.x, self.obecnyStan.y))
|
|
# self.update_position(self.obecnyStan.x, self.obecnyStan.y)
|
|
|
|
#storage = ["none"] * 10
|
|
storage = []
|
|
max_size = 10
|
|
ln = len(storage)
|
|
|
|
def add_element(self, element):
|
|
if self.ln < self.max_size:
|
|
self.storage.append(element)
|
|
self.ln=self.ln+1
|
|
else:
|
|
print("I'm full!")
|
|
def remove_element(self):
|
|
if self.ln > 0:
|
|
element = self.storage.pop()
|
|
self.ln=self.ln-1
|
|
return element
|
|
else:
|
|
print("I'm empty!")
|
|
|
|
def update_position(self, x, y):
|
|
self.obecnyStan.x = x
|
|
self.obecnyStan.y = y
|
|
self.rect.topleft = (x, y)
|
|
|
|
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")
|
|
|
|
self.rect = self.image.get_rect()
|
|
|
|
|
|
def load_package(self):
|
|
#for package in listOfPackages.list:
|
|
# for package in listOfPackages:
|
|
# 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()
|
|
# listOfPackages.pop()
|
|
package = listOfPackages.pop()
|
|
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 load_packages_collision(self):
|
|
pass
|
|
# packages_collision = pygame.sprite.spritecollide(self, listOfPackages.package_group, False)
|
|
# if packages_collision:
|
|
# for package in packages_collision:
|
|
# self.add_element(package)
|
|
# listOfPackages.list.remove(package) # collision doesn't work, collision always happens
|
|
|
|
def drop_package(self):
|
|
package = self.remove_element()
|
|
if package is not None:
|
|
package.x = self.obecnyStan.x
|
|
package.y = self.obecnyStan.y
|
|
# listOfPackages.list.append(package)
|
|
listOfPackages.append(package)
|
|
|
|
def __zainicjuj_stan_poczatkowy(self):
|
|
from wyszukiwanie import Stan
|
|
self.obecnyStan = Stan(0, 0, 1)
|
|
|
|
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):
|
|
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)
|
|
|
|
def picks_up_package(self):
|
|
paczka_pop = ekran.lista_paczek.pop()
|
|
ekran.lista_paczek_na_regalach.append(paczka_pop)
|
|
paczka_pop.is_in_move = True
|
|
self.storage.append(paczka_pop)
|
|
self.ln = self.ln + 1
|
|
|
|
def drops_package(self, paczka, reg, predictions):
|
|
paczka.update_position(reg.numerWiersza*70, reg.numerKolumny*70)
|
|
paczka.is_in_move = False
|
|
self.storage.pop()
|
|
self.ln = self.ln - 1
|
|
reg.put_package_on_the_regal(paczka, predictions)
|
|
|