diff --git a/.idea/AI_wozek_widlowy.iml b/.idea/AI_wozek_widlowy.iml
index 74d515a..7eb1baf 100644
--- a/.idea/AI_wozek_widlowy.iml
+++ b/.idea/AI_wozek_widlowy.iml
@@ -4,7 +4,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 5eee172..d56657a 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Environment.py b/Environment.py
new file mode 100644
index 0000000..ed981ad
--- /dev/null
+++ b/Environment.py
@@ -0,0 +1,45 @@
+import numpy as np
+from Shelf import Shelf
+from Grid import Grid
+WINDOW_X = 1400
+WINDOW_Y = 750
+RECT_SIZE = 50
+
+
+class Environment:
+ def __init__(self, window):
+ self.window = window
+ self.grid = Grid(self.window)
+ self.list_of_coordinates = self.compute_coordinates_of_shelves()
+ self.shelves = self.create_shelves()
+
+ # fills surface with color, draws grid&shelves
+ def draw_itself(self):
+ self.window.fill((70, 77, 87))
+ self.draw_shelves()
+ self.grid.draw_grid()
+
+ # computes shelves coordinates according to window size, might change later
+ def compute_coordinates_of_shelves(self):
+ y = 0
+ y1 = WINDOW_Y - 6*RECT_SIZE
+ arr = []
+ for x in range(2*RECT_SIZE, WINDOW_X - 2*RECT_SIZE, 3*RECT_SIZE):
+ arr.append(x)
+ arr.append(y)
+ arr.append(x)
+ arr.append(y1)
+ list_of_coordinates = np.array(arr).reshape(int(len(arr)/2), 2)
+ return list_of_coordinates
+
+ # creating list of shelves
+ def create_shelves(self):
+ shelves = []
+ for row in self.list_of_coordinates:
+ shelf = Shelf(self.window, row[0], row[1])
+ shelves.append(shelf)
+ return shelves
+
+ def draw_shelves(self):
+ for shelf in self.shelves:
+ shelf.draw()
diff --git a/Grid.py b/Grid.py
new file mode 100644
index 0000000..d211b71
--- /dev/null
+++ b/Grid.py
@@ -0,0 +1,22 @@
+import pygame
+WINDOW_X = 1400
+WINDOW_Y = 750
+RECT_SIZE = 50
+
+
+class Grid:
+ def __init__(self, window):
+ self.window = window
+
+ # function to draw a grid, it draws a line every 50px(RECT_SIZE) for both x and y axis
+ def draw_grid(self):
+ num_of_columns = int(WINDOW_X / RECT_SIZE)
+ num_of_rows = int(WINDOW_Y / RECT_SIZE)
+ x = 0
+ y = 0
+ for i in range(num_of_columns):
+ x += RECT_SIZE
+ pygame.draw.line(self.window, (255, 255, 255), (x, 0), (x, WINDOW_Y))
+ for i in range(num_of_rows):
+ y += RECT_SIZE
+ pygame.draw.line(self.window, (255, 255, 255), (0, y), (WINDOW_X, y))
\ No newline at end of file
diff --git a/Package.py b/Package.py
new file mode 100644
index 0000000..5ddd535
--- /dev/null
+++ b/Package.py
@@ -0,0 +1,30 @@
+import numpy as np
+import glob2
+import pygame
+import random
+RECT_SIZE = 50
+
+
+class Package:
+ def __init__(self, window):
+ self.window = window
+ self.length = np.random.randint(1, 3) * RECT_SIZE -1
+ self.width = RECT_SIZE-1
+ self.color = list(np.random.choice(range(256), size=3))
+ self.x = 1251
+ self.y = 351
+ # self.mark = random.choice(['fragile', 'dont turn around', 'keep dry', 'glass'])
+ self.mark_image = self.get_marking_photo()
+ self.block = pygame.Rect(self.x, self.y, self.width, self.length)
+
+ def get_marking_photo(self):
+ file_path_type = ["resources/package_markings/*.jpg"]
+ images = glob2.glob(random.choice(file_path_type))
+ random_image = random.choice(images)
+ print(random_image)
+ return random_image
+
+ def draw(self):
+ pygame.draw.rect(self.window, self.color, self.block)
+ pygame.display.flip()
+
diff --git a/Program.py b/Program.py
new file mode 100644
index 0000000..4442039
--- /dev/null
+++ b/Program.py
@@ -0,0 +1,36 @@
+import pygame
+from pygame.locals import *
+from Truck import Truck
+
+
+WINDOW_X = 1400
+WINDOW_Y = 750
+RECT_SIZE = 50
+
+
+class Program:
+ def __init__(self):
+ pygame.init()
+ self.window = pygame.display.set_mode((WINDOW_X, WINDOW_Y)) # decides window's size
+ self.track = Truck(self.window)
+ self.track.draw()
+
+ def run(self):
+ running = True
+ while running:
+ for event in pygame.event.get(): # integrating with keyboard
+ if event.type == KEYDOWN:
+ if event.key == K_LEFT:
+ self.track.move_left()
+
+ if event.key == K_RIGHT:
+ self.track.move_right()
+
+ if event.key == K_UP:
+ self.track.move_up()
+
+ if event.key == K_DOWN:
+ self.track.move_down()
+
+ elif event.type == QUIT:
+ running = False
diff --git a/Shelf.py b/Shelf.py
new file mode 100644
index 0000000..68a94de
--- /dev/null
+++ b/Shelf.py
@@ -0,0 +1,16 @@
+import pygame
+RECT_SIZE = 50
+
+
+class Shelf:
+ def __init__(self, window, x, y):
+ self.window = window
+ self.color = (143, 68, 33)
+ self.width = RECT_SIZE
+ self.length = 6*RECT_SIZE
+ self.x = x
+ self.y = y
+ self.block = pygame.Rect(self.x, self.y, self.width, self.length)
+
+ def draw(self):
+ pygame.draw.rect(self.window, self.color, self.block)
\ No newline at end of file
diff --git a/Truck.py b/Truck.py
new file mode 100644
index 0000000..532f726
--- /dev/null
+++ b/Truck.py
@@ -0,0 +1,52 @@
+
+import pygame
+from Environment import Environment
+from Package import Package
+RECT_SIZE = 50
+
+
+class Truck:
+ def __init__(self, window, ):
+ self.window = window
+ self.image = pygame.image.load("resources/truck.jpeg").convert()
+ self.x = 701 # (x,y) - position of the truck
+ self.y = 401
+ self.has_package = False
+ self.environment = Environment(window)
+ self.package = Package(self.window)
+
+ # drawing the truck
+ def draw(self):
+ self.environment.draw_itself()
+ self.package.draw()
+ self.window.blit(self.image, (self.x, self.y))
+ pygame.display.flip()
+
+ # moving the truck
+ def move_right(self):
+ self.x += RECT_SIZE
+ self.draw()
+
+ def move_left(self):
+ self.x -= RECT_SIZE
+ self.draw()
+
+ def move_up(self):
+ self.y -= RECT_SIZE
+ self.draw()
+
+ def move_down(self):
+ self.y += RECT_SIZE
+ self.draw()
+
+ # def collision_with_shelves(self,x,y):
+ # for row in self.environment.compute_coordinates_of_shelves():
+ # if self.is_collision(x, y,row[0],row[1]):
+ # return True
+ # return False
+ #
+ # def is_collision(self, x1, y1, x2, y2):
+ # if x1 >= x2 and x1 <= x2 + RECT_SIZE:
+ # if y1 >= y2 and y1 <= y2 + 6*RECT_SIZE:
+ # return True
+ #
diff --git a/__pycache__/Environment.cpython-39.pyc b/__pycache__/Environment.cpython-39.pyc
new file mode 100644
index 0000000..c20c4b3
Binary files /dev/null and b/__pycache__/Environment.cpython-39.pyc differ
diff --git a/__pycache__/Grid.cpython-39.pyc b/__pycache__/Grid.cpython-39.pyc
new file mode 100644
index 0000000..5199792
Binary files /dev/null and b/__pycache__/Grid.cpython-39.pyc differ
diff --git a/__pycache__/Package.cpython-39.pyc b/__pycache__/Package.cpython-39.pyc
new file mode 100644
index 0000000..90413c1
Binary files /dev/null and b/__pycache__/Package.cpython-39.pyc differ
diff --git a/__pycache__/Program.cpython-39.pyc b/__pycache__/Program.cpython-39.pyc
new file mode 100644
index 0000000..d80d896
Binary files /dev/null and b/__pycache__/Program.cpython-39.pyc differ
diff --git a/__pycache__/Shelf.cpython-39.pyc b/__pycache__/Shelf.cpython-39.pyc
new file mode 100644
index 0000000..33185f7
Binary files /dev/null and b/__pycache__/Shelf.cpython-39.pyc differ
diff --git a/__pycache__/Truck.cpython-39.pyc b/__pycache__/Truck.cpython-39.pyc
new file mode 100644
index 0000000..7a6043c
Binary files /dev/null and b/__pycache__/Truck.cpython-39.pyc differ
diff --git a/resources/package_markings/1.jpg b/resources/package_markings/1.jpg
new file mode 100644
index 0000000..1ebf2da
Binary files /dev/null and b/resources/package_markings/1.jpg differ
diff --git a/resources/package_markings/Etykieta-Logistyczna-Uwaga-szklo.jpg b/resources/package_markings/Etykieta-Logistyczna-Uwaga-szklo.jpg
new file mode 100644
index 0000000..c655614
Binary files /dev/null and b/resources/package_markings/Etykieta-Logistyczna-Uwaga-szklo.jpg differ
diff --git a/resources/package_markings/c3e8808cd8efcfd26c23fbf88704676d.jpg b/resources/package_markings/c3e8808cd8efcfd26c23fbf88704676d.jpg
new file mode 100644
index 0000000..c142ae4
Binary files /dev/null and b/resources/package_markings/c3e8808cd8efcfd26c23fbf88704676d.jpg differ
diff --git a/resources/package_markings/image002.jpg b/resources/package_markings/image002.jpg
new file mode 100644
index 0000000..b957c7d
Binary files /dev/null and b/resources/package_markings/image002.jpg differ
diff --git a/resources/package_markings/indeks.jpg b/resources/package_markings/indeks.jpg
new file mode 100644
index 0000000..ebb20d7
Binary files /dev/null and b/resources/package_markings/indeks.jpg differ
diff --git a/resources/package_markings/ma001.jpg b/resources/package_markings/ma001.jpg
new file mode 100644
index 0000000..1da452c
Binary files /dev/null and b/resources/package_markings/ma001.jpg differ
diff --git a/resources/package_markings/ma002.jpg b/resources/package_markings/ma002.jpg
new file mode 100644
index 0000000..62fdada
Binary files /dev/null and b/resources/package_markings/ma002.jpg differ
diff --git a/resources/track.png b/resources/track.png
deleted file mode 100644
index 24b7c96..0000000
Binary files a/resources/track.png and /dev/null differ
diff --git a/resources/truck.jpg b/resources/truck.jpg
deleted file mode 100644
index 600d0b3..0000000
Binary files a/resources/truck.jpg and /dev/null differ
diff --git a/run.py b/run.py
index 9670d33..ae0dc7d 100644
--- a/run.py
+++ b/run.py
@@ -1,108 +1,4 @@
-import pygame
-from pygame.locals import *
-
-WINDOW_X = 1350
-WINDOW_Y = 850
-RECT_SIZE = 50
-
-
-class Truck:
- def __init__(self, window, ):
- self.window = window
- self.image = pygame.image.load("resources/truck.jpeg").convert()
- self.x = 701 # (x,y) - position of the truck
- self.y = 401
- self.grid = Grid(self.window)
- self.shelves = Shelves(window)
-
- # drawing the truck
- def draw(self):
- self.grid.redraw()
- self.shelves.draw_shelves()
- self.window.blit(self.image, (self.x, self.y))
- pygame.display.flip()
-
- # moving the truck
- def move_right(self):
- self.x += RECT_SIZE
- self.draw()
-
- def move_left(self):
- self.x -= RECT_SIZE
- self.draw()
-
- def move_up(self):
- self.y -= RECT_SIZE
- self.draw()
-
- def move_down(self):
- self.y += RECT_SIZE
- self.draw()
-
-
-class Grid:
- def __init__(self, window):
- self.window = window
-
- # function to draw a grid, it draws a line every 50px(RECT_SIZE) for both x and y axis
- def draw_grid(self):
- num_of_columns = int(WINDOW_X / RECT_SIZE)
- num_of_rows = int(WINDOW_Y / RECT_SIZE)
- x = 0
- y = 0
- for i in range(num_of_columns):
- x += RECT_SIZE
- pygame.draw.line(self.window, (255, 255, 255), (x, 0), (x, WINDOW_Y))
- for i in range(num_of_rows):
- y += RECT_SIZE
- pygame.draw.line(self.window, (255, 255, 255), (0, y), (WINDOW_X, y))
-
- # filling a background with color and grid
- def redraw(self):
- self.window.fill((70, 77, 87))
- self.draw_grid()
-
-
-class Shelves:
- def __init__(self, window):
- self.window = window
-
- def draw_shelves(self):
- width = RECT_SIZE - 1
- length = 6*RECT_SIZE
- for i in range(2*RECT_SIZE+1, WINDOW_X - 2*RECT_SIZE, 3*RECT_SIZE):
- pygame.draw.rect(self.window, (143, 68, 33), pygame.Rect(i, 0, width, length))
- pygame.draw.rect(self.window, (143, 68, 33), pygame.Rect(i, (WINDOW_Y - 6*RECT_SIZE)+1, width, length))
-
-
-class Program:
- def __init__(self):
- pygame.init()
- self.window = pygame.display.set_mode((WINDOW_X, WINDOW_Y)) # decides window's size
- self.track = Truck(self.window)
- self.track.draw()
-
- def run(self):
- running = True
-
- while running:
- for event in pygame.event.get(): # integrating with keyboard
- if event.type == KEYDOWN:
- if event.key == K_LEFT:
- self.track.move_left()
-
- if event.key == K_RIGHT:
- self.track.move_right()
-
- if event.key == K_UP:
- self.track.move_up()
-
- if event.key == K_DOWN:
- self.track.move_down()
-
- elif event.type == QUIT:
- running = False
-
+from Program import Program
if __name__ == "__main__":
program = Program()