2023-04-20 20:54:58 +02:00
|
|
|
import pygame
|
2023-05-06 13:53:01 +02:00
|
|
|
import ekran
|
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-03-27 12:10:08 +02:00
|
|
|
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")
|
|
|
|
# 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-04-20 20:54:58 +02:00
|
|
|
# storage = ["none"] * 10
|
2023-03-27 12:10:08 +02:00
|
|
|
storage = []
|
|
|
|
max_size = 10
|
|
|
|
|
|
|
|
def add_element(element, storage, max_size):
|
|
|
|
if len(storage) < max_size:
|
|
|
|
storage.append(element)
|
|
|
|
else:
|
|
|
|
print("I'm full!")
|
2023-04-20 20:54:58 +02:00
|
|
|
|
2023-03-27 12:10:08 +02:00
|
|
|
def remove_element(storage):
|
|
|
|
if len(storage) > 0:
|
|
|
|
place = storage.pop()
|
|
|
|
return place
|
|
|
|
else:
|
|
|
|
print("I'm empty!")
|
|
|
|
|
|
|
|
def dynamic_wozek_picture(wozek, storage):
|
|
|
|
if len(storage) == 0:
|
|
|
|
wozek.image = pygame.image.load("images/pusty_wozek.png")
|
|
|
|
elif ((len(storage) > 0) and (len(storage) < 4)):
|
|
|
|
wozek.image = pygame.image.load("images/pelny_wozek_1_crate.png")
|
|
|
|
elif ((len(storage) > 3) and (len(storage) < 10)):
|
|
|
|
wozek.image = pygame.image.load("images/pelny_wozek_2_crates.png")
|
|
|
|
elif (len(storage) == 10):
|
2023-04-20 20:54:58 +02:00
|
|
|
wozek.image = pygame.image.load("images/pelny_wozek_full_3_crates.png")
|
|
|
|
|
|
|
|
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):
|
|
|
|
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
|
|
|
|