mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-05-23 07:16:44 +02:00
added vsibility radius around agent
This commit is contained in:
parent
556e8923a3
commit
8c8a8594fc
@ -16,7 +16,6 @@ class Entity:
|
|||||||
class Renderer:
|
class Renderer:
|
||||||
BG_COLOR = (99, 110, 114)
|
BG_COLOR = (99, 110, 114)
|
||||||
WHITE = (200, 200, 200)
|
WHITE = (200, 200, 200)
|
||||||
PINK = (0.5, 255, 118, 117)
|
|
||||||
|
|
||||||
def __init__(self, grid_w=16, grid_h=16, cell_size=40, fps=4, grid_lines=True, view_radius=2):
|
def __init__(self, grid_w=16, grid_h=16, cell_size=40, fps=4, grid_lines=True, view_radius=2):
|
||||||
self.grid_h = grid_h
|
self.grid_h = grid_h
|
||||||
@ -76,7 +75,8 @@ class Renderer:
|
|||||||
if 'agent' in asset and self.view_radius > 0:
|
if 'agent' in asset and self.view_radius > 0:
|
||||||
visibility_rect = bp['dest'].inflate((self.view_radius*2)*self.cell_size, (self.view_radius*2)*self.cell_size)
|
visibility_rect = bp['dest'].inflate((self.view_radius*2)*self.cell_size, (self.view_radius*2)*self.cell_size)
|
||||||
shape_surf = pygame.Surface(visibility_rect.size, pygame.SRCALPHA)
|
shape_surf = pygame.Surface(visibility_rect.size, pygame.SRCALPHA)
|
||||||
pygame.draw.rect(shape_surf, self.PINK, shape_surf.get_rect())
|
pygame.draw.rect(shape_surf, self.WHITE, shape_surf.get_rect())
|
||||||
|
shape_surf.set_alpha(96)
|
||||||
self.screen.blit(shape_surf, visibility_rect)
|
self.screen.blit(shape_surf, visibility_rect)
|
||||||
self.screen.blit(**bp)
|
self.screen.blit(**bp)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
@ -37,7 +37,7 @@ class GettingDirty(BaseFactory):
|
|||||||
def render(self):
|
def render(self):
|
||||||
if not self.renderer: # lazy init
|
if not self.renderer: # lazy init
|
||||||
height, width = self.state.shape[1:]
|
height, width = self.state.shape[1:]
|
||||||
self.renderer = Renderer(width, height, view_radius=0)
|
self.renderer = Renderer(width, height, view_radius=2)
|
||||||
|
|
||||||
dirt = [Entity('dirt', [x, y], min(self.state[DIRT_INDEX, x, y], 1), 'scale')
|
dirt = [Entity('dirt', [x, y], min(self.state[DIRT_INDEX, x, y], 1), 'scale')
|
||||||
for x, y in np.argwhere(self.state[DIRT_INDEX] > h.IS_FREE_CELL)]
|
for x, y in np.argwhere(self.state[DIRT_INDEX] > h.IS_FREE_CELL)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user