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

This commit is contained in:
Woj 2023-04-30 23:18:17 +02:00
parent 48c4833ec8
commit 916abd2125
5 changed files with 88 additions and 77 deletions

View File

@ -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))

65
main.py
View File

@ -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

8
packageList.py Normal file
View File

@ -0,0 +1,8 @@
class listOfPackages:
list = []
def add(self, item):
self.list.append(item)
def remove(self):
self.list.pop()

View File

@ -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

View File

@ -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")
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