level maker for https://my.numworks.com/python/mathieu-croslacoste/ruin_lite9_eps
originally by fime
from ion import keydown as k from kandinsky import draw_string as d,fill_rect as f from time import monotonic as c,sleep as s def printLvl(): try: lv,txt=compressLvl(),"" for i in range(len(lv)//219+1):txt+=lv[219*i:219*i+min(219,len(lv))]+"\n" print("\nLevel hash:\n"+txt) except:print("\nNo lvl loaded\n") def up(): d("Platform {}, Number :{}".format(sel,len(lvl)),0,0);d("Ghost:{}".format("x"+str(1-ghost[0])+" y"+str(1-ghost[1])),190,20);d("Mode:"+["Position","Size"][mode],0,202);d(str(lvl[sel]),0,20);d("{} bytes".format(len(lvl)*9),0,181) for id,arg in enumerate(lvl): if id==sel:c="r" elif id==0:c="orange" elif id==len(lvl)-1:c="g" else:c="b" f(arg[0]*5,arg[1]*5,arg[2]*5,arg[3]*5,c) def compressLvl(): txt="1"if ghost[0]else"0";txt+="1"if ghost[1]else"0" for i in lvl: x,y,w,h,nbNmy=i for j in(x,y,w,h):txt+=("0"if j<16 else"")+hex(j)[2:] txt+=str(nbNmy) return txt def uncompressLvl(txt): global ghost;Hex2Int=lambda n:int("0x"+n);plats,ghost=[],[int(txt[0]),int(txt[1])] for i in range(2,len(txt),9): ptfStr=txt[i:i+9];plat=[] for j in range(0,8,2):plat+=[Hex2Int(ptfStr[j:j+2])] plat.append(int(ptfStr[-1]));plats.append(plat) return plats def l(): print("\n---Press button---\n\n 1-New Level\n 2-Load level from hash");lvl=[[29,22,6,1,0]] while 1-k(42)-k(43):0 if k(43): print(">Load level...") try:lvl=uncompressLvl(input("\nPaste level code:\n")) except:print("\n>Error: unable to load from hash") else:print(">New level...") print("\n>>>Launching editor");editor(lvl) def editor(inLvl): global lvl,mode,sel,ghost;lvl,sel,mode=inLvl,0,0;up() while 1: if k(48):break for i in(0,1,2,3,4,12,13,16,17,33,34,45,46,52): if k(i): f(0,0,320,222,"w") if i==0:lvl[sel][mode*2]-=1 elif i==3:lvl[sel][mode*2]+=1 elif i==1:lvl[sel][mode*2+1]-=1 elif i==2:lvl[sel][mode*2+1]+=1 elif i==4:mode=1-mode elif i==12:ghost[0]=1-ghost[0] elif i==13:ghost[1]=1-ghost[1] elif i==16:lvl.insert(sel,list(lvl[sel]));sel,mode=sel+1,0 elif i==17 and len(lvl)>1:lvl.pop(sel);sel-=1 elif i==33:sel=(sel-1)%len(lvl) elif i==34:sel=(sel+1)%len(lvl) elif i==45:lvl[sel][4]+=1 elif i==46:lvl[sel][4]-=1 for j,l in enumerate((69,49,69,49)):lvl[sel][j]=lvl[sel][j]%(l-5) if i==52:printLvl() lvl[sel][4]=lvl[sel][4]%10;up();p=c() while k(i): if c()-p>(.2,.02)[i<4]:break f(0,0,320,222,"w");d("Press back to leave",65,101);printLvl();print("\nLevel size:{} bytes\nPlatforms number:{}\nCompression ratio:{}".format(len(lvl)*9,len(lvl),round(len(str(lvl))/len(compressLvl()),2))) while k(4):0 ghost=[1,1] try:l() except KeyboardInterrupt:printLvl()