--!name Lane Racer
--!icon game
--!category Games
local p=snail.touchscreen==true local R,z=14,17 local A=7 local S=4 local Q={}local _={"..^!..","..++..","<++++>","=++++?","..++..","..~|.."}local g,G="menu",1 local s={}local i,f,o,C,E=2,0,3,0,0 local l,v=0,0 local u,t,J,y,P=false,1,nil,0,false local n={0,0}local M=1 local function K(af)M=(M*1664525+1013904223)&0xFFFFFFFF return(M>>16)%af end local function O()if t==1 then return math.max(500,900-f*5)end return math.max(450,650-f*3)end local function aj()snail.save(n[1]..","..n[2])end local function X()for d=1,3 do s[d]={}for c=1,A do s[d][c]=false end end E=0 end local function ag()if os and os.time then M=os.time()%100000+11 end X()i,f,o,C=2,0,3,0 l,v=0,1 u,J,y=false,nil,0 g="play"snail.tick(O())end local function ah()g="over"snail.tick(0)P=f>n[t]if P then n[t]=f aj()end end local function ai()f=math.min(999,f+1)if f%50==0 and o<3 then o=o+1 J,y="BONUS  extra car",2 end snail.tick(O())end local function ak()E=E+1 if E<(f<30 and 2 or 1)then return end if K(100)>=math.min(85,55+f)then return end local d=K(3)+1 s[d][1]=true if K(100)<math.min(35,f)then s[(d+K(2))%3+1][1]=true end E=0 end function tick()if g~="play"or u then snail.tick(0)return end if v>0 then v=v-1 return end if y>0 then y=y-1 if y==0 then J=nil end end if l>0 then l=l-1 if l==0 then X()if o==0 then ah()end end return end if s[i][A]then o=o-1 l=4 return end for d=1,3 do local b=s[d]if b[A]then ai()end for c=A,2,-1 do b[c]=b[c-1]end b[1]=false end C=C+1 ak()end local function N(d)if g~="play"or u or v>0 or l>0 then return end i=math.max(1,math.min(3,d))end function key(h)if g=="menu"then if h=="up"or h=="down"then G=3-G elseif h=="ok"then t=G ag()end return end if g=="over"then if h=="ok"then g="menu"end return end if h=="ok"then u=not u snail.tick(u and 0 or O())return end if h=="left"then N(i-1)elseif h=="right"then N(i+1)end end local function ac(m,q)local a,b=q-z-1,m-1 if a<0 then return nil end local H,Y=2*(b-S)-5,2*a-5 if H>=-7 and H<=7 then local U,V=math.abs(H),math.abs(Y)if U>V then return H<0 and"left"or"right"end if V>U then return Y<0 and"up"or"down"end return nil end for T,r in ipairs(Q)do if b>=r[1]and b<=r[1]+1 then return r[3]end end end function touch(ae,m,q)if ae~="board"then return end if p then local h=ac(m,q)if h then return key(h)end else m=m-1 end local b=m-1 if q>1 and q<=z then if b<3*i then N(i-1)elseif b>3*i+1 then N(i+1)end end end local function ad()local k={}for a=1,6 do k[a]={}for b=1,R do k[a][b]="."end for c=1,6 do k[a][S+c]=_[a]:sub(c,c)end end for T,r in ipairs(Q)do local e,a,b=r[4]and"()[]"or"$&;:",r[2]+1,r[1]+1 k[a][b],k[a][b+1]=e:sub(1,1),e:sub(2,2)k[a+1][b],k[a+1][b+1]=e:sub(3,3),e:sub(4,4)end for a=1,6 do k[a]=table.concat(k[a])end return k end local function al(D)local F={}for a=0,z-1 do local w=table.concat(D[a])F[#F+1]=p and w or"."..w.."."end if p then for T,L in ipairs(ad())do F[#F+1]=L end end return table.concat(F,"/")end local function aa()local x=v>0 local D={}for a=0,z-1 do local L={}for b=1,R do L[b]="."end D[a]=L end local function j(b,a,ab)D[a][b+1]=ab end local function W(b,a,I,e)j(b,a,I and e:sub(1,1)or e:sub(1,1):upper())j(b+1,a,I and e:sub(2,2)or e:sub(2,2):upper())j(b,a+1,I and e:sub(3,3)or e:sub(3,3):upper())j(b+1,a+1,I and e:sub(4,4)or e:sub(4,4):upper())end local w=x and"888"or string.format("%3d",f):gsub(" ","_")for c=1,3 do j(c-1,0,w:sub(c,c))end j(13,0,x and"8"or tostring(o))for a=1,z-1 do j(2,a,"e");j(11,a,"e")j(0,a,(x or(a-C)%3==0)and"t"or"T")j(13,a,(x or(a-C)%3==1)and"t"or"T")end for d=1,3 do for c=1,A do W(3*d,2*c-1,x or s[d][c],"abcd")end W(3*d,15,x or(i==d and l%2==0),"pqrs")end return al(D)end function draw()local Z=string.format("GAME %s  BEST %d",t==1 and"A"or"B",n[t])snail.title((p and g~="menu")and"Lane Racer  "..Z or"Lane Racer")if g=="menu"then snail.row("Game A",G==1)snail.row("Game B (faster)",G==2)snail.gap()snail.text(string.format("Best: A %d   B %d",n[1],n[2]))snail.gap()snail.small("Dodge the oncoming cars coming down the three lanes.")if p then snail.small("Steer with the d-pad under the screen, or tap the")snail.small("road beside your car.")else snail.small("LEFT and RIGHT change lanes.")end snail.small("Each car you pass scores. Three crashes and it's over;")snail.small("every 50 points wins back a car. Top right: cars left.")snail.hint("OK start BACK leave")return end if not p then snail.small(Z)end local B=J if l>0 then B="CRASH!"end if v>0 then B="GAME "..(t==1 and"A"or"B")end if u then B="PAUSED"end if g=="over"then B=string.format("GAME OVER  %d%s",f,P and"  BEST!"or"")end snail.board(aa(),nil,B)if g=="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 w=snail.load()if w then local m,q=w:match("(%d+),(%d+)")n={tonumber(m)or 0,tonumber(q)or 0}end end
