From e2924ae3c612b0d6d18215cddb72203e436236a2 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 4 Apr 2022 20:08:45 +0200 Subject: [PATCH] cleanup2 --- Environment.py | 52 ++++++++++++++++++++++++++------------------------ Grid.py | 15 ++++++--------- Shelf.py | 5 +++-- Truck.py | 1 + 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/Environment.py b/Environment.py index ed981ad..11faee9 100644 --- a/Environment.py +++ b/Environment.py @@ -1,45 +1,47 @@ import numpy as np from Shelf import Shelf +import pygame from Grid import Grid WINDOW_X = 1400 WINDOW_Y = 750 RECT_SIZE = 50 +RECT_COLOR = (70, 77, 87) 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 + # draws grid&shelves def draw_itself(self): - self.window.fill((70, 77, 87)) - self.draw_shelves() + self.compute_coordinates_of_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 + matrix = self.create_data_world() + for idx, value in np.ndenumerate(matrix): + x = RECT_SIZE*idx[1] + y = RECT_SIZE*idx[0] + if value == 0: + pygame.draw.rect(self.window, RECT_COLOR, (x, y, RECT_SIZE, RECT_SIZE)) + for idx, value in np.ndenumerate(matrix): + x = RECT_SIZE*idx[1] + y = RECT_SIZE*idx[0] + if value == 1: + shelf = Shelf(self.window, x,y) + shelf.draw() + + def create_data_world(self): + matrix = np.zeros((16, 28)) + shelf_y = 0 + shelf_y1 = 9 + + for x in range(2, 22, 3): + matrix[shelf_y][x] = 1 + matrix[shelf_y1][x] = 1 + print(matrix) + return matrix - # 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 index d211b71..d75a180 100644 --- a/Grid.py +++ b/Grid.py @@ -2,6 +2,7 @@ import pygame WINDOW_X = 1400 WINDOW_Y = 750 RECT_SIZE = 50 +RECT_COLOR = (70, 77, 87) class Grid: @@ -10,13 +11,9 @@ class Grid: # 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 + + for x in range(RECT_SIZE, WINDOW_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 + + for y in range(RECT_SIZE, WINDOW_Y, RECT_SIZE): + pygame.draw.line(self.window, (255, 255, 255), (0, y), (WINDOW_X, y)) diff --git a/Shelf.py b/Shelf.py index 68a94de..8d22503 100644 --- a/Shelf.py +++ b/Shelf.py @@ -1,11 +1,11 @@ import pygame RECT_SIZE = 50 +SHELF_COLOR = (143, 68, 33) 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 @@ -13,4 +13,5 @@ class Shelf: 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 + pygame.draw.rect(self.window, SHELF_COLOR, self.block) + # pygame.draw.line(self.window, (255, 255, 255), (self.x, self.y), (self.x, self.y + self.length)) diff --git a/Truck.py b/Truck.py index 532f726..a3ce7d2 100644 --- a/Truck.py +++ b/Truck.py @@ -14,6 +14,7 @@ class Truck: self.has_package = False self.environment = Environment(window) self.package = Package(self.window) + # self.speed # drawing the truck def draw(self):