--!name Sky Drop
--!icon game
--!category Games
local n=snail.touchscreen==true local N,F=14,16 local W={0,-1,0,1,0}local V=4 local U={}local ae={"..^!..","..++..","<++++>","=++++?","..++..","..~|.."}local g,E="menu",1 local q={}local y,C,h,T=2,2,3,1 local w,A=0,false local f,s,H,u=0,0,0,0 local t,m,J,z,R=false,1,nil,0,false local l={0,0}local M=1 local function S(an)M=(M*1664525+1013904223)&0xFFFFFFFF return(M>>16)%an end local function P()if m==1 then return math.max(500,950-f*3)end return math.max(450,700-f*2)end local function al()if m==1 then return math.min(70,35+f//3)end return math.min(85,55+f//4)end local function aq()snail.save(l[1]..","..l[2])end local function ao()if os and os.time then M=os.time()%100000+11 end for a=1,3 do q[a]={false,false,false,false,false}end y,C,h,T=2,2,3,1 w,A=0,false f,s,H,u=0,0,0,1 t,J,z=false,nil,0 g="play"snail.tick(P())end local function ap()g="over"snail.tick(0)R=f>l[m]if R then l[m]=f aq()end end local function ag()f=math.min(9999,f+1)H=1 if(f==200 or f==500)and s>0 then s=0 J,z="BONUS  misses cleared",2 end snail.tick(P())end local function ai()local ad=2*w-1 if A then w,A=0,false if s>=3 then ap()end elseif h==ad then A=true s=s+1 else h=h+(ad>h and 1 or-1)end end local function ar()if S(100)>=al()then C=math.max(1,math.min(3,C+S(3)-1))return end local a=S(3)+1 for ab=1,3 do if q[ab][2]and math.abs(ab-a)>1 then a=2 end end C=a q[a][1]=true end function tick()if g~="play"or t then snail.tick(0)return end H=0 if u>0 then u=u-1 return end if z>0 then z=z-1 if z==0 then J=nil end end if w>0 then ai()return end for a=1,3 do if q[a][5]then q[a][5]=false if y==a then ag()else w=a end end end if w>0 then return end for a=1,3 do local O=q[a]for c=5,2,-1 do O[c]=O[c-1]end O[1]=false end if h==1 or h==5 then T=h==1 and 1 or-1 end h=h+T ar()end local function Q(a)if g~="play"or t or u>0 then return end y=math.max(1,math.min(3,a))end function key(a)if g=="menu"then if a=="up"or a=="down"then E=3-E elseif a=="ok"then m=E ao()end return end if g=="over"then if a=="ok"then g="menu"end return end if a=="ok"then t=not t snail.tick(t and 0 or P())return end if a=="left"then Q(y-1)elseif a=="right"then Q(y+1)end end local function aj(k,x)local b,d=x-F-1,k-1 if b<0 then return nil end local I,_=2*(d-V)-5,2*b-5 if I>=-7 and I<=7 then local Y,Z=math.abs(I),math.abs(_)if Y>Z then return I<0 and"left"or"right"end if Z>Y then return _<0 and"up"or"down"end return nil end for X,p in ipairs(U)do if d>=p[1]and d<=p[1]+1 then return p[3]end end end function touch(am,k,x)if am~="board"then return end if n then local a=aj(k,x)if a then return key(a)end else k=k-1 end if x<=F then Q(k<=4 and 1 or k<=8 and 2 or 3)end end local function ak()local j={}for b=1,6 do j[b]={}for d=1,N do j[b][d]="."end for c=1,6 do j[b][V+c]=ae[b]:sub(c,c)end end for X,p in ipairs(U)do local K,b,d=p[4]and"()[]"or"$&;:",p[2]+1,p[1]+1 j[b][d],j[b][d+1]=K:sub(1,1),K:sub(2,2)j[b+1][d],j[b+1][d+1]=K:sub(3,3),K:sub(4,4)end for b=1,6 do j[b]=table.concat(j[b])end return j end local function as(B)local D={}for b=0,F-1 do local v=table.concat(B[b])D[#D+1]=n and v or"."..v.."."end if n then for X,L in ipairs(ak())do D[#D+1]=L end end return table.concat(D,"/")end local function af()local o=u>0 local B={}for b=0,F-1 do local L={}for d=1,N do L[d]="."end B[b]=L end local function e(d,b,ah)B[b][d+1]=ah end local v=o and"8888"or string.format("%4d",f):gsub(" ","_")for c=1,4 do e(c-1,0,v:sub(c,c))end for c=1,3 do e(10+c,0,(o or s>=c)and"f"or"F")end e(1,1,"k");e(6,0,"k")for d=0,N-1 do e(d,13,"w");e(d,15,"g")end for a=1,3 do local r=4*a-1 local i=o or C==a e(r,1,i and"h"or"H");e(r+1,1,i and"t"or"T")for c=1,5 do i=o or q[a][c]e(r+W[c],2*c,i and"p"or"P")e(r+W[c],2*c+1,i and"m"or"M")end i=o or y==a e(r-1,12,i and"b"or"B")e(r,12,i and(H>0 and"c"or"n")or"N")i=o or w==a e(r,13,i and(A and"z"or"s")or"S")end for ac=1,5 do e(2*ac+1,14,(o or h==ac)and"f"or"F")end return as(B)end function draw()local aa=string.format("GAME %s  BEST %d",m==1 and"A"or"B",l[m])snail.title((n and g~="menu")and"Sky Drop  "..aa or"Sky Drop")if g=="menu"then snail.row("Game A",E==1)snail.row("Game B (faster)",E==2)snail.gap()snail.text(string.format("Best: A %d   B %d",l[1],l[2]))snail.gap()snail.small("Row the boat under the parachutists before they hit the sea.")if n then snail.small("Row with the d-pad, or tap a lane.")else snail.small("LEFT and RIGHT row the boat.")end snail.small("Miss one and the shark gets him. Three and it's over.")snail.small("200 and 500 points clear your misses.")snail.hint("OK start BACK leave")return end if not n then snail.small(aa)end local G=J if u>0 then G="GAME "..(m==1 and"A"or"B")end if t then G="PAUSED"end if g=="over"then G=string.format("GAME OVER  %d%s",f,R and"  BEST!"or"")end snail.board(af(),nil,G)if g=="over"then snail.hint("OK menu BACK leave")elseif n then snail.hint("OK pause BACK leave")else snail.hint("L left R right OK pause BACK leave")end end function start()snail.ink("fast")local v=snail.load()if v then local k,x=v:match("(%d+),(%d+)")l={tonumber(k)or 0,tonumber(x)or 0}end end
