wozek no longer "pops" when picking up a package

This commit is contained in:
Woj 2023-05-27 23:20:08 +02:00
parent 3167c74e4a
commit 82d1b7088e
4 changed files with 23 additions and 4 deletions

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

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