1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/usr/bin/env python3
import sys
from PIL import Image
img = Image.open(sys.argv[1]).convert('RGB')
width, height = img.size
map_pixels = [ ]
player_position = (0, 0)
ghosts = []
teles = []
for y in range(height):
linha = []
for x in range(width):
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))
if (r == 0xFF) and (g == 0xFF) and (b == 0x00):
teles.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(f"int telessize = {len(teles)};")
print("struct { float x, y; } teles[] = {")
print("".join([ f"{{ .x = {str(x[0])}, .y = {str(x[1])} }}, " for x in teles ]))
print("};")
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("};")
|