-- LabyRoll' -- Louis DURAND (c) 2011 -- FRANCE 54 function on.create() paint=0 pause=false prog=var.recall("prog") if prog==nil then prog=1 end rand_set={10,10} lev=1 item=0 choi=1 xm=120 ym=110 noms_perso=var.recall("noms_perso") if noms_perso==nil then noms_perso={} end levels={ {{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,3,0,0,0},{0,1,1,1,0,0,1,1,1,0,0},{0,0,1,0,0,0,0,1,0,0,0},{0,0,1,0,0,0,0,1,0,0,0},{0,0,1,0,0,0,0,1,0,0,0},{0,0,1,0,2,0,1,1,1,2,0},{4,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}}, {{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,2,0,0,0,2,0,0,0},{0,0,0,2,0,0,0,2,0,0,0},{0,0,0,0,0,3,0,0,0,0,0},{0,0,1,0,0,0,0,0,1,0,0},{0,0,0,1,1,1,1,1,0,0,0},{0,0,0,0,0,0,4,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}}, {{3,1,0,0,0,0,0,0,0,0,0},{0,1,0,0,2,0,0,0,0,0,0},{0,1,1,2,1,0,0,0,0,0,0},{0,0,0,0,1,0,0,0,0,0,0},{2,2,0,0,1,1,1,1,0,1,0},{0,0,0,2,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,2,0,0},{0,0,0,1,0,0,0,0,1,4,0},{0,0,0,2,2,0,0,2,2,0,0}}, {{0,0,0,0,2,2,2,0,0,0,0},{0,0,0,2,1,1,1,2,0,0,0},{0,0,2,1,0,4,0,1,2,0,0},{0,2,1,0,0,0,0,0,1,2,0},{2,1,2,2,0,0,0,2,2,1,2},{0,1,2,2,0,0,0,2,2,1,0},{0,1,0,0,0,2,0,0,0,1,0},{0,1,0,0,2,0,2,0,0,1,0},{0,1,0,0,2,3,2,0,0,1,0}}, {{2,1,0,1,0,1,0,2,0,2,0},{0,0,0,1,0,0,0,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,2,2,2,3,2}}, {{4,0,1,0,1,0,0,0,0,0,2},{0,0,0,0,1,0,1,1,2,0,0},{1,1,2,0,1,0,0,0,0,2,0},{0,0,0,0,1,2,0,0,0,1,0},{0,1,1,1,1,1,1,1,0,1,0},{0,2,0,0,0,0,0,0,0,1,0},{0,0,2,1,1,1,1,1,1,1,0},{0,1,0,0,2,0,2,0,0,1,0},{0,0,0,2,0,2,3,2,0,0,0}}, {{3,0,0,0,2,0,0,0,0,0,0},{1,1,1,0,1,0,2,1,1,2,0},{2,0,0,0,0,0,2,0,0,1,0},{0,0,1,1,1,2,0,0,0,0,0},{0,2,1,0,0,1,0,1,1,1,1},{2,0,2,0,0,1,0,0,0,0,0},{1,2,0,2,0,1,1,1,1,1,0},{1,1,0,1,0,1,0,0,0,1,0},{4,0,0,1,0,0,0,2,0,0,0}} } end function on.paint(gc) local str,n ww=platform.window:width() wh=platform.window:height() if paint==0 then -- Menu gc:setColorRGB(220,220,255) gc:fillRect(0,0,ww,wh) gc:setFont("serif","r",20) gc:setColorRGB(200,150,50) gc:drawString("LabyRoll'",ww/2-gc:getStringWidth("LabyRoll'")/2+2,2,"top") gc:setColorRGB(20,255,30) gc:drawString("LabyRoll'",ww/2-gc:getStringWidth("LabyRoll'")/2,0,"top") gc:setColorRGB(50,0,50) gc:setFont("sansserif","b",10) gc:drawString("Choisissez un niveau :",40,50,"top") gc:drawString("Niveaux perso :",40,125,"top") gc:drawString("Niveau al"..string.uchar(233).."atoire",40,150,"top") gc:drawString(string.uchar(201).."diteur de niveaux",40,175,"top") if item==0 then gc:drawString(">",40-gc:getStringWidth("> "),50,"top") gc:setColorRGB(220,200,140) gc:fillRect((lev-math.floor(lev/9)*8)*ww/9-ww/18,75+math.floor(lev/9)*25,ww/9+1,25) else gc:drawString(">",40-gc:getStringWidth("> "),100+item*25,"top") end gc:setFont("sansserif","r",10) gc:setColorRGB(0,0,0) if #noms_perso~=0 then gc:drawString(noms_perso[choi],233-gc:getStringWidth(noms_perso[choi])/2,125,"top") if choi~=1 then gc:drawString(string.uchar(9664),160,125,"top") end if choi~=#noms_perso then gc:drawString(string.uchar(9654),300,125,"top") end else gc:drawString("Aucun niveau enregistr"..string.uchar(233),160,125,"top") end if item==1 then gc:setFont("sansserif","r",6) gc:drawString("[del] (ou clic ici) pour supprimer.",165,140,"top") elseif item==2 then gc:setFont("sansserif","r",10) if platform.isDeviceModeRendering() then gc:drawString("Murs : "..tostring(rand_set[1]),160,150,"top") gc:drawString("Trous : "..tostring(rand_set[2]),240,150,"top") gc:setFont("sansserif","r",7) gc:drawString("[+] [-] ["..string.uchar(215).."] ["..string.uchar(247).."]",170,165,"top") else gc:drawString("Murs : "..tostring(rand_set[1]),188,150,"top") gc:drawString("Trous : "..tostring(rand_set[2]),327,150,"top") gc:setFont("sansserif","r",7) gc:drawString("[+] [-]",198,165,"top") gc:drawString("["..string.uchar(215).."] ["..string.uchar(247).."]",340,165,"top") end end for n=1,3 do gc:drawLine(ww/9-ww/18,50+n*25,ww-ww/18,50+n*25) end for n=1,9 do gc:drawLine(n*ww/9-ww/18,75,n*ww/9-ww/18,125) end gc:setColorRGB(0,180,0) gc:setFont("sansserif","r",12) ll=gc:getStringWidth(string.uchar(10003)) for n=1,8 do if prog>n then gc:drawString(string.uchar(10003),n*ww/9-ll/2,75,"top") end end for n=1,8 do if prog>n+8 then gc:drawString(string.uchar(10003),n*ww/9-ll/2,100,"top") end end elseif paint==1 then -- Jeu gc:setColorRGB(20,255,30) gc:setFont("serif","bi",12) gc:drawString("Laby",250,10,"middle") gc:setFont("serif","b",12) gc:drawString("Roll'",280,30,"middle") gc:setColorRGB(150,100,190) gc:drawString("Niveau :",250,100,"top") gc:setFont("serif","r",12) gc:drawString(nivo,250,120,"top") gc:setColorRGB(200,180,60) gc:fillRect(0,0,245,220) gc:setColorRGB(200,160,60) gc:fillRect(10,20,220,180) gc:setColorRGB(50,50,50) for n=1,#trou do gc:fillArc(trou[n][2]*20-9,trou[n][1]*20+1,18,18,0,360) end gc:setColorRGB(200,0,0) gc:drawLine(finc*20-10,finl*20,finc*20+10,finl*20+20) gc:drawLine(finc*20+10,finl*20,finc*20-10,finl*20+20) if fin~=0 then gc:setFont("serif","b",13) gc:drawString(tostring(20-fin).." !",250,60,"top") end gc:setColorRGB(130,130,130) gc:fillArc(x+10,y+20,16,16,0,360) gc:setColorRGB(180,140,30) for n=1,#mur do xm=mur[n][2]*20-10 ym=mur[n][1]*20 if ay>0 then gc:fillPolygon({xm+ax/12,ym+ay/11,xm,ym,xm+20,ym,xm+20+ax/12,ym+ay/11}) end if ax>0 then gc:fillPolygon({xm+ax/12,ym+ay/11,xm,ym,xm,ym+20,xm+ax/12,ym+20+ay/11}) end if ay<0 then gc:fillPolygon({xm+20+ax/12,ym+20+ay/11,xm+20,ym+20,xm,ym+20,xm+ax/12,ym+20+ay/11}) end if ax<0 then gc:fillPolygon({xm+20+ax/12,ym+20+ay/11,xm+20,ym+20,xm+20,ym,xm+20+ax/12,ym+ay/11}) end end if ax<0 then gc:setColorRGB(180,140,30) gc:fillPolygon({10+ax/12,20+ay/11,10,20,10,200,10+ax/12,200+ay/11}) if ay<0 then gc:fillPolygon({10+ax/12,20+ay/11,10,20,230,20,230+ax/12,20+ay/11}) gc:setColorRGB(200,180,60) gc:fillPolygon({230+ax/12,200+ay/11,230,200,10,200,10+ax/12,200+ay/11}) else gc:fillPolygon({230+ax/12,200+ay/11,230,200,10,200,10+ax/12,200+ay/11}) gc:setColorRGB(200,180,60) gc:fillPolygon({10+ax/12,20+ay/11,10,20,230,20,230+ax/12,20+ay/11}) end gc:fillPolygon({230+ax/12,20+ay/11,230,20,230,200,230+ax/12,200+ay/11}) else gc:setColorRGB(180,140,30) gc:fillPolygon({230+ax/12,20+ay/11,230,20,230,200,230+ax/12,200+ay/11}) if ay<0 then gc:fillPolygon({10+ax/12,20+ay/11,10,20,230,20,230+ax/12,20+ay/11}) gc:setColorRGB(200,180,60) gc:fillPolygon({230+ax/12,200+ay/11,230,200,10,200,10+ax/12,200+ay/11}) else gc:fillPolygon({230+ax/12,200+ay/11,230,200,10,200,10+ax/12,200+ay/11}) gc:setColorRGB(200,180,60) gc:fillPolygon({10+ax/12,20+ay/11,10,20,230,20,230+ax/12,20+ay/11}) end gc:fillPolygon({10+ax/12,20+ay/11,10,20,10,200,10+ax/12,200+ay/11}) end gc:setColorRGB(200,180,60) for n=1,#mur do gc:fillRect(mur[n][2]*20-10+ax/12,mur[n][1]*20+ay/11,20,20) end gc:setColorRGB(200,0,0) gc:drawLine(120,110,ax+120,ay+110) -- Ligne de stabilite if not(begin) then gc:setColorRGB(math.random(0,255),math.random(0,255),math.random(0,255)) gc:setFont("sansserif","b",15) gc:drawString("Cliquez !",122-gc:getStringWidth("Cliquez !")/2,170) end elseif paint==2 then gc:setFont("serif","bi",20) gc:setColorRGB(math.random(0,255),math.random(0,255),math.random(0,255)) gc:drawString("Dommage !",70,70,"top") elseif paint==3 then gc:setFont("serif","bi",20) gc:setColorRGB(math.random(0,255),math.random(0,255),math.random(0,255)) gc:drawString("Bravo !",90,70,"top") gc:setColorRGB(0,0,0) gc:setFont("sansserif","i",10) gc:drawString("[enter] pour continuer,",40,125,"top") gc:drawString("[tab] pour recommencer.",40,150,"top") elseif paint==4 then -- WINSCREEN ! gc:setColorRGB(200,160,60) gc:fillRect(0,0,ww,wh) gc:setColorRGB(200,180,60) for n=1,math.random(50) do gc:fillRect(math.random(0,ww/20)*20,math.random(0,wh/20)*20,20,20) end gc:setColorRGB(50,50,50) for n=1,math.random(50) do gc:fillArc(math.random(0,ww/20)*20+1,math.random(0,wh/20)*20+1,18,18,0,360) end gc:setColorRGB(255,0,60) gc:setFont("serif","r",20) local tit="F"..string.uchar(233).."licitations !" gc:drawString(tit,(ww-gc:getStringWidth(tit))/2,120) gc:setColorRGB(30,30,240) gc:setFont("sansserif","b",11) tit="Avez-vous essay"..string.uchar(233).." l'"..string.uchar(233).."diteur de niveaux ? ;)" gc:drawString(tit,(ww-gc:getStringWidth(tit))/2,160) elseif paint==5 then -- Editeur de niveaux gc:setColorRGB(20,255,30) gc:setFont("serif","bi",12) gc:drawString("Laby",250,10,"middle") gc:setFont("serif","b",12) gc:drawString("Roll'",280,30,"middle") gc:setColorRGB(150,100,190) gc:setColorRGB(200,180,60) gc:fillRect(0,0,245,220) gc:fillRect(250,67,20,20) gc:setColorRGB(200,160,60) gc:fillRect(10,20,220,180) gc:fillRect(250,45,20,20) -- legende premier element gc:setColorRGB(50,50,50) gc:fillArc(251,90,18,18,0,360) gc:setColorRGB(130,130,130) gc:fillArc(252,113,16,16,0,360) gc:setColorRGB(200,0,0) gc:drawLine(250,133,270,153) gc:drawLine(270,133,250,153) gc:setColorRGB(150,100,190) gc:drawString("[A]",275,42,"top") gc:drawString("[B]",275,64,"top") gc:drawString("[C]",275,86,"top") gc:drawString("[D]",275,108,"top") gc:drawString("[E]",275,130,"top") gc:setPen("thin","dashed") gc:setColorRGB(100,100,100) gc:drawLine(245,41,ww,41) gc:drawLine(245,157,ww,157) gc:setColorRGB(0,0,200) gc:drawRect(249,44+selec*22,21,21) gc:setPen("thin","smooth") gc:setColorRGB(0,0,0) gc:setFont("sansserif","r",8) gc:drawString("[ctrl]+[del] (clear) pour tout effacer.",20,197,"top") for l=1,9 do for c=1,11 do if tab[l][c]==1 then gc:setColorRGB(200,180,60) gc:fillRect(c*20-10,l*20,20,20) elseif tab[l][c]==2 then gc:setColorRGB(50,50,50) gc:fillArc(c*20-9,l*20+1,18,18,0,360) elseif tab[l][c]==3 then gc:setColorRGB(130,130,130) gc:fillArc(c*20-8,l*20+2,16,16,0,360) elseif tab[l][c]==4 then gc:setColorRGB(200,0,0) gc:drawLine(c*20-10,l*20,c*20+10,l*20+20) gc:drawLine(c*20+10,l*20,c*20-10,l*20+20) end end end gc:setColorRGB(180,10,200) gc:drawRect(csel*20-10,lsel*20,20,20) end if pause==true then gc:setColorRGB(255,255,230) gc:fillRect(50,40,ww-100,wh-80) gc:setPen("thin","dashed") gc:setColorRGB(0,10,30) gc:drawRect(50,40,ww-100,wh-80) gc:setPen("thin","smooth") if paint==1 then str="Pause" gc:setFont("serif","r",9) gc:setColorRGB(0,0,100) gc:drawString(" Vous pouvez jouer avec la souris, les",55,80,"middle") gc:drawString("fl"..string.uchar(232).."ches, ou avec le pav"..string.uchar(233).." num"..string.uchar(233).."rique.",55,100,"middle") gc:drawString("[enter] (ou clic g.) pour continuer",70,125,"middle") gc:drawString("[esc] (ou clic d.) pour quitter",70,142,"middle") gc:drawString("[tab] pour recommencer",70,159,"middle") elseif paint==5 then str="Menu" gc:setFont("serif","r",9) gc:setColorRGB(0,0,100) gc:drawString("Quitter",90,76,"middle") gc:drawString("Ajouter murs al"..string.uchar(233).."atoires",90,92,"middle") gc:drawString("Ajouter trous al"..string.uchar(233).."atoires",90,108,"middle") gc:drawString("Annuler action ["..string.uchar(8629).."]",90,124,"middle") gc:drawString("Enregistrer :",70,140,"middle") gc:drawString("Charger :",70,156,"middle") gc:drawString(string.uchar(9670),58,76+opt*16,"middle") if opt==4 then gc:setColorRGB(230,230,255) gc:fillRect(150,136,100,16) gc:setColorRGB(0,0,0) gc:drawString(msg,155,141,"middle") n=gc:getStringWidth(msg) gc:drawLine(155+n,138,155+n,150) gc:setColorRGB(255,0,0) if exist==1 then gc:drawString("Existant. Remplacer ?",150,156,"middle") elseif exist==2 then gc:drawString("D"..string.uchar(233).."part inexistant !",150,156,"middle") elseif exist==3 then gc:drawString("Arriv"..string.uchar(233).."e inexistante !",150,156,"middle") end elseif opt==5 then gc:setColorRGB(0,0,0) if #noms_perso~=0 then gc:drawString(noms_perso[choi],155,156,"middle") if choi~=1 then gc:drawString(string.uchar(9664),145,156,"middle") end if choi~=#noms_perso then gc:drawString(string.uchar(9654),250,156,"middle") end else gc:drawString("Aucun niveau enregistr"..string.uchar(233),145,156,"middle") end end elseif paint==0 then str=string.uchar(192).." propos" gc:setFont("sansserif","b",9) gc:setColorRGB(0,0,255) gc:drawString("Louis DURAND "..string.uchar(169).." 2011-2012",75,85,"middle") gc:drawString("FRANCE ~ 54",115,105,"middle") gc:setFont("sansserif","r",8) gc:setColorRGB(0,0,0) gc:drawString("Remarques ? Probl"..string.uchar(232).."mes ? =>",55,125,"middle") gc:drawString("aphone@hotmail.fr Et retrouvez mes autres",60,142,"middle") gc:drawString("programmes sur ti-planet.org ! :)",60,159,"middle") end gc:setFont("serif","r",20) gc:setColorRGB(200,150,50) gc:drawString(str,ww/2-gc:getStringWidth(str)/2+2,35,"top") gc:setColorRGB(20,255,30) gc:drawString(str,ww/2-gc:getStringWidth(str)/2,33,"top") end if not(platform.isDeviceModeRendering()) then gc:setColorRGB(0,0,0) gc:setFont("sansserif","r",7) gc:drawString("(ou clic droit)",253,196,"top") gc:fillRect(270,170,42,25) gc:setColorRGB(240,240,240) gc:drawRect(271,171,39,22) gc:setFont("sansserif","b",11) gc:drawString("esc",278,170,"top") end end function on.timer() vx=(vx+ax)*0.95 x=x+vx/100 vy=(vy+ay)*0.95 y=y+vy/100 if y<0 then y=0 vy=-math.floor(vy/4) end if y>164 then y=164 vy=-math.floor(vy/4) end if x<0 then x=0 vx=-math.floor(vx/4) end if x>204 then x=204 vx=-math.floor(vx/4) end c1=math.floor(x/20)+1 c2=math.floor((x+8)/20)+1 c3=math.floor((x+16)/20)+1 l1=math.floor(y/20)+1 l2=math.floor((y+8)/20)+1 l3=math.floor((y+16)/20)+1 is_trou=0 if tab[l2][c1]==1 then x=c1*20 vx=-math.floor(vx/4) elseif tab[l2][c1]==2 then if x-c1*20+18<14 then vx=vx-50 end is_trou=1 end if tab[l1][c2]==1 then y=l1*20 vy=-math.floor(vy/4) elseif tab[l1][c2]==2 then if y-l1*20+18<14 then vy=vy-50 end is_trou=is_trou+1 end if c3<12 then if tab[l2][c3]==1 then x=(c1-1)*20+4 vx=-math.floor(vx/4) elseif tab[l2][c3]==2 then if c3*20-18-x<14 then vx=vx+50 end is_trou=is_trou+1 end end if l3<10 then if tab[l3][c2]==1 then y=(l1-1)*20+4 vy=-math.floor(vy/4) elseif tab[l3][c2]==2 then if l3*20-18-y<14 then vy=vy+50 end is_trou=is_trou+1 end end if is_trou>2 then timer.stop() paint=2 end if l2==finl and c2==finc then fin=fin+1 if fin>=20 then timer.stop() paint=3 end else fin=0 end platform.window:invalidate() end function on.mouseMove(xx,yy) if pause==false then if paint==1 then cursor.set("crosshair") if xx<240 and yy<220 and begin then ax=(xx-120) ay=(yy-110) else cursor.set("pointer") end elseif paint==0 then local item2,lev2 item2=item lev2=lev if yy>127 and yy<202 then item=math.floor((yy-107)/25) elseif yy<125 then item=0 if math.abs(xx-ww/2)<4*ww/9 and math.abs(yy-100)<25 then lev=math.floor((yy-75)/25)*8+math.floor((18*xx-ww)/(2*ww))+1 if lev>prog then lev=prog end end end if item2~=item or lev2~=lev then platform.window:invalidate() end elseif paint==5 then cursor.set("hand pointer") end else cursor.set("hollow pointer") if paint==5 and xx>50 and xx72 and yy<168 then local opt2=opt opt=math.floor((yy-72)/16) if opt~=opt2 then platform.window:invalidate() end end end end function on.mouseDown(xx,yy) local dev=platform.isDeviceModeRendering() if not(dev) and math.abs(291-xx)<21 and math.abs(182-yy)<12 then on.escapeKey() else if paint==2 then paint=1 init() elseif paint==3 then paint=1 if item==0 then lev=lev+1 if lev>prog then prog=lev var.store("prog",prog) end load_level() elseif item==2 then load_level() else paint=0 platform.window:invalidate() end elseif paint==1 then if pause==true then pause=false timer.start(0.05) elseif not(begin) and xx<240 and yy<220 then timer.start(0.05) ax=(xx-120) ay=(yy-110) begin=true else ax=0 ay=0 end elseif paint==0 then if pause==true then pause=false platform.window:invalidate() else if math.abs(xx-165)<7 and math.abs(yy-138)<8 then on.arrowLeft() elseif math.abs(xx-305)<7 and math.abs(yy-138)<8 then on.arrowRight() elseif math.abs(xx-233)<70 and math.abs(yy-150)<5 then on.backspaceKey() elseif math.abs(xx-176)<7 and math.abs(yy-176)<6 and dev or math.abs(xx-206)<8 and math.abs(yy-176)<6 and not(dev) then on.charIn("+") elseif math.abs(xx-196)<7 and math.abs(yy-176)<6 and dev or math.abs(xx-233)<8 and math.abs(yy-176)<6 and not(dev) then on.charIn("-") elseif math.abs(xx-262)<7 and math.abs(yy-176)<6 and dev or math.abs(xx-348)<8 and math.abs(yy-176)<6 and not(dev) then on.charIn("*") elseif math.abs(xx-282)<7 and math.abs(yy-176)<6 and dev or math.abs(xx-375)<8 and math.abs(yy-176)<6 and not(dev) then on.charIn("/") elseif math.abs(xx-ww/2)<4*ww/9 and math.abs(yy-100)<25 or yy>125 then on.enterKey() end end elseif paint==5 then if pause==true then if xx>50 and xx72 and yy<168 then if opt==5 and math.abs(150-xx)<7 then on.arrowLeft() elseif opt==5 and math.abs(255-xx)<7 then on.arrowRight() else on.enterKey() end else pause=false end else if xx>249 and yy>44 and yy<156 then cursor.set("hand closed") sav_tab() selec=math.floor((yy-45)/22) elseif xx>10 and xx<230 and yy>20 and yy<200 then csel=math.floor((xx+10)/20) lsel=math.floor(yy/20) poser(selec) elseif xx<170 and yy>200 and yy<216 then on.clearKey() end end platform.window:invalidate() end end end function on.rightMouseDown(x,y) on.escapeKey() end function on.charIn(ch) ch=string.lower(ch) if paint==0 then if ch=="8" then on.arrowUp() elseif ch=="2" then on.arrowDown() elseif ch=="4" then on.arrowLeft() elseif ch=="6" then on.arrowRight() elseif ch=="5" then on.enterKey() elseif ch=="+" then rand_set[1]=(rand_set[1]+1)%51 elseif ch=="-" then rand_set[1]=(rand_set[1]-1)%51 elseif ch=="*" then rand_set[2]=(rand_set[2]+1)%51 elseif ch=="/" then rand_set[2]=(rand_set[2]-1)%51 end platform.window:invalidate() elseif paint==1 and pause==false then if string.find(ch,"%d") and ch~="0" then if not(begin) then timer.start(0.05) begin=true end ch=tonumber(ch) if ax<125 and (ch==3 or ch==6 or ch==9) then ax=ax+25 end if ax>-125 and (ch==1 or ch==4 or ch==7) then ax=ax-25 end if ay<125 and ch<4 then ay=ay+25 end if ay>-125 and ch>6 then ay=ay-25 end if ch==5 then on.enterKey() end end elseif paint==5 and pause==false then if string.find(ch,"[abcde]") then if selec~=string.byte(ch)-97 then sav_tab() selec=string.byte(ch)-97 end poser(selec) end if string.find(ch,"%d") and ch~="0" then ch=tonumber(ch) if csel<11 and (ch==3 or ch==6 or ch==9) then csel=csel+1 end if csel>1 and (ch==1 or ch==4 or ch==7) then csel=csel-1 end if lsel<9 and ch<4 then lsel=lsel+1 end if lsel>1 and ch>6 then lsel=lsel-1 end if ch==5 then on.enterKey() end end platform.window:invalidate() elseif paint==5 then if string.find(ch,"[%a%d_]") and #msg<16 then msg=msg..ch exist=0 platform.window:invalidate() end elseif ch=="5" then on.mouseDown(120,110) end end function on.enterKey() local n,rl,rc if paint==0 then if pause==true then pause=false platform.window:invalidate() else if item==3 then if tab==nil then tab={{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}} end csel=6 lsel=5 selec=0 opt=0 paint=5 msg="mon_level"..tostring(#noms_perso+1) exist=0 choi=1 sav_tab() elseif #noms_perso~=0 or item~=1 then paint=1 load_level() end end platform.window:invalidate() elseif paint==5 then if pause==true then if opt==0 then pause=false paint=0 elseif opt==1 or opt==2 then sav_tab() pause=false for n=1,10 do rl=math.random(1,9) rc=math.random(1,11) if (rl~=lstrt or rc~=cstrt) and (rl~=finl or rc~=finc) then tab[rl][rc]=opt end end elseif opt==3 then pause=false on.returnKey() elseif opt==4 then if exist~=1 then if cstrt~=nil and finc~=nil then for n=1,#noms_perso do if msg==noms_perso[n] then exist=1 end end if #msg~=0 and not(string.find(string.usub(msg,1,1),"%d")) and exist~=1 then table.insert(noms_perso,msg) var.store("noms_perso",noms_perso) stoMat(tab,msg) paint=0 pause=false end else if cstrt==nil then exist=2 else exist=3 end end else stoMat(tab,msg) paint=0 pause=false end elseif opt==5 and #noms_perso~=0 then pause=false msg=noms_perso[choi] load_level() end else poser(selec) end platform.window:invalidate() else on.mouseDown(120,110) end end function on.escapeKey() if math.abs(3-paint)<2 then paint=0 elseif pause==false then pause=true timer.stop() elseif paint==1 or paint==5 then pause=false if paint==1 then paint=0 end else pause=false end platform.window:invalidate() end function on.clearKey() if paint==5 and pause==false then sav_tab() tab={{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}} cstrt=nil finc=nil platform.window:invalidate() elseif paint==5 and opt==4 then msg="" exist=0 end end function on.tabKey() if paint==1 or paint==2 or paint==3 then paint=1 pause=false init() elseif paint==5 and pause==false then sav_tab() selec=(selec+1)%5 platform.window:invalidate() end end function on.backtabKey() if paint==5 and pause==false then sav_tab() selec=(selec-1)%5 platform.window:invalidate() end end function on.backspaceKey() if paint==5 and pause==true and opt==4 then msg=string.sub(msg,1,#msg-1) exist=0 elseif paint==5 then poser(0) elseif paint==0 and item==1 and #noms_perso~=0 then math.eval("DelVar "..noms_perso[choi]) table.remove(noms_perso,choi) var.store("noms_perso",noms_perso) if choi>#noms_perso then choi=#noms_perso end end platform.window:invalidate() end function on.returnKey() local tab_buf,cstrtb,lstrtb,fincb,finlb if paint==5 and pause==false then tab_buf=deepcopy(tab2) tab2=deepcopy(tab) cstrtb=cstrt lstrtb=lstrt fincb=finc finlb=finl tab=deepcopy(tab_buf) cstrt=cstrt2 lstrt=lstrt2 finc=finc2 finl=finl2 cstrt2=cstrtb lstrt2=lstrtb finc2=fincb finl2=finlb platform.window:invalidate() end end function on.arrowLeft() if pause==false then if paint==1 and ax>-125 then if not(begin) then timer.start(0.05) begin=true end ax=ax-25 elseif paint==5 and csel>1 then csel=csel-1 platform.window:invalidate() elseif paint==0 then if item==0 and lev>1 then lev=lev-1 elseif item==1 and choi>1 then choi=choi-1 end platform.window:invalidate() end elseif paint==5 and opt==5 and choi>1 then choi=choi-1 platform.window:invalidate() end end function on.arrowRight() if pause==false then if paint==1 and ax<125 then if not(begin) then timer.start(0.05) begin=true end ax=ax+25 elseif paint==5 and csel<11 then csel=csel+1 platform.window:invalidate() elseif paint==0 then if item==0 and lev-125 then if not(begin) then timer.start(0.05) begin=true end ay=ay-25 elseif paint==5 and lsel>1 then lsel=lsel-1 platform.window:invalidate() elseif paint==0 then if item==0 and lev>8 then lev=lev-8 elseif item>0 then item=item-1 else item=3 end platform.window:invalidate() end elseif paint==5 then opt=(opt-1)%6 platform.window:invalidate() end end function on.arrowDown() if pause==false then if paint==1 and ay<125 then if not(begin) then timer.start(0.05) begin=true end ay=ay+25 elseif paint==5 and lsel<9 then lsel=lsel+1 platform.window:invalidate() elseif paint==0 then if item==0 and lev<9 and prog>8 then lev=lev+8 if lev>prog then lev=prog end else item=math.fmod(item+1,4) end platform.window:invalidate() end elseif paint==5 then opt=(opt+1)%6 platform.window:invalidate() end end -- Fonctions function load_level() local l,c,r,i if item==0 then if lev<17 then tab=deepcopy(levels[lev]) nivo=tostring(lev).." / 16" else lev=16 paint=4 end elseif item==2 then tab={{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}} for i=1,2 do for n=1,rand_set[i] do rl=math.random(1,9) rc=math.random(1,11) tab[rl][rc]=i end end cstrt=math.random(1,11) lstrt=math.random(1,9) finl=lstrt finc=cstrt while finl==lstrt and finc==cstrt do finl=math.random(1,9) finc=math.random(1,11) end tab[lstrt][cstrt]=3 tab[finl][finc]=4 nivo="Al"..string.uchar(233).."atoire!" elseif item==1 or item==3 then nivo=noms_perso[choi] tab=var.recall(noms_perso[choi]) end mur={} trou={} for l=1,9 do for c=1,11 do if tab[l][c]==1 then table.insert(mur,{l,c}) elseif tab[l][c]==2 then table.insert(trou,{l,c}) elseif tab[l][c]==3 then cstrt=c lstrt=l elseif tab[l][c]==4 then finl=l finc=c end end end if item ~=3 then init() end end function poser(ch) if csel==cstrt and lsel==lstrt then cstrt=nil elseif csel==finc and lsel==finl then finc=nil end if ch==3 then if cstrt~=nil then tab[lstrt][cstrt]=0 end cstrt=csel lstrt=lsel elseif ch==4 then if finc~=nil then tab[finl][finc]=0 end finc=csel finl=lsel end tab[lsel][csel]=ch end function init() timer.stop() vx=0 vy=0 ax=0 ay=0 fin=0 x=(cstrt-1)*20+2 y=(lstrt-1)*20+2 is_trou=0 begin=false platform.window:invalidate() end function deepcopy(t) if type(t) ~= 'table' then return t end local mt = getmetatable(t) local res = {} for k,v in pairs(t) do if type(v) == 'table' then v = deepcopy(v) end res[k] = v end setmetatable(res,mt) return res end -- From better Lua. Merci a Adriweb ! function sav_tab() tab2=deepcopy(tab) cstrt2=cstrt lstrt2=lstrt finc2=finc finl2=finl end function stoMat(t,nom) local c,l math.eval("NewMat(9,11)=:"..nom) for l=1,#t do for c=1,#t[1] do if t[l][c]~=0 then math.eval(tostring(t[l][c]).."=:"..nom.."["..tostring(l)..","..tostring(c).."]") end end end end