--!name Egg Catch
--!icon game
--!category Games
local p=snail.touchscreen==true local z,G=14,17 local af={{5,7},{5,14},{8,7},{8,14}}local ad={{2,1,0},{11,12,13}}local V=4 local U={}local ae={"..^!..","..++..","<++++>","=++++?","..++..","..~|.."}local h,F="menu",1 local t={}local w,f,u=1,0,0 local o,C,I,x=0,0,0,0 local v,m,K,A,T=false,1,nil,0,false local l={0,0}local N=1 local function ab(an)N=(N*1664525+1013904223)&0xFFFFFFFF return(N>>16)%an end local function Y(c,b)local ac=(c==1 or c==3)and 1 or 8 if c<=2 then return b-1,ac+b end return z-b,ac+b end local function S()if m==1 then return math.max(500,900-f*2)end return math.max(450,650-f)end local function ar()if m==1 then return math.min(80,40+f//4)end return math.min(90,60+f//5)end local function aq()snail.save(l[1]..","..l[2])end local function ao()if os and os.time then N=os.time()%100000+11 end for c=1,4 do t[c]={false,false,false,false,false}end w,f,u=1,0,0 o,C,I,x=0,0,0,1 v,K,A=false,nil,0 h="play"snail.tick(S())end local function ap()h="over"snail.tick(0)T=f>l[m]if T then l[m]=f aq()end end local function ah()f=math.min(9999,f+1)I=1 if(f==200 or f==500)and u>0 then u=0 K,A="BONUS  misses cleared",2 end snail.tick(S())end local function am(c)u=u+1 C=c<=2 and 1 or 2 o=3 end function tick()if h~="play"or v then snail.tick(0)return end I=0 if x>0 then x=x-1 return end if A>0 then A=A-1 if A==0 then K=nil end end if o>0 then o=o-1 if o==0 then C=0 if u>=3 then ap()end end return end for c=1,4 do if t[c][5]then t[c][5]=false if w==c then ah()else am(c)end end end if o>0 then return end for c=1,4 do local R=t[c]for b=5,2,-1 do R[b]=R[b-1]end R[1]=false end if ab(100)<ar()then t[ab(4)+1][1]=true end end local function D(j,P)if h~="play"or v or x>0 then return end w=(j-1)*2+(P and 1 or 2)end function key(g)if h=="menu"then if g=="up"or g=="down"then F=3-F elseif g=="ok"then m=F ao()end return end if h=="over"then if g=="ok"then h="menu"end return end if g=="ok"then v=not v snail.tick(v and 0 or S())return end local j,P=w<=2 and 1 or 2,w%2==1 if g=="left"then D(1,P)elseif g=="right"then D(2,P)elseif g=="up"then D(j,true)elseif g=="down"then D(j,false)end end local function ai(k,r)local a,d=r-G-1,k-1 if a<0 then return nil end local J,Z=2*(d-V)-5,2*a-5 if J>=-7 and J<=7 then local W,X=math.abs(J),math.abs(Z)if W>X then return J<0 and"left"or"right"end if X>W then return Z<0 and"up"or"down"end return nil end for Q,s in ipairs(U)do if d>=s[1]and d<=s[1]+1 then return s[3]end end end function touch(ak,k,r)if ak~="board"then return end if p then local g=ai(k,r)if g then return key(g)end else k=k-1 end if r<=G then D(k<=z//2 and 1 or 2,r<=9)end end local function aj()local i={}for a=1,6 do i[a]={}for d=1,z do i[a][d]="."end for b=1,6 do i[a][V+b]=ae[a]:sub(b,b)end end for Q,s in ipairs(U)do local L,a,d=s[4]and"()[]"or"$&;:",s[2]+1,s[1]+1 i[a][d],i[a][d+1]=L:sub(1,1),L:sub(2,2)i[a+1][d],i[a+1][d+1]=L:sub(3,3),L:sub(4,4)end for a=1,6 do i[a]=table.concat(i[a])end return i end local function as(B)local E={}for a=0,G-1 do local y=table.concat(B[a])E[#E+1]=p and y or"."..y.."."end if p then for Q,M in ipairs(aj())do E[#E+1]=M end end return table.concat(E,"/")end local function ag()local q=x>0 local B={}for a=0,G-1 do local M={}for d=1,z do M[d]="."end B[a]=M end local function e(d,a,c)B[a][d+1]=c end local y=q and"8888"or string.format("%4d",f):gsub(" ","_")for b=1,4 do e(b-1,0,y:sub(b,b))end for b=1,3 do e(10+b,0,(q or u>=b)and"k"or"K")end for c=1,4 do local Q,a=Y(c,1)local aa=not q and t[c][1]if c<=2 then e(0,a-1,aa and"i"or"h")else e(z-1,a-1,aa and"y"or"j")end end for c=1,4 do local al=c<=2 for b=1,5 do local d,a=Y(c,b)local n=q or t[c][b]e(d,a,al and(n and"e"or"E")or(n and"f"or"F"))end end for a=7,15 do e(6,a,"l");e(7,a,"l")end e(5,9,"p");e(8,9,"q")for d=0,z-1 do e(d,16,"g")end for b,O in ipairs(af)do local n=q or w==b e(O[1],O[2],n and((I>0 and w==b)and"c"or"a")or"A")e(O[1],O[2]+1,n and"b"or"B")end for j=1,2 do e(j==1 and 3 or 10,15,(q or C==j)and"s"or"S")local at=C==j and 4-o or 0 for b,d in ipairs(ad[j])do local n=q or at==b e(d,15,j==1 and(n and"k"or"K")or(n and"m"or"M"))end end return as(B)end function draw()local _=string.format("GAME %s  BEST %d",m==1 and"A"or"B",l[m])snail.title((p and h~="menu")and"Egg Catch  ".._ or"Egg Catch")if h=="menu"then snail.row("Game A",F==1)snail.row("Game B (faster)",F==2)snail.gap()snail.text(string.format("Best: A %d   B %d",l[1],l[2]))snail.gap()snail.small("Catch the eggs as they roll off the four chutes.")if p then snail.small("Tap a corner of the screen or use the d-pad")snail.small("under it to climb to a spot.")else snail.small("LEFT and RIGHT cross over, UP and DOWN climb.")end snail.small("Three broken eggs and it's over. 200 and 500")snail.small("points clear your misses.")snail.hint("OK start BACK leave")return end if not p then snail.small(_)end local H=K if x>0 then H="GAME "..(m==1 and"A"or"B")end if v then H="PAUSED"end if h=="over"then H=string.format("GAME OVER  %d%s",f,T and"  BEST!"or"")end snail.board(ag(),nil,H)if h=="over"then snail.hint("OK menu BACK leave")elseif p 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 y=snail.load()if y then local k,r=y:match("(%d+),(%d+)")l={tonumber(k)or 0,tonumber(r)or 0}end end
