Fixes to placing packages

This commit is contained in:
tonywesoly 2022-04-25 17:58:51 +02:00
parent bcc40c37e1
commit fb6ebb1d7d
4 changed files with 5 additions and 11 deletions

View File

@ -2,7 +2,6 @@ from Empty import Empty
from Moving_truck import Moving_truck
from Package import Package
from Package_types import Package_types
from Placed_package import Placed_package
from Shelf import Shelf
import pygame
import random

View File

@ -1,6 +1,5 @@
from Empty import Empty
from Package import Package
from Placed_package import Placed_package
from Shelf import Shelf
@ -16,7 +15,7 @@ class Moving_truck:
field_to_move_to = self.enviroment_2d[truck_x+x][truck_y+y]
if isinstance(field_to_move_to, Empty):
self.swap_fields(truck_x, truck_y, truck_x+x, truck_y+y)
elif isinstance(field_to_move_to, Package) and not isinstance(field_to_move_to, Placed_package):
elif isinstance(field_to_move_to, Package) and not field_to_move_to.is_placed:
self.move_truck_with_package(x, y)
def move_truck_with_package(self, x, y):
@ -38,8 +37,10 @@ class Moving_truck:
truck_x = self.truck.x
truck_y = self.truck.y
package = self.enviroment_2d[truck_x+x][truck_y+y]
# self.enviroment_2d[truck_x+x][truck_y +
# y] = Placed_package(package)
self.enviroment_2d[truck_x+x][truck_y +
y] = Placed_package(package)
y].is_placed = True
self.move_without_swapping(
truck_x+x, truck_y+y, truck_x+(x*2), truck_y+(y*2))
self.move_without_swapping(truck_x, truck_y, truck_x+x, truck_y+y)

View File

@ -12,6 +12,7 @@ class Package(Field):
Field.__init__(self, window, x, y)
self.mark_image = self.get_marking_photo()
self.type = random.choice(list(Package_types))
self.is_placed = False
def get_marking_photo(self):
file_path_type = ["resources/package_markings/*.jpg"]

View File

@ -1,7 +0,0 @@
from Package import Package
class Placed_package(Package):
def __init__(self, package):
Package.__init__(self, package.window, package.x, package.y)
self.type = package.type