add python script "levelconv.py"
This commit is contained in:
parent
2c159812cf
commit
34b702561a
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
|
@ -0,0 +1,71 @@
|
|||
from PIL import Image
|
||||
|
||||
# Palette de couleurs
|
||||
pierre = (0, 0, 0, 255)
|
||||
brique = (255, 0, 0, 255)
|
||||
empty = (255, 255, 255, 255)
|
||||
|
||||
# Load image
|
||||
filename = input("File name ?\n> ")
|
||||
img = Image.open(filename)
|
||||
print("Loaded", filename, "(size =", img.size, ")")
|
||||
|
||||
code = "w_current_x = " + str(img.size[0]) + ";\nw_current_y = " + str(img.size[1]) + ";\nworld_t lvl[]=\n{"
|
||||
largeur=img.size[0]
|
||||
hauteur=img.size[1]
|
||||
|
||||
# Balayage des pixels : passe pour dessiner les murs
|
||||
pixels = img.load()
|
||||
for x in range(0,img.size[0]):
|
||||
code += "\n "
|
||||
for i in range(0, img.size[1]):
|
||||
y=img.size[1]-i-1
|
||||
if pixels[x,y] == brique:
|
||||
code += "{BRICK,0}, "
|
||||
elif pixels[x,y] == pierre:
|
||||
hexa="0x"
|
||||
|
||||
left=1
|
||||
right=1
|
||||
|
||||
if x != 0:
|
||||
left = (pixels[x-1,y] == pierre)
|
||||
if x != img.size[0]-1:
|
||||
right = (pixels[x+1,y] == pierre)
|
||||
|
||||
sx=0
|
||||
if left and right:
|
||||
sx=1
|
||||
elif left and right==0:
|
||||
sx=2
|
||||
elif left==0 and right:
|
||||
sx=0
|
||||
hexa+= str(sx)
|
||||
|
||||
|
||||
up=0 # vide par defaut
|
||||
down=1
|
||||
|
||||
if y != 0:
|
||||
up = (pixels[x,y-1] == pierre)
|
||||
if y != img.size[1]-1:
|
||||
down = (pixels[x,y+1] == pierre)
|
||||
|
||||
sy=0
|
||||
if up and down:
|
||||
sy=1
|
||||
elif up and down==0:
|
||||
sy=1
|
||||
elif up==0 and down:
|
||||
sy=0
|
||||
hexa+= str(sy)
|
||||
|
||||
|
||||
code += "{EARTH," + hexa + "}, "
|
||||
elif pixels[x,y]==empty:
|
||||
code += "{0,0}, "
|
||||
else:
|
||||
code += "{0,'?'}, "
|
||||
#code += str(pixels[x,y])
|
||||
|
||||
print (code)
|
Loading…
Reference in New Issue