diff options
Diffstat (limited to 'img2map')
| -rwxr-xr-x | img2map | 37 |
1 files changed, 29 insertions, 8 deletions
@@ -3,19 +3,40 @@ import sys from PIL import Image -img = Image.open(sys.argv[1]).convert('1') +img = Image.open(sys.argv[1]).convert('RGB') width, height = img.size -print(f"int map_width = {width};") -print(f"int map_height = {height};") -print("char map_data[] = {") +map_pixels = [ ] +player_position = (0, 0) + +ghosts = [] for y in range(height): linha = [] for x in range(width): - pixel = img.getpixel((x, y)) - valor = '0' if pixel == 0 else '1' - linha.append(valor) - print(f" {', '.join(linha)},") + r, g, b = img.getpixel((x, y)) + valor = '0' + if (r == 0xFF) and (g == 0xFF) and (b == 0xFF): + valor = '1' + + if (r == 0x00) and (g == 0x00) and (b == 0xFF): + player_position = (x, y) + + if (r == 0xFF) and (g == 0x00) and (b == 0x00): + ghosts.append((x, y)) + + map_pixels.append(valor) +print(f"int map_width = {width};") +print(f"int map_height = {height};") +print(f"float player_x = {player_position[0]};") +print(f"float player_y = {player_position[1]};") +print(f"int ghostcount = {len(ghosts)};") + +print("float ghostpositions[][2] = {") +print("".join([ f"{{ {str(x[0])}, {str(x[1])} }}, " for x in ghosts ])) +print("};") + +print("char map_data[] = {") +print("".join([ f"{x}," for x in map_pixels ])) print("};") |
