cleanup2
This commit is contained in:
parent
9f379f7893
commit
e2924ae3c6
@ -1,45 +1,47 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from Shelf import Shelf
|
from Shelf import Shelf
|
||||||
|
import pygame
|
||||||
from Grid import Grid
|
from Grid import Grid
|
||||||
WINDOW_X = 1400
|
WINDOW_X = 1400
|
||||||
WINDOW_Y = 750
|
WINDOW_Y = 750
|
||||||
RECT_SIZE = 50
|
RECT_SIZE = 50
|
||||||
|
RECT_COLOR = (70, 77, 87)
|
||||||
|
|
||||||
|
|
||||||
class Environment:
|
class Environment:
|
||||||
def __init__(self, window):
|
def __init__(self, window):
|
||||||
self.window = window
|
self.window = window
|
||||||
self.grid = Grid(self.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):
|
def draw_itself(self):
|
||||||
self.window.fill((70, 77, 87))
|
self.compute_coordinates_of_shelves()
|
||||||
self.draw_shelves()
|
|
||||||
self.grid.draw_grid()
|
self.grid.draw_grid()
|
||||||
|
|
||||||
# computes shelves coordinates according to window size, might change later
|
# computes shelves coordinates according to window size, might change later
|
||||||
def compute_coordinates_of_shelves(self):
|
def compute_coordinates_of_shelves(self):
|
||||||
y = 0
|
matrix = self.create_data_world()
|
||||||
y1 = WINDOW_Y - 6*RECT_SIZE
|
for idx, value in np.ndenumerate(matrix):
|
||||||
arr = []
|
x = RECT_SIZE*idx[1]
|
||||||
for x in range(2*RECT_SIZE, WINDOW_X - 2*RECT_SIZE, 3*RECT_SIZE):
|
y = RECT_SIZE*idx[0]
|
||||||
arr.append(x)
|
if value == 0:
|
||||||
arr.append(y)
|
pygame.draw.rect(self.window, RECT_COLOR, (x, y, RECT_SIZE, RECT_SIZE))
|
||||||
arr.append(x)
|
for idx, value in np.ndenumerate(matrix):
|
||||||
arr.append(y1)
|
x = RECT_SIZE*idx[1]
|
||||||
list_of_coordinates = np.array(arr).reshape(int(len(arr)/2), 2)
|
y = RECT_SIZE*idx[0]
|
||||||
return list_of_coordinates
|
if value == 1:
|
||||||
|
shelf = Shelf(self.window, x,y)
|
||||||
# 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()
|
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
|
||||||
|
|
||||||
|
|
||||||
|
13
Grid.py
13
Grid.py
@ -2,6 +2,7 @@ import pygame
|
|||||||
WINDOW_X = 1400
|
WINDOW_X = 1400
|
||||||
WINDOW_Y = 750
|
WINDOW_Y = 750
|
||||||
RECT_SIZE = 50
|
RECT_SIZE = 50
|
||||||
|
RECT_COLOR = (70, 77, 87)
|
||||||
|
|
||||||
|
|
||||||
class Grid:
|
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
|
# function to draw a grid, it draws a line every 50px(RECT_SIZE) for both x and y axis
|
||||||
def draw_grid(self):
|
def draw_grid(self):
|
||||||
num_of_columns = int(WINDOW_X / RECT_SIZE)
|
|
||||||
num_of_rows = int(WINDOW_Y / RECT_SIZE)
|
for x in range(RECT_SIZE, WINDOW_X, 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))
|
pygame.draw.line(self.window, (255, 255, 255), (x, 0), (x, WINDOW_Y))
|
||||||
for i in range(num_of_rows):
|
|
||||||
y += RECT_SIZE
|
for y in range(RECT_SIZE, WINDOW_Y, RECT_SIZE):
|
||||||
pygame.draw.line(self.window, (255, 255, 255), (0, y), (WINDOW_X, y))
|
pygame.draw.line(self.window, (255, 255, 255), (0, y), (WINDOW_X, y))
|
5
Shelf.py
5
Shelf.py
@ -1,11 +1,11 @@
|
|||||||
import pygame
|
import pygame
|
||||||
RECT_SIZE = 50
|
RECT_SIZE = 50
|
||||||
|
SHELF_COLOR = (143, 68, 33)
|
||||||
|
|
||||||
|
|
||||||
class Shelf:
|
class Shelf:
|
||||||
def __init__(self, window, x, y):
|
def __init__(self, window, x, y):
|
||||||
self.window = window
|
self.window = window
|
||||||
self.color = (143, 68, 33)
|
|
||||||
self.width = RECT_SIZE
|
self.width = RECT_SIZE
|
||||||
self.length = 6*RECT_SIZE
|
self.length = 6*RECT_SIZE
|
||||||
self.x = x
|
self.x = x
|
||||||
@ -13,4 +13,5 @@ class Shelf:
|
|||||||
self.block = pygame.Rect(self.x, self.y, self.width, self.length)
|
self.block = pygame.Rect(self.x, self.y, self.width, self.length)
|
||||||
|
|
||||||
def draw(self):
|
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))
|
||||||
|
1
Truck.py
1
Truck.py
@ -14,6 +14,7 @@ class Truck:
|
|||||||
self.has_package = False
|
self.has_package = False
|
||||||
self.environment = Environment(window)
|
self.environment = Environment(window)
|
||||||
self.package = Package(self.window)
|
self.package = Package(self.window)
|
||||||
|
# self.speed
|
||||||
|
|
||||||
# drawing the truck
|
# drawing the truck
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user