def txt2map(txt, gamelayer, tilelayer): size = txt.readline().split() width = tilelayer.width = gamelayer.width = int(size[0]) height = tilelayer.height = gamelayer.height = int(size[1]) for y in range(0, height): row = txt.readline().rstrip('\n') x = 0 for c in row: t = Tile() t.index = rgb2tile(txt2rgb(c)) tilelayer.set_tile(x, y, t) t.index = rgb2game(txt2rgb(c)) gamelayer.set_tile(x, y, t) x += 1
def img2map(img, gamelayer, tilelayer): width, height = img.size tilelayer.width = gamelayer.width = width tilelayer.height = gamelayer.height = height for y in range(0, height): for x in range(0, width): rgb = img.getpixel((x, y)) tileidx = rgb2tile(rgb) gameidx = rgb2game(rgb) t = Tile() t.index = tileidx tilelayer.set_tile(x, y, t) t.index = gameidx gamelayer.set_tile(x, y, t)