--!name Highway Dash
--!icon game
--!category Games
local j,aq,ab=24,32,6 local i=aq-ab local M=0.45 local O,ao=10,1.1 local L=250 local N=24 local P=40 local ap={[0]="g","A","E","F","C",".","L","M","H","J","b","b","I","K","w","w",}local ac="..uzv....uv.....uzzv...."local x={big={"PQRS","TUVX"},mid={"mn"},small={"c"}}local t,D={},{}for a=0,i-1 do local ai=(a+1)/i t[a]=2.5/ai-2.5 D[a]=9*ai+0.15 end local E=t[0]local k="menu"local g,f,e,p=0,0,0,60 local y,n,v,J=0,0,0,nil local o,w,u,W=false,L,0,false local S,z={},{}local K=1 local function B(V)K=(K*1664525+1013904223)&0xFFFFFFFF return(K>>16)%V end local function af(an)local d=an//P local ag=(an%P)/P local q=S[d%#S+1]local aC=math.min(1,ag/0.2,(1-ag)/0.2)return q*aC end local function Y(b,at)b.z=g+at b.x=(B(3)-1)*0.6 b.v=4+B(4)b.dz=b.z-g end local function ah()if os and os.time then K=os.time()%100000+7 end local aj={0,0,0,1,-1,1.5,-1.5,2,-2,0.8,-0.8}for c=1,120 do S[c]=c<=2 and 0 or aj[B(#aj)+1]end g,f,e,p=0,2,0,60 y,n,v,J=0,0,0,nil o,w,W=false,L,false for c=1,5 do z[c]=z[c]or{}Y(z[c],25+c*14)end k="race"snail.tick(450)end local function aG()snail.save(string.format("%d",math.floor(u*100+0.5)))end local function al(h,V)J,v=h,V end local function I()return g*N/3600 end local function ay()k="over"snail.tick(0)if I()>u then u,W=I(),true aG()end end function tick()if k~="race"or o then snail.tick(0)return end if v>0 then v=v-1 if v==0 then J=nil end end local q=af(g+2)if n>0 then n=n-1 f=0 else local _=math.abs(e)>1.05 and 3 or O if f<_ then f=math.min(_,f+ao)else f=math.max(_,f-2.5)end e=e-q*f/O*0.15 if e<-2 then e=-2 elseif e>2 then e=2 end end g=g+f*M y=y+q*f*0.04 for ar,b in ipairs(z)do b.z=b.z+b.v*M local l=b.z-g if n==0 and b.dz>-0.2 and l<0.5 and math.abs(b.x-e)<0.5 then n,f=4,0 Y(b,E+B(20))l=b.dz al("CRASH!",3)end b.dz=l if l<-3 or l>E+20 then Y(b,E+B(20))end end p=p-M if g>=w then w=w+L p=p+30 al("CHECKPOINT  +30s",3)end if p<=0 then p=0 ay()end end local function Z(H)if n==0 then e=e+H*0.2 if e<-2 then e=-2 elseif e>2 then e=2 end end end function key(d)if k=="menu"then if d=="ok"or d=="up"then ah()end return end if k=="over"then if d=="ok"then ah()elseif d=="up"or d=="down"then k="menu"end return end if d=="ok"then o=not o snail.tick(o and 0 or 450)return end if o then return end if d=="left"then Z(-1)return true end if d=="right"then Z(1)return true end if d=="down"then f=math.max(0,f-2)return true end if d=="up"then if n==0 then f=math.min(O+2,f+1)end return true end end function touch(aB,as,aI)if k~="race"or o or aB~="board"then return end Z(as<=j//2 and-1 or 1)return true end local function aE()local m,A={},{}local aa,T=0,0 for a=i-1,0,-1 do T=T+af(g+t[a])*0.012 aa=aa+T A[a]=j/2+aa-e*D[a]end local ae=-1 local ax=w-g for a=i-1,0,-1 do if t[a]>=ax then ae=a break end end for a=0,i-1 do local U,q=D[a],A[a]local aF=U*0.14+0.2 local ad=((g+t[a])//2)%2 local aD=2+ad local C={}for r=0,j-1 do local d=0 for az=0,1 do local H=math.abs(r+0.25+az*0.5-q)local aw=H<U and 1 or(H<U+aF and aD or 0)d=d*4+aw end local G=ap[d]if G=="."then if a==ae then G="x"elseif ad==0 and a>4 and math.abs(r+0.5-q)<0.5 then G="l"end end C[r+1]=G end m[a]=C end return m,A end local function X(m,a,r,h)local C=m[a]if not C then return end for c=1,#h do local R=r+c if R>=1 and R<=j then C[R]=h:sub(c,c)end end end local function au()local m,A=aE()for ar,b in ipairs(z)do local l=b.dz if l>0.5 and l<E then local a=0 for c=i-1,0,-1 do if t[c]>=l then a=c break end end local r=A[a]+b.x*D[a]local F=a>=i-8 and x.big or(a>=i-15 and x.mid or x.small)local aH=#F[1]local av=math.floor(r-aH/2+0.5)for c=1,#F do X(m,a-#F+c,av,F[c])end end end X(m,i-2,j//2-2,x.big[1])X(m,i-1,j//2-2,x.big[2])local s={}local am=math.floor(17-y)%j for a=0,ab-2 do local h=string.rep(".",j)if a==1 then h=h:sub(1,am).."*"..h:sub(am+2)end s[#s+1]=h:sub(1,j)end local ak=math.floor(y)%j s[#s+1]=(ac:sub(ak+1)..ac:sub(1,ak))for a=0,i-1 do s[#s+1]=table.concat(m[a])end return table.concat(s,"/")end local function aA()return string.format("%ds   %d km/h   %.1f km   next %.1f km",math.ceil(p),math.floor(f*N+0.5),I(),(w-g)*N/3600)end function draw()snail.title("Highway Dash")if k=="menu"then snail.row("Start race",true)snail.gap()snail.text(u>0 and string.format("Best distance: %.1f km",u)or"No race yet.")snail.gap()snail.small("Tap or hold the left or right half of the road to steer.")snail.small("DOWN brakes, UP gives a burst of speed, OK pauses.")snail.small("Bends push you outward, so steer into them.")snail.small("Grass slows you down and cars stop you dead.")snail.small("Each checkpoint adds 30 seconds to the clock.")snail.hint("OK start BACK leave")return end snail.small(aA())local Q=J if o then Q="PAUSED"end if k=="over"then Q=string.format("TIME UP  %.1f km%s",I(),W and"  NEW BEST!"or"")end snail.board(au(),nil,Q)if k=="over"then snail.hint("OK race BACK leave")else snail.hint("L left R right OK pause BACK leave")end end function start()snail.ink("fast")local h=snail.load()u=(h and tonumber(h)or 0)/100 end
