예제 #1
0
    def _load_tiles(self, path):
        tile_ids, size = self.tile_definitions()
        sheet = pygame.image.load(path)

        tiles = {
            tile: util.image_at(sheet, tile - 1, size).convert_alpha()
            for tile in tile_ids
        }

        return tiles
예제 #2
0
    def tiles(self):
        try:
            tileset_path = os.path.join(dir_path, "assets", "textures", "tiles.png")
            sheet = pygame.image.load(tileset_path)
        except pygame.error:
            tileset_path = os.path.join(dir_path,  "assets", "textures", "tiles.png")
            sheet = pygame.image.load(tileset_path)

        tile_types = [int(getattr(Tile, x)) for x in Tile.__dict__.keys() if not x.startswith("__") and not x == 'name']

        tiles = {}
        for tile_type in tile_types:
            sprite = util.image_at(sheet, tile_type - 1, self.gui.map.tile_width).convert_alpha()  # -1 to account for index 0
            tiles[tile_type] = sprite

        return tiles