def on_mapbuilt(self, event): """ Build the bg from the map cells, and blit it. The pixel width and height of map cells comes from the window's dimensions and the map's visibility radius. Called only once at the beginning, when model.map has been built. """ worldmap = event.worldmap self.cellsprs = dict() # maps model.Cell to view.CellSprite # determine width and height of cell spr from map visibility r = worldmap.visibility_radius self.visib_rad = r diam = 2 * r + 1 self.visib_diam = diam height = self.win_size[1] celsize = int(height / diam) self.cspr_size = celsize # Build world screen_bg to be scrolled when the avatar moves # so that world_bg can be scrolled. # Padding of visib_diam so that the screen bg can subsurface(world_bg) v_rad = self.visib_rad w_w, w_h = worldmap.width, worldmap.height w_surf_w = celsize * (w_w + 2 * v_rad) w_surf_h = celsize * (w_h + 2 * v_rad) worldbg = pygame.Surface((w_surf_w, w_surf_h)) worldbg.fill(config_get_nonwalkable_color()) for i in range(w_w): for j in range(w_h): # don't forget the visib_rad of padding cspr_left = (v_rad + i) * celsize cspr_top = (v_rad + j) * celsize cellrect = pygame.Rect(cspr_left, cspr_top, celsize, celsize) cell = worldmap.get_cell(i, j) cellspr = CellSprite(cell, cellrect) self.cellsprs[cell] = cellspr # blit the cell to world bg worldbg.blit(cellspr.image, cellspr.rect) worldbg = worldbg.convert() self.world_bg = worldbg # Center screen screen_bg on entrance cell, and blit eleft, etop = worldmap.entrance_coords self.center_screen_on_coords(eleft, etop)
def __init__(self, cell, rect, group=()): Sprite.__init__(self, group) self.dims = self.width, self.height = rect.width, rect.height # fill self.image filled with the appropriate color self.image = pygame.Surface(self.dims) if cell.isentrance: color = config_get_entrance_color() elif cell.islair: color = config_get_lair_color() elif cell.iswalkable: color = config_get_walkable_color() else: # non-walkable color = config_get_nonwalkable_color() self.image.fill(color) self.rect = rect self.cell = cell