From 916abd2125e373f4cf14596cfa9b34b42441455e Mon Sep 17 00:00:00 2001 From: Woj Date: Sun, 30 Apr 2023 23:18:17 +0200 Subject: [PATCH] wozek can pick-up and drop load, visable packages in the warehouse, list of staged packages, fixed code in most classes so that it works --- etykieta.py | 10 ++------ main.py | 65 ++++++++++++++++++-------------------------------- packageList.py | 8 +++++++ paczka.py | 25 +++++++++++++++---- wozek.py | 57 ++++++++++++++++++++++++++----------------- 5 files changed, 88 insertions(+), 77 deletions(-) create mode 100644 packageList.py diff --git a/etykieta.py b/etykieta.py index 94f64d2..bec7199 100644 --- a/etykieta.py +++ b/etykieta.py @@ -1,16 +1,10 @@ -#from main import pygame import secrets, string class Etykieta: - def __init__(self, id, nadawca, adres, imie, nazwisko, telefon): + def __init__(self, nadawca, adres, imie, nazwisko, telefon): self.nadawca = nadawca self.adres = adres self.imie = imie self.nazwisko = nazwisko self.telefon = telefon - self.id = ''.join(secrets.choice(string.ascii_uppercase + string.digits) for _ in range(9)) - - - - - + self.id = ''.join(secrets.choice(string.ascii_uppercase + string.digits) for _ in range(9)) \ No newline at end of file diff --git a/main.py b/main.py index 6296b94..eecb1eb 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,9 @@ import sys import pygame import regal -import paczka -#from wozek import Wozek +from paczka import Paczka +from wozek import Wozek +from packageList import listOfPackages pygame.init() screen = pygame.display.set_mode((980, 980)) @@ -12,50 +13,17 @@ pygame.display.set_caption("Inteligentny wozek") icon = pygame.image.load('images/icon.png') pygame.display.set_icon(icon) -class Wozek(): - def __init__(self): - 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 +def draw(self): + screen.blit(self.image, (self.x, self.y)) - def draw(self): - screen.blit(self.image, (self.x, self.y)) - - #storage = ["none"] * 10 - storage = [] - max_size = 10 - - def add_element(element, storage, max_size): - if len(storage) < max_size: - storage.append(element) - else: - print("I'm full!") - 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): - wozek.image = pygame.image.load("images/pelny_wozek_full_3_crates.png") def main(): wozek = Wozek() + packageList = listOfPackages() + demo_paczka = Paczka('duzy', 10, any, False, any, any, any, any, any) + packageList.add(demo_paczka) + while True: for event in pygame.event.get(): if event.type == pygame.QUIT: @@ -78,6 +46,15 @@ def main(): wozek.y_change = 0 if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT: wozek.x_change = 0 + + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_SPACE: + if wozek.ln == 0: + wozek.load_package() + wozek.dynamic_wozek_picture() + else: + wozek.drop_package() + wozek.dynamic_wozek_picture() wozek.x += wozek.x_change wozek.y += wozek.y_change @@ -117,7 +94,11 @@ def main(): regal.Regal(15, 1, 9, 8) regal.Regal(16, 1, 9, 9) - wozek.draw() + draw(wozek) + if wozek.ln == 0: + for x in packageList.list: + draw(x) + #demo_paczka.narysuj(430,400,screen) pygame.display.flip() # updating frames diff --git a/packageList.py b/packageList.py new file mode 100644 index 0000000..f422911 --- /dev/null +++ b/packageList.py @@ -0,0 +1,8 @@ + +class listOfPackages: + list = [] + + def add(self, item): + self.list.append(item) + def remove(self): + self.list.pop() \ No newline at end of file diff --git a/paczka.py b/paczka.py index 28cd692..41b2260 100644 --- a/paczka.py +++ b/paczka.py @@ -6,14 +6,29 @@ class Paczka: def __init__(self, rozmiar, waga, kategoria, czy_krucha, nadawca, adres, imie, nazwisko, telefon): self.rozmiar = rozmiar + self.image = pygame.image.load("images/paczka.png") + if rozmiar == 'duzy': + self.image = pygame.transform.scale(self.image, (50, 50)) + self.szerokosc = 50 + self.wysokosc = 50 + elif rozmiar == 'sredni': + self.image = pygame.transform.scale(self.image, (35, 35)) + self.szerokosc = 35 + self.wysokosc = 35 + elif rozmiar == 'maly': + self.image = pygame.transform.scale(self.image, (20, 20)) + self.szerokosc = 20 + self.wysokosc = 20 + else: + self.image = pygame.transform.scale(self.image, (20, 20)) + self.szerokosc = 20 + self.wysokosc = 20 + self.rozmiar = 'undefined' self.waga = waga self.kategoria = kategoria self.czy_krucha = czy_krucha - self.x = 0 - self.y = 0 - self.szerokosc = 0 - self.wysokosc = 0 - self.image = pygame.image.load("images/paczka.png") + self.x = 430 + self.y = 400 self.label = Etykieta(nadawca, adres, imie, nazwisko, telefon) # zmienia rozmiar obrazka w zaleznosci od rozmiaru diff --git a/wozek.py b/wozek.py index cc083f8..86415f1 100644 --- a/wozek.py +++ b/wozek.py @@ -1,6 +1,5 @@ -from main import pygame, screen - -#screen nie dziaƂa +import pygame,math +from packageList import listOfPackages class Wozek(): def __init__(self): @@ -14,31 +13,45 @@ class Wozek(): # Credit: Forklift icons created by Smashicons - Flaticon # https://www.flaticon.com/free-icons/forklift - def draw(self): - screen.blit(self.image, (self.x, self.y)) #storage = ["none"] * 10 storage = [] max_size = 10 + ln = len(storage) - def add_element(element, storage, max_size): - if len(storage) < max_size: - storage.append(element) + 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(storage): - if len(storage) > 0: - place = storage.pop() - return place + 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 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): - wozek.image = pygame.image.load("images/pelny_wozek_full_3_crates.png") \ No newline at end of file + + 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.x - package.x)**2 + (self.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.x+50 + package.y = self.y \ No newline at end of file