mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-05-23 15:26:43 +02:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
be82ac65e2
@ -10,6 +10,7 @@ class Entity:
|
|||||||
name: str
|
name: str
|
||||||
pos: np.array
|
pos: np.array
|
||||||
value: float = 1
|
value: float = 1
|
||||||
|
value_operation: str = 'none'
|
||||||
|
|
||||||
|
|
||||||
class Renderer:
|
class Renderer:
|
||||||
@ -29,7 +30,7 @@ class Renderer:
|
|||||||
self.screen = pygame.display.set_mode(self.screen_size)
|
self.screen = pygame.display.set_mode(self.screen_size)
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
assets = list((Path(__file__).parent / 'assets').glob('*.png'))
|
assets = list((Path(__file__).parent / 'assets').glob('*.png'))
|
||||||
self.assets = {path.stem: self.load_asset(str(path), 0.95) for path in assets}
|
self.assets = {path.stem: self.load_asset(str(path), 0.97) for path in assets}
|
||||||
self.fill_bg()
|
self.fill_bg()
|
||||||
|
|
||||||
def fill_bg(self):
|
def fill_bg(self):
|
||||||
@ -44,7 +45,13 @@ class Renderer:
|
|||||||
def blit_params(self, entity, name):
|
def blit_params(self, entity, name):
|
||||||
r, c = entity.pos
|
r, c = entity.pos
|
||||||
img = self.assets[name]
|
img = self.assets[name]
|
||||||
|
if entity.value_operation == 'opacity':
|
||||||
img.set_alpha(255*entity.value)
|
img.set_alpha(255*entity.value)
|
||||||
|
elif entity.value_operation == 'scale':
|
||||||
|
re = img.get_rect()
|
||||||
|
img = pygame.transform.smoothscale(
|
||||||
|
img, (int(entity.value*re.width), int(entity.value*re.height))
|
||||||
|
)
|
||||||
o = self.cell_size//2
|
o = self.cell_size//2
|
||||||
r_, c_ = r*self.cell_size + o, c*self.cell_size + o
|
r_, c_ = r*self.cell_size + o, c*self.cell_size + o
|
||||||
rect = img.get_rect()
|
rect = img.get_rect()
|
||||||
@ -54,7 +61,7 @@ class Renderer:
|
|||||||
def load_asset(self, path, factor=1.0):
|
def load_asset(self, path, factor=1.0):
|
||||||
s = int(factor*self.cell_size)
|
s = int(factor*self.cell_size)
|
||||||
wall_img = pygame.image.load(path).convert_alpha()
|
wall_img = pygame.image.load(path).convert_alpha()
|
||||||
wall_img = pygame.transform.scale(wall_img, (s, s))
|
wall_img = pygame.transform.smoothscale(wall_img, (s, s))
|
||||||
return wall_img
|
return wall_img
|
||||||
|
|
||||||
def render(self, pos_dict):
|
def render(self, pos_dict):
|
||||||
|
@ -40,7 +40,7 @@ class GettingDirty(BaseFactory):
|
|||||||
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=0)
|
||||||
|
|
||||||
dirt = [Entity('dirt', [x, y], self.state[DIRT_INDEX, x, y]) for x, y in np.argwhere(self.state[DIRT_INDEX] > h.IS_FREE_CELL)]
|
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)]
|
||||||
walls = [Entity('dirt', pos) for pos in np.argwhere(self.state[h.LEVEL_IDX] > h.IS_FREE_CELL)]
|
walls = [Entity('dirt', pos) for pos in np.argwhere(self.state[h.LEVEL_IDX] > h.IS_FREE_CELL)]
|
||||||
agents = [Entity('agent', pos) for pos in np.argwhere(self.state[h.AGENT_START_IDX] > h.IS_FREE_CELL)]
|
agents = [Entity('agent', pos) for pos in np.argwhere(self.state[h.AGENT_START_IDX] > h.IS_FREE_CELL)]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user