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 #9
@ -1,16 +1,10 @@
|
|||||||
#from main import pygame
|
|
||||||
import secrets, string
|
import secrets, string
|
||||||
|
|
||||||
class Etykieta:
|
class Etykieta:
|
||||||
def __init__(self, id, nadawca, adres, imie, nazwisko, telefon):
|
def __init__(self, nadawca, adres, imie, nazwisko, telefon):
|
||||||
self.nadawca = nadawca
|
self.nadawca = nadawca
|
||||||
self.adres = adres
|
self.adres = adres
|
||||||
self.imie = imie
|
self.imie = imie
|
||||||
self.nazwisko = nazwisko
|
self.nazwisko = nazwisko
|
||||||
self.telefon = telefon
|
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))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
61
main.py
61
main.py
@ -1,8 +1,9 @@
|
|||||||
import sys
|
import sys
|
||||||
import pygame
|
import pygame
|
||||||
import regal
|
import regal
|
||||||
import paczka
|
from paczka import Paczka
|
||||||
#from wozek import Wozek
|
from wozek import Wozek
|
||||||
|
from packageList import listOfPackages
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
screen = pygame.display.set_mode((980, 980))
|
screen = pygame.display.set_mode((980, 980))
|
||||||
@ -12,50 +13,17 @@ 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)
|
||||||
|
|
||||||
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):
|
def draw(self):
|
||||||
screen.blit(self.image, (self.x, self.y))
|
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():
|
def main():
|
||||||
wozek = Wozek()
|
wozek = Wozek()
|
||||||
|
packageList = listOfPackages()
|
||||||
|
demo_paczka = Paczka('duzy', 10, any, False, any, any, any, any, any)
|
||||||
|
packageList.add(demo_paczka)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
@ -79,6 +47,15 @@ def main():
|
|||||||
if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
|
if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
|
||||||
wozek.x_change = 0
|
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.x += wozek.x_change
|
||||||
wozek.y += wozek.y_change
|
wozek.y += wozek.y_change
|
||||||
|
|
||||||
@ -117,7 +94,11 @@ def main():
|
|||||||
regal.Regal(15, 1, 9, 8)
|
regal.Regal(15, 1, 9, 8)
|
||||||
regal.Regal(16, 1, 9, 9)
|
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
|
pygame.display.flip() # updating frames
|
||||||
|
|
||||||
|
8
packageList.py
Normal file
8
packageList.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
class listOfPackages:
|
||||||
|
list = []
|
||||||
|
|
||||||
|
def add(self, item):
|
||||||
|
self.list.append(item)
|
||||||
|
def remove(self):
|
||||||
|
self.list.pop()
|
25
paczka.py
25
paczka.py
@ -6,14 +6,29 @@ class Paczka:
|
|||||||
|
|
||||||
def __init__(self, rozmiar, waga, kategoria, czy_krucha, nadawca, adres, imie, nazwisko, telefon):
|
def __init__(self, rozmiar, waga, kategoria, czy_krucha, nadawca, adres, imie, nazwisko, telefon):
|
||||||
self.rozmiar = rozmiar
|
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.waga = waga
|
||||||
self.kategoria = kategoria
|
self.kategoria = kategoria
|
||||||
self.czy_krucha = czy_krucha
|
self.czy_krucha = czy_krucha
|
||||||
self.x = 0
|
self.x = 430
|
||||||
self.y = 0
|
self.y = 400
|
||||||
self.szerokosc = 0
|
|
||||||
self.wysokosc = 0
|
|
||||||
self.image = pygame.image.load("images/paczka.png")
|
|
||||||
self.label = Etykieta(nadawca, adres, imie, nazwisko, telefon)
|
self.label = Etykieta(nadawca, adres, imie, nazwisko, telefon)
|
||||||
|
|
||||||
# zmienia rozmiar obrazka w zaleznosci od rozmiaru
|
# zmienia rozmiar obrazka w zaleznosci od rozmiaru
|
||||||
|
55
wozek.py
55
wozek.py
@ -1,6 +1,5 @@
|
|||||||
from main import pygame, screen
|
import pygame,math
|
||||||
|
from packageList import listOfPackages
|
||||||
#screen nie działa
|
|
||||||
|
|
||||||
class Wozek():
|
class Wozek():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -14,31 +13,45 @@ class Wozek():
|
|||||||
# 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
|
||||||
|
|
||||||
def draw(self):
|
|
||||||
screen.blit(self.image, (self.x, self.y))
|
|
||||||
|
|
||||||
#storage = ["none"] * 10
|
#storage = ["none"] * 10
|
||||||
storage = []
|
storage = []
|
||||||
max_size = 10
|
max_size = 10
|
||||||
|
ln = len(storage)
|
||||||
|
|
||||||
def add_element(element, storage, max_size):
|
def add_element(self, element):
|
||||||
if len(storage) < max_size:
|
if self.ln < self.max_size:
|
||||||
storage.append(element)
|
self.storage.append(element)
|
||||||
|
self.ln=self.ln+1
|
||||||
else:
|
else:
|
||||||
print("I'm full!")
|
print("I'm full!")
|
||||||
def remove_element(storage):
|
def remove_element(self):
|
||||||
if len(storage) > 0:
|
if self.ln > 0:
|
||||||
place = storage.pop()
|
element = self.storage.pop()
|
||||||
return place
|
self.ln=self.ln-1
|
||||||
|
return element
|
||||||
else:
|
else:
|
||||||
print("I'm empty!")
|
print("I'm empty!")
|
||||||
|
|
||||||
def dynamic_wozek_picture(wozek, storage):
|
def dynamic_wozek_picture(self):
|
||||||
if len(storage) == 0:
|
if self.ln == 0:
|
||||||
wozek.image = pygame.image.load("images/pusty_wozek.png")
|
self.image = pygame.image.load("images/pusty_wozek.png")
|
||||||
elif ((len(storage) > 0) and (len(storage) < 4)):
|
elif ((self.ln > 0) and (self.ln < 4)):
|
||||||
wozek.image = pygame.image.load("images/pelny_wozek_1_crate.png")
|
self.image = pygame.image.load("images/pelny_wozek_1_crate.png")
|
||||||
elif ((len(storage) > 3) and (len(storage) < 10)):
|
elif ((self.ln > 3) and (self.ln < 10)):
|
||||||
wozek.image = pygame.image.load("images/pelny_wozek_2_crates.png")
|
self.image = pygame.image.load("images/pelny_wozek_2_crates.png")
|
||||||
elif (len(storage) == 10):
|
elif (self.ln == 10):
|
||||||
wozek.image = pygame.image.load("images/pelny_wozek_full_3_crates.png")
|
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
|
Loading…
Reference in New Issue
Block a user