Stworzenie spawnera paczek. Paczki się tworzą po odstawieniu
This commit is contained in:
parent
fa0191d02c
commit
0618b40afa
@ -2,6 +2,7 @@ from Empty import Empty
|
||||
from Moving_truck import Moving_truck
|
||||
from Package import Package
|
||||
from Package_types import Package_types
|
||||
from Packages_spawner import Packages_spawner
|
||||
from Shelf import Shelf
|
||||
import pygame
|
||||
import random
|
||||
@ -20,13 +21,15 @@ class Environment:
|
||||
self.initialize_eviroment_2d()
|
||||
self.add_shelfs_to_enviroment_2d()
|
||||
# TEST CREATE PACKAGE
|
||||
new_package = Package(self.window, 26, 7)
|
||||
self.enviroment_2d[26][7] = new_package
|
||||
self.package_spawner = Packages_spawner(window,self.enviroment_2d)
|
||||
self.package_spawner.spawn_package()
|
||||
# new_package = Package(self.window, 26, 7)
|
||||
# self.enviroment_2d[26][7] = new_package
|
||||
new_truck = Truck(window, 14, 7)
|
||||
self.enviroment_2d[14][7] = new_truck
|
||||
self.truck = new_truck
|
||||
self.moving_truck = Moving_truck(
|
||||
self.window, self.enviroment_2d, self.truck)
|
||||
self.window, self.enviroment_2d, self.truck, self.package_spawner)
|
||||
self.astar = Pathfinding(self.enviroment_2d)
|
||||
|
||||
def draw_all_elements(self):
|
||||
|
@ -4,10 +4,11 @@ from Shelf import Shelf
|
||||
|
||||
|
||||
class Moving_truck:
|
||||
def __init__(self, window, enviroment_2d, truck):
|
||||
def __init__(self, window, enviroment_2d, truck, package_spawner):
|
||||
self.enviroment_2d = enviroment_2d
|
||||
self.truck = truck
|
||||
self.window = window
|
||||
self.package_spawner = package_spawner
|
||||
|
||||
def move(self, x, y):
|
||||
truck_x = self.truck.x
|
||||
@ -39,6 +40,7 @@ class Moving_truck:
|
||||
self.enviroment_2d[truck_x+x][truck_y +
|
||||
y].is_placed = True
|
||||
self.truck.has_package = False
|
||||
self.package_spawner.spawn_package()
|
||||
|
||||
def swap_fields(self, x1, y1, x2, y2):
|
||||
self.enviroment_2d[x1][y1], self.enviroment_2d[x2][y2] = self.enviroment_2d[x2][y2], self.enviroment_2d[x1][y1]
|
||||
|
@ -9,8 +9,7 @@ import math
|
||||
|
||||
|
||||
class Package(Field):
|
||||
def __init__(self, window, x, y, type=random.choice(list(Package_types))
|
||||
):
|
||||
def __init__(self, window, x, y, type):
|
||||
Field.__init__(self, window, x, y)
|
||||
self.mark_image = self.get_marking_photo()
|
||||
self.type = type
|
||||
|
17
Packages_spawner.py
Normal file
17
Packages_spawner.py
Normal file
@ -0,0 +1,17 @@
|
||||
import random
|
||||
from Global_variables import Global_variables as G_var
|
||||
from Package import Package
|
||||
from Package_types import Package_types
|
||||
|
||||
|
||||
class Packages_spawner:
|
||||
def __init__(self, window,enviroment_2d):
|
||||
self.window = window
|
||||
self.enviroment_2d = enviroment_2d
|
||||
|
||||
def spawn_package(self):
|
||||
package_x = random.randrange(22,26)
|
||||
package_y = random.randrange(1,13)
|
||||
package_type = random.choice(list(Package_types))
|
||||
new_package = Package(self.window,package_x,package_y,package_type)
|
||||
self.enviroment_2d[package_x][package_y] = new_package
|
Loading…
Reference in New Issue
Block a user