AIprojekt-wozek/Environment.py
2022-04-04 20:08:45 +02:00

48 lines
1.3 KiB
Python

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)
# draws grid&shelves
def draw_itself(self):
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):
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