forked from s474139/Inteligentny_Wozek
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
import pygame,math
|
|
from packageList import listOfPackages
|
|
|
|
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
|
|
|
|
|
|
#storage = ["none"] * 10
|
|
storage = []
|
|
max_size = 10
|
|
ln = len(storage)
|
|
|
|
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(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(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 |