'regal can store packages and various fixes' Merge pull request (#16) from fixes_for_picking_up_and_screen_size into master

Reviewed-on: s474139/Inteligentny_Wozek#16
This commit is contained in:
Wojciech Medenecki 2023-05-28 00:08:40 +02:00
commit 113f694ccd
10 changed files with 62 additions and 21 deletions

View File

@ -7,8 +7,8 @@ import wozek
from packageList import * from packageList import *
from paczka import Paczka from paczka import Paczka
EKRAN_SZEROKOSC = 980 EKRAN_SZEROKOSC = 770
EKRAN_WYSOKOSC = 980 EKRAN_WYSOKOSC = 770
screen = pygame.display.set_mode((EKRAN_SZEROKOSC, EKRAN_WYSOKOSC)) screen = pygame.display.set_mode((EKRAN_SZEROKOSC, EKRAN_WYSOKOSC))
miejsce = pygame.image.load('images/miejsce_paczek.png') miejsce = pygame.image.load('images/miejsce_paczek.png')
miejsce = pygame.transform.scale(miejsce, (140, 140)) miejsce = pygame.transform.scale(miejsce, (140, 140))
@ -16,7 +16,7 @@ pygame.display.set_caption("Inteligentny wozek")
icon = pygame.image.load('images/icon.png') icon = pygame.image.load('images/icon.png')
pygame.display.set_icon(icon) pygame.display.set_icon(icon)
lista_paczek = packageList.zainicjuj_liste_paczek() lista_paczek = packageList.zainicjuj_liste_paczek(a_pix, b_pix)
def narysuj_regaly(): def narysuj_regaly():
regal.Regal(1, 1, x1, y1) regal.Regal(1, 1, x1, y1)
@ -78,4 +78,4 @@ def sprawdz_ktora_kolumna(y):
def narysuj_paczki(wozek): def narysuj_paczki(wozek):
if wozek.ln == 0: if wozek.ln == 0:
for paczka in lista_paczek.list: for paczka in lista_paczek.list:
paczka.narysuj(a_pix, b_pix, screen) paczka.narysuj(paczka.x, paczka.y, screen)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -60,12 +60,12 @@ def main():
if wozek.obecnyStan.x <= 0: if wozek.obecnyStan.x <= 0:
wozek.obecnyStan.x = 0 wozek.obecnyStan.x = 0
elif wozek.obecnyStan.x >= 916: elif wozek.obecnyStan.x >= ekran.EKRAN_SZEROKOSC-70:
wozek.obecnyStan.x = 916 wozek.obecnyStan.x = ekran.EKRAN_SZEROKOSC-70
if wozek.obecnyStan.y <= 0: if wozek.obecnyStan.y <= 0:
wozek.obecnyStan.y = 0 wozek.obecnyStan.y = 0
elif wozek.obecnyStan.x >= 916: elif wozek.obecnyStan.y >= ekran.EKRAN_WYSOKOSC-70:
wozek.obecnyStan.x = 916 wozek.obecnyStan.y = ekran.EKRAN_WYSOKOSC-70
ekran.odswiez_ekran(wozek) ekran.odswiez_ekran(wozek)

View File

@ -1,16 +1,23 @@
import pygame
from paczka import Paczka
class listOfPackages: class listOfPackages:
list = [] list = []
package_group = pygame.sprite.Group()
def add(self, item): def add(self, item):
self.list.append(item) self.list.append(item)
self.package_group.add(item)
def remove(self): def remove(self):
self.list.pop() last_package = self.list.pop()
self.package_group.remove(last_package)
def zainicjuj_liste_paczek(): def zainicjuj_liste_paczek(init_x, init_y):
from paczka import Paczka
packageList = listOfPackages() packageList = listOfPackages()
demo_paczka = Paczka('duzy', 10, any, False, True, False, any, any, any, any, any) demo_paczka = Paczka('duzy', 10, any, False, True, False, any, any, any, any, any)
demo_paczka.update_position(init_x, init_y)
packageList.add(demo_paczka) packageList.add(demo_paczka)
return packageList return packageList

View File

@ -2,11 +2,13 @@ from etykieta import Etykieta
import pygame import pygame
class Paczka: class Paczka(pygame.sprite.Sprite):
def __init__(self, rozmiar, waga, kategoria, priorytet, ksztalt, kruchosc, nadawca, adres, imie, nazwisko, telefon): def __init__(self, rozmiar, waga, kategoria, priorytet, ksztalt, kruchosc, nadawca, adres, imie, nazwisko, telefon):
super().__init__()
self.rozmiar = rozmiar self.rozmiar = rozmiar
self.image = pygame.image.load("images/paczka.png") self.image = pygame.image.load("images/paczka.png")
self.rect = self.image.get_rect()
if rozmiar == 'duzy': if rozmiar == 'duzy':
self.image = pygame.transform.scale(self.image, (50, 50)) self.image = pygame.transform.scale(self.image, (50, 50))
self.szerokosc = 50 self.szerokosc = 50
@ -62,3 +64,8 @@ class Paczka:
print("Zmien rozmiar paczki") print("Zmien rozmiar paczki")
print("Paczka moze miec rozmiar duzy, sredni lub maly") print("Paczka moze miec rozmiar duzy, sredni lub maly")
exit(0) exit(0)
def update_position(self, x, y):
self.x = x
self.y = y
self.rect.topleft = (x, y)

View File

@ -8,8 +8,8 @@ def obliczPixeleNaPodstawieKratek(wymiar): #Przeliczanie współrzędnych podany
i = i + 1 i = i + 1
return pixele return pixele
EKRAN_SZEROKOSC = 980 EKRAN_SZEROKOSC = 770
EKRAN_WYSOKOSC = 980 EKRAN_WYSOKOSC = 770
blockSize = 70 blockSize = 70
x1, y1, x2, y2, x3, y3, x4, y4 = [None] * 8 x1, y1, x2, y2, x3, y3, x4, y4 = [None] * 8

View File

@ -18,8 +18,9 @@ def obliczPixeleDlugosciRegalu(self): #Przeliczanie dlugości regału podanego
i = i + 1 i = i + 1
return dlugoscRegalu return dlugoscRegalu
class Regal: class Regal(pygame.sprite.Sprite):
def __init__(self, numerRegalu, dlugoscRegaluWKratkach, numerWiersza, numerKolumny): def __init__(self, numerRegalu, dlugoscRegaluWKratkach, numerWiersza, numerKolumny):
super().__init__()
from ekran import screen from ekran import screen
self.numerRegalu = numerRegalu self.numerRegalu = numerRegalu
self.wysokoscRegalu = 64 self.wysokoscRegalu = 64
@ -30,26 +31,33 @@ class Regal:
self.kolumna = obliczPixeleNaPodstawieKratek(numerKolumny) self.kolumna = obliczPixeleNaPodstawieKratek(numerKolumny)
self.dlugosc = obliczPixeleDlugosciRegalu(self) self.dlugosc = obliczPixeleDlugosciRegalu(self)
# from main import screen package_storage = []
# from ekran import screen shelfs = { # here packages are stored
"dolna": package_storage,
"gorna": package_storage
}
if(self.numerRegalu >= 0 and self.numerRegalu <= 4): if(self.numerRegalu >= 0 and self.numerRegalu <= 4):
reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu]) reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu])
reg = pygame.image.load("images/regal.png") reg = pygame.image.load("images/regal.png")
self.rect = reg.get_rect()
screen.blit(reg, (self.wiersz, self.kolumna)) screen.blit(reg, (self.wiersz, self.kolumna))
if(self.numerRegalu >= 5 and self.numerRegalu <= 8): if(self.numerRegalu >= 5 and self.numerRegalu <= 8):
reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu]) reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu])
reg = pygame.image.load("images/regal1.png") reg = pygame.image.load("images/regal1.png")
self.rect = reg.get_rect()
screen.blit(reg, (self.wiersz, self.kolumna)) screen.blit(reg, (self.wiersz, self.kolumna))
if(self.numerRegalu >= 9 and self.numerRegalu <= 12): if(self.numerRegalu >= 9 and self.numerRegalu <= 12):
reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu]) reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu])
reg = pygame.image.load("images/regal2.png") reg = pygame.image.load("images/regal2.png")
self.rect = reg.get_rect()
screen.blit(reg, (self.wiersz, self.kolumna)) screen.blit(reg, (self.wiersz, self.kolumna))
if(self.numerRegalu >= 13 and self.numerRegalu <= 16): if(self.numerRegalu >= 13 and self.numerRegalu <= 16):
reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu]) reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu])
reg = pygame.image.load("images/regal3.png") reg = pygame.image.load("images/regal3.png")
self.rect = reg.get_rect()
screen.blit(reg, (self.wiersz, self.kolumna)) screen.blit(reg, (self.wiersz, self.kolumna))

