This commit is contained in:
Anna Śmigiel 2022-04-04 20:08:45 +02:00
parent 9f379f7893
commit e2924ae3c6
4 changed files with 37 additions and 36 deletions

View File

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

15
Grid.py
View File

@ -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))
for y in range(RECT_SIZE, WINDOW_Y, RECT_SIZE):
pygame.draw.line(self.window, (255, 255, 255), (0, y), (WINDOW_X, y))

View File

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

View File

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