Example #1
0
def make_map(path, outputpath=None, mark=False, name=None):
    images = {}
    render = {}
    if mark:
        mark = [12, 26, 31]
    else:
        mark = []
    for tile in mark:
        try:
            images[tile] = (pygame.image.load(str(tile) + ".png"))
        except Exception as e:
            print("Could not load image for tile ID %d") % (tile)
            raise e
        render[tile] = []
    if len(mark):
        chests = []
        chestsizes = []
        for x in range(6):
            chests.append((pygame.image.load("21_" + str(x * 36) + ".png")))
            chestsizes.append(chests[-1].get_size())

        mark.append(21)
        render[21] = []
    start = time.clock()
    with open(path, "rb") as f:
        b = [0]
        header = get_header(f)[0]  # read header with tlib.get_header and also reach tile data in f
        x, y = header["width"], header["height"]  #read world size from header cache
        s = pygame.surface.Surface((x, y))  #create a software surface to save tile colors in
        s.fill((200, 200, 255))
        levels = header["groundlevel"], header["rocklevel"]
        pygame.draw.rect(s, (150, 75, 0),
                         ((0, levels[0]),
                          (x, y - levels[0])))

        pygame.draw.rect(s, (50, 50, 50),
                         ((0, levels[1]),
                          (x, y - levels[1])))
        for xi in range(x):  # for each slice
            for yi in range(y):  # get the tiles
                #tiles start from the upper left corner, then go downwards
                # when a slice is complete its starts with the next slice

                tile, b = get_tile_buffered(f, b)  #tlib.get_tile

                tile, wall, liquid, multi, wire = tile
                if not liquid:  #liquid == 0 means no liquid
                    # there could be a liquid and a tile, like a chest and water,
                    #but I can only set one color to a pixel anyway, so I priotise the tile
                    if tile == None:
                        if wall:
                            if wall in colorlib.walldata:
                                s.set_at((xi, yi), colorlib.walldata[wall])
                            else:
                                print(wall)
                                s.set_at((xi, yi), (wall, wall, wall))

                                #s.set_at((xi,yi), (255,255,255))#if no tile present, set it white

                    elif tile in colorlib.data:
                        s.set_at((xi, yi), colorlib.data[tile])  #if colorlib has a color use it
                    else:
                        s.set_at((xi, yi), (tile, tile, tile))  #make a grey
                elif liquid > 0:  #0>x>256 is water, the higher x is the more water is there
                    s.set_at((xi, yi), (19, 86, 134))
                else:  #lava is -256>x>0
                    s.set_at((xi, yi), (150, 35, 17))
                if tile in mark:
                    if multi == None:
                        render[tile].append((xi, yi, multi))
                    elif multi[0] % 36 == 0 and multi[1] == 0:
                        render[tile].append((xi, yi, multi))
            if xi % 100 == 0:  # every ten slices print the progress
                if name == None:
                    print("done %5d of %5d\r" % (xi, x))
                else:
                    print("done %5d of %5d, of %s" % (xi, x, name))

    for tile in render:
        for pos in render[tile]:


            if tile == 21:
                if pos[2][0] % 36 == 0 and pos[2][1] == 0:
                    kind = pos[2][0] // 36
                    try:
                        s.blit(chests[kind], (pos[0] - chestsizes[kind][0] // 2, pos[1] - chestsizes[kind][1] // 2))
                    except IndexError:
                        kind = 0
                        s.blit(chests[kind], (pos[0] - chestsizes[kind][0] // 2, pos[1] - chestsizes[kind][1] // 2))
            else:
                i = images[tile]
                size = i.get_size()
                s.blit(i, (pos[0] - size[0] // 2, pos[1] - size[1] // 2))
    try:
        if outputpath == None:
            pa = path[:-3] + "png"
        else:
            pa = outputpath[:-3] + "png"
        pygame.image.save(s, pa)
    except:  # if pygame was not build with additional image types, we go with with bmp which is guaranteed to exist
        if outputpath == None:
            pa = path[:-3] + "bmp"
        else:
            pa = outputpath[:-3] + "bmp"
        pygame.image.save(s, pa)  # save the map and exit
    if name:
        print("completed mapping " + name)
    else:
        print("Completed mapping a World! ")
    return pa
Example #2
0
def make_map(path, outputpath=None, mark=False, name=None):
    images = {}
    render = {}
    if mark:
        mark = [12, 26, 31]
    else:
        mark = []
    for tile in mark:
        try:
            images[tile] = (pygame.image.load(str(tile) + ".png"))
        except Exception as e:
            print("Could not load image for tile ID %d") % (tile)
            raise e
        render[tile] = []
    if len(mark):
        chests = []
        chestsizes = []
        for x in range(6):
            chests.append((pygame.image.load("21_" + str(x * 36) + ".png")))
            chestsizes.append(chests[-1].get_size())

        mark.append(21)
        render[21] = []
    start = time.clock()
    with open(path, "rb") as f:
        b = [0]
        header = get_header(
            f
        )[0]  # read header with tlib.get_header and also reach tile data in f
        x, y = header["width"], header[
            "height"]  #read world size from header cache
        s = pygame.surface.Surface(
            (x, y))  #create a software surface to save tile colors in
        s.fill((200, 200, 255))
        levels = header["groundlevel"], header["rocklevel"]
        pygame.draw.rect(s, (150, 75, 0), ((0, levels[0]), (x, y - levels[0])))

        pygame.draw.rect(s, (50, 50, 50), ((0, levels[1]), (x, y - levels[1])))
        for xi in range(x):  # for each slice
            for yi in range(y):  # get the tiles
                #tiles start from the upper left corner, then go downwards
                # when a slice is complete its starts with the next slice

                tile, b = get_tile_buffered(f, b)  #tlib.get_tile

                tile, wall, liquid, multi, wire = tile
                if not liquid:  #liquid == 0 means no liquid
                    # there could be a liquid and a tile, like a chest and water,
                    #but I can only set one color to a pixel anyway, so I priotise the tile
                    if tile == None:
                        if wall:
                            if wall in colorlib.walldata:
                                s.set_at((xi, yi), colorlib.walldata[wall])
                            else:
                                print(wall)
                                s.set_at((xi, yi), (wall, wall, wall))

                                #s.set_at((xi,yi), (255,255,255))#if no tile present, set it white

                    elif tile in colorlib.data:
                        s.set_at((xi, yi), colorlib.data[tile]
                                 )  #if colorlib has a color use it
                    else:
                        s.set_at((xi, yi), (tile, tile, tile))  #make a grey
                elif liquid > 0:  #0>x>256 is water, the higher x is the more water is there
                    s.set_at((xi, yi), (19, 86, 134))
                else:  #lava is -256>x>0
                    s.set_at((xi, yi), (150, 35, 17))
                if tile in mark:
                    if multi == None:
                        render[tile].append((xi, yi, multi))
                    elif multi[0] % 36 == 0 and multi[1] == 0:
                        render[tile].append((xi, yi, multi))
            if xi % 100 == 0:  # every ten slices print the progress
                if name == None:
                    print("done %5d of %5d\r" % (xi, x))
                else:
                    print("done %5d of %5d, of %s" % (xi, x, name))

    for tile in render:
        for pos in render[tile]:

            if tile == 21:
                if pos[2][0] % 36 == 0 and pos[2][1] == 0:
                    kind = pos[2][0] // 36
                    try:
                        s.blit(chests[kind],
                               (pos[0] - chestsizes[kind][0] // 2,
                                pos[1] - chestsizes[kind][1] // 2))
                    except IndexError:
                        kind = 0
                        s.blit(chests[kind],
                               (pos[0] - chestsizes[kind][0] // 2,
                                pos[1] - chestsizes[kind][1] // 2))
            else:
                i = images[tile]
                size = i.get_size()
                s.blit(i, (pos[0] - size[0] // 2, pos[1] - size[1] // 2))
    try:
        if outputpath == None:
            pa = path[:-3] + "png"
        else:
            pa = outputpath[:-3] + "png"
        pygame.image.save(s, pa)
    except:  # if pygame was not build with additional image types, we go with with bmp which is guaranteed to exist
        if outputpath == None:
            pa = path[:-3] + "bmp"
        else:
            pa = outputpath[:-3] + "bmp"
        pygame.image.save(s, pa)  # save the map and exit
    if name:
        print("completed mapping " + name)
    else:
        print("Completed mapping a World! ")
    return pa
Example #3
0
def make_info(path):
    with  open(path, "rb") as f:
        header = get_header(f)[0]
    for key in header:
        print(key + ": " + str(header[key]))