59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
import pygame
|
|
import warehouse
|
|
import agent
|
|
import random
|
|
from attributes import PackSize
|
|
|
|
WINDOW_SIZE = (600, 600)
|
|
COLORS = {
|
|
'white': (255, 255, 255),
|
|
'black': (0, 0, 0),
|
|
'gray': (128, 128, 128),
|
|
'darkgray': (60,60,60),
|
|
'yellow': (225,225,0)
|
|
}
|
|
COLOR_OF_FIELD = {
|
|
'Floor': 'gray',
|
|
'Rack': 'white',
|
|
'Pack': 'yellow'
|
|
}
|
|
TILE_WIDTH = 30
|
|
TILE_HEIGHT = 30
|
|
CIRCLE_CENTER_X, CIRCLE_CENTER_Y = int(TILE_WIDTH/2), int(TILE_HEIGHT/2)
|
|
|
|
class MainGameFrame:
|
|
def __init__(self):
|
|
self.display = pygame.display.set_mode(WINDOW_SIZE)
|
|
self.warehouse_map = warehouse.Warehouse(20, 20)
|
|
starting_x, starting_y = random.randrange(40), random.randrange(40)
|
|
self.agent = agent.Agent(starting_x, starting_y, 20)
|
|
def run(self):
|
|
self.draw_floor()
|
|
self.draw_agent()
|
|
while True:
|
|
pygame.display.update()
|
|
|
|
def draw_floor(self):
|
|
for x in range(self.warehouse_map.width):
|
|
for y in range(self.warehouse_map.height):
|
|
self.draw_field(x,y)
|
|
|
|
def draw_field(self, x, y):
|
|
current_tile = self.warehouse_map.tiles[x][y]
|
|
color = COLOR_OF_FIELD.get(current_tile.category.name, 'white')
|
|
color = COLORS[color]
|
|
pygame.draw.rect(self.display, COLORS['black'],
|
|
(x * TILE_WIDTH, y * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT))
|
|
pygame.draw.rect(self.display, color,
|
|
((x * TILE_WIDTH) + 1, (y * TILE_HEIGHT) + 1, TILE_WIDTH - 1, TILE_HEIGHT - 1))
|
|
|
|
def draw_agent(self):
|
|
agent_position_x, agent_position_y = self.agent.x, self.agent.y
|
|
agent_screen_position = ((agent_position_x*TILE_WIDTH) + CIRCLE_CENTER_X, (agent_position_y*TILE_HEIGHT) + CIRCLE_CENTER_Y)
|
|
# import pdb
|
|
# pdb.set_trace()
|
|
pygame.draw.circle(self.display, COLORS['black'], agent_screen_position, self.agent.radius, int(self.agent.radius/2))
|
|
|
|
if __name__ == '__main__':
|
|
maingame = MainGameFrame()
|
|
maingame.run() |