View File

@ -3,8 +3,9 @@ import pygame,math
from packageList import listOfPackages from packageList import listOfPackages
class Wozek(): class Wozek(pygame.sprite.Sprite):
def __init__(self): def __init__(self):
super().__init__()
self.obecnyStan = None self.obecnyStan = None
# self.x = 55 # self.x = 55
# self.y = 55 # self.y = 55
@ -13,12 +14,14 @@ class Wozek():
self.height = 64 self.height = 64
self.width = 64 self.width = 64
self.image = pygame.image.load("images/pusty_wozek.png") self.image = pygame.image.load("images/pusty_wozek.png")
self.rect = self.image.get_rect()
# Credit: Forklift icons created by Smashicons - Flaticon # Credit: Forklift icons created by Smashicons - Flaticon
# https://www.flaticon.com/free-icons/forklift # https://www.flaticon.com/free-icons/forklift
self.__zainicjuj_stan_poczatkowy() self.__zainicjuj_stan_poczatkowy()
def draw(self): def draw(self):
ekran.screen.blit(self.image, (self.obecnyStan.x, self.obecnyStan.y)) ekran.screen.blit(self.image, (self.obecnyStan.x, self.obecnyStan.y))
# self.update_position(self.obecnyStan.x, self.obecnyStan.y)
#storage = ["none"] * 10 #storage = ["none"] * 10
storage = [] storage = []
@ -39,6 +42,11 @@ class Wozek():
else: else:
print("I'm empty!") 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): def dynamic_wozek_picture(self):
if self.ln == 0: if self.ln == 0:
self.image = pygame.image.load("images/pusty_wozek.png") self.image = pygame.image.load("images/pusty_wozek.png")
@ -49,6 +57,8 @@ class Wozek():
elif (self.ln == 10): elif (self.ln == 10):
self.image = pygame.image.load("images/pelny_wozek_full_3_crates.png") self.image = pygame.image.load("images/pelny_wozek_full_3_crates.png")
self.rect = self.image.get_rect()
def load_package(self): def load_package(self):
for package in listOfPackages.list: for package in listOfPackages.list:
@ -56,12 +66,21 @@ class Wozek():
if dist <= 50: if dist <= 50:
self.add_element(package) self.add_element(package)
listOfPackages.list.pop() 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): def drop_package(self):
package = self.remove_element() package = self.remove_element()
if package is not None: if package is not None:
listOfPackages.list.append(package) package.x = self.obecnyStan.x
package.x = self.obecnyStan.x+50
package.y = self.obecnyStan.y package.y = self.obecnyStan.y
listOfPackages.list.append(package)
def __zainicjuj_stan_poczatkowy(self): def __zainicjuj_stan_poczatkowy(self):
from wyszukiwanie import Stan from wyszukiwanie import Stan