update levelconv and make lvl 2 a little easier

This commit is contained in:
Milang 2020-01-12 18:04:09 +01:00
parent 34b702561a
commit 651ca374c2
2 changed files with 108 additions and 16 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -1,9 +1,18 @@
from PIL import Image
# Palette de couleurs
pierre = (0, 0, 0, 255)
brique = (255, 0, 0, 255)
empty = (255, 255, 255, 255)
pierre = (0, 0, 0, 255)
brique = (255, 0, 0, 255)
empty = (255, 255, 255, 255)
piece = (203, 255, 0, 255)
boite_piece = (255, 153, 0, 255)
boite_champi = (204, 0, 255, 255)
brique_piece = (101, 127, 0, 255)
beton = (84, 84, 84, 255)
tuyau_milieu = (0, 255, 102, 255)
tuyau_bout = (50, 255, 0, 255)
# Load image
filename = input("File name ?\n> ")
@ -20,9 +29,8 @@ 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:
if pixels[x,y] == pierre:
hexa="0x"
left=1
@ -51,21 +59,105 @@ for x in range(0,img.size[0]):
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)
sy = int(bool(up))
hexa += str(sy)
code += "{EARTH," + hexa + "}, "
elif pixels[x,y]==piece:
code += "{COIN,0}, "
elif pixels[x,y] == brique:
code += "{BRICK,0}, "
elif pixels[x,y]==brique_piece:
code += "{BRICK,0x15}, "
elif pixels[x,y]==boite_piece:
code += "{GIFT,0x11}, "
elif pixels[x,y]==boite_champi:
code += "{GIFT,0x21}, "
elif pixels[x,y]==empty:
code += "{0,0}, "
elif pixels[x,y]==beton:
code += "{BLOC,0}, "
elif pixels[x,y]==tuyau_bout:
left=0
right=0
up=0 # vide par defaut
down=0
tx=0
ty=0
if x:
left = (pixels[x-1,y] == tuyau_bout) or (pixels[x-1,y] == tuyau_milieu)
if x != img.size[0]-1:
right = (pixels[x+1,y] == tuyau_bout) or (pixels[x+1,y] == tuyau_milieu)
if y:
up = (pixels[x,y-1] == tuyau_bout) or (pixels[x,y-1] == tuyau_milieu)
if y != img.size[1]-1:
down = (pixels[x,y+1] == tuyau_bout) or (pixels[x,y+1] == tuyau_milieu)
if right and down:
tx=0
if (pixels[x,y+1]==tuyau_milieu):
ty=2
elif left and down:
if (pixels[x,y+1]==tuyau_milieu):
tx=1
ty=2
else:
tx=2
ty=0
elif up and right:
tx=0
if (pixels[x,y-1]==tuyau_milieu):
ty=4
else:
ty=1
elif up and left:
if (pixels[x,y-1]==tuyau_milieu):
tx=1
ty=4
else:
tx=2
ty=1
hexa="0x"+str(tx)+str(ty)
code += "{TUYAU,"+hexa+"}, "
elif pixels[x,y]==tuyau_milieu:
left=0
right=0
up=0 # vide par defaut
down=0
tx=0
ty=0
if x:
left = (pixels[x-1,y] == tuyau_bout) or (pixels[x-1,y] == tuyau_milieu)
if x != img.size[0]-1:
right = (pixels[x+1,y] == tuyau_bout) or (pixels[x+1,y] == tuyau_milieu)
if y:
up = (pixels[x,y-1] == tuyau_bout) or (pixels[x,y-1] == tuyau_milieu)
if y != img.size[1]-1:
down = (pixels[x,y+1] == tuyau_bout) or (pixels[x,y+1] == tuyau_milieu)
if right and left==0:
tx=0
ty=3
elif left and right==0:
tx=1
ty=3
elif up==0 and down:
tx=1
ty=0
elif up and down==0:
tx=1
ty=1
hexa="0x"+str(tx)+str(ty)
code += "{TUYAU,"+hexa+"}, "
else:
code += "{0,'?'}, "
#code += str(pixels[x,y])
code += "\n};"
print (code)
f = open(filename+".c", 'w')
f.write(code)
f.close()