--!name Blip Football
--!icon game
--!category Games
local s=snail.touchscreen==true local an,af=14,s and 12 or 16 local U,ae=12,50 local ap={{4,1},{4,3},{6,2},{9,1},{11,3},{8,2}}local az={"1ST","2ND","3RD","4TH"}local ao=4 local am={}local aA={"..^!..","..++..","<++++>","=++++?","..++..","..~|.."}local l,S,m="menu",1,1 local p,j,C,w=0,0,1,ae local G,P,I=1,20,30 local f,r,u,A=2,2,16,{}local i,aj="huddle",false local x,Z,q,_=0,nil,0,nil local B,ag=false,false local v={0,0}local ad=1 local function M(Q)ad=(ad*1664525+1013904223)&0xFFFFFFFF return(ad>>16)%Q end local function aH()return m==1 and 800 or 650 end local function L()local aG=B or(x==0 and q==0 and i=="huddle")snail.tick(aG and 0 or aH())end local function aP()snail.save(v[1]..","..v[2])end local function y(T,Q,H)Z,q,_=T,Q,H L()end local function av()i,aj="huddle",false f,r,u=2,2,P-4 A={}for e=1,m==1 and 5 or 6 do A[e]={ap[e][1],ap[e][2]}end L()end local function ai(o)P,G,I=o,1,math.min(o+10,100)av()end local function aM()l,i="over","away"snail.tick(0)ag=p>v[m]if ag then v[m]=p aP()end end local function aL()if os and os.time then ad=os.time()%100000+11 end p,j,C,w=0,0,1,ae B,Z,q,_=false,nil,0,nil x=1 l="play"ai(20)end local function J(H)if w>0 then return H()end if C==4 then return aM()end C,w=C+1,ae y(C==3 and"HALFTIME"or"END OF QUARTER "..(C-1),2,H)end local function ak(aK)i="away"y("VISITORS' BALL",1,function()w=math.max(0,w-8-M(10))local ax=(m==1 and 25 or 35)+(80-aK)//2 local b,T,o=M(100),"VISITORS PUNT",10+2*M(11)if b<ax then j,T,o=j+7,"VISITORS TOUCHDOWN",20 elseif b<ax+20 then j,T,o=j+3,"VISITORS FIELD GOAL",20 end j=math.min(99,j)y(T,2,function()J(function()ai(o)end)end)end)end local function aS()i="dead"p=math.min(99,p+7)y("TOUCHDOWN",2,function()J(function()ak(80)end)end)end local function ay()i,aj="dead",true local k=u+2*f y(nil,1,function()if k<=0 then j=math.min(99,j+2)y("SAFETY",2,function()J(function()ak(60)end)end)elseif k>=I then y("FIRST DOWN",2,function()J(function()ai(k)end)end)elseif G==4 then y("TURNOVER ON DOWNS",2,function()J(function()ak(k)end)end)else G,P=G+1,k J(av)end end)end local function ah(a,d)for e,c in ipairs(A)do if c[1]==a and c[2]==d then return e end end end local function aT()u,f=u+20,f-10 for E,c in ipairs(A)do c[1]=c[1]-10 end for E,c in ipairs(A)do if c[1]<1 then local aJ=M(3)for e=0,8 do local a,d=U-e//3,(aJ+e)%3+1 if not ah(a,d)then c[1],c[2]=a,d break end end end end end local function ac(W,X)local a,d=f+W,r+X if d<1 or d>3 or a<1 or u+2*a<0 then return end f,r=a,d if f>U then aT()end if ah(f,r)then return ay()end if u+2*f>=100 then aS()end end local function aD(c)local W,X=f-c[1],r-c[2]local a,d=c[1],c[2]local aq=math.abs(W)if X~=0 and(aq<=1 or(aq<=3 and M(2)==0))then d=d+(X>0 and 1 or-1)else a=a+(W>0 and 1 or-1)end if ah(a,d)then return end c[1],c[2]=a,d if a==f and d==r then ay()end end function tick()if l~="play"or B then snail.tick(0)return end if x>0 then x=x-1 L()return end if q>0 then q=q-1 if q==0 then local H=_ Z,_=nil,nil H()end return end if i~="live"then L()return end w=math.max(0,w-1)local aN=m==1 and 45 or 55 for E,c in ipairs(A)do if i=="live"and M(100)<aN then aD(c)end end end function key(h)if h=="top"then return end if l=="menu"then if h=="up"or h=="down"then S=3-S elseif h=="ok"then m=S aL()end return end if l=="over"then if h=="ok"then l="menu"end return end if h=="ok"then B=not B L()return end if B or x>0 or q>0 then return end if i=="huddle"then i="live"L()end if i~="live"then return end if h=="left"then ac(-1,0)elseif h=="right"then ac(1,0)elseif h=="up"then ac(0,-1)elseif h=="down"then ac(0,1)end end local function aE(t,F)local b,a=F-af-1,t-1 if b<0 then return nil end local Y,au=2*(a-ao)-5,2*b-5 if Y>=-7 and Y<=7 then local as,at=math.abs(Y),math.abs(au)if as>at then return Y<0 and"left"or"right"end if at>as then return au<0 and"up"or"down"end return nil end for E,z in ipairs(am)do if a>=z[1]and a<=z[1]+1 then return z[3]end end end function touch(aI,t,F)if aI~="board"then return end if s then local h=aE(t,F)if h then return key(h)end else t=t-1 end local a,b=t-1,F-1 if l~="play"or b>6 or a<1 or a>U then return end local d=math.max(1,math.min(3,(b+1)//2))if d~=r then return key(d<r and"up"or"down")end if a~=f then return key(a<f and"left"or"right")end end local function aF()local n={}for b=1,6 do n[b]={}for a=1,an do n[b][a]="."end for e=1,6 do n[b][ao+e]=aA[b]:sub(e,e)end end for E,z in ipairs(am)do local aa,b,a=z[4]and"()[]"or"$&;:",z[2]+1,z[1]+1 n[b][a],n[b][a+1]=aa:sub(1,1),aa:sub(2,2)n[b+1][a],n[b+1][a+1]=aa:sub(3,3),aa:sub(4,4)end for b=1,6 do n[b]=table.concat(n[b])end return n end local function aQ(O)local R={}for b=0,af-1 do local D=table.concat(O[b])R[#R+1]=s and D or"."..D.."."end if s then for E,ab in ipairs(aF())do R[#R+1]=ab end end return table.concat(R,"/")end local function aB()local V=x>0 local O={}for b=0,af-1 do local ab={}for a=1,an do ab[a]="."end O[b]=ab end local function g(a,b,aC)O[b][a+1]=aC end local function K(a,b,Q,al)local D=V and("88"):sub(1,al)or string.format("%"..al.."d",math.max(0,math.min(Q,99))):gsub(" ","_")for e=1,al do g(a+e-1,b,D:sub(e,e))end end local k=u+2*f g(0,8,"D");K(1,8,G,1)g(11,8,"Y");K(12,8,I-k,2)g(0,10,"H");K(1,10,p,2)g(11,10,"V");K(12,10,j,2)g(0,11,"Q");K(1,11,C,1)g(11,11,"T");K(12,11,w,2)local ar=i=="away"for a=1,U do local o=u+2*a g(a,0,"w")g(a,6,(V or(not ar and(o==I or o==100)))and"n"or"m")g(a,2,"k")g(a,4,"k")for d=1,3 do g(a,2*d-1,V and"t"or"g")end end if not V and not ar then for E,c in ipairs(A)do g(c[1],2*c[2]-1,"x")end g(f,2*r-1,aj and"t"or"r")end return aQ(O)end local function aR(k)if k==50 then return"50"end return(k<50 and"OWN "or"OPP ")..(k<50 and k or 100-k)end function draw()local aw=string.format("GAME %s  BEST %d",m==1 and"A"or"B",v[m])snail.title((s and l~="menu")and"Blip Football  "..aw or"Blip Football")if l=="menu"then snail.row("Game A",S==1)snail.row("Game B (six faster defenders)",S==2)snail.gap()snail.text(string.format("Best: A %d   B %d",v[1],v[2]))snail.gap()snail.small("Run the ball past the defenders. Ten yards in four downs")snail.small("is a first down; the goal line is a touchdown, 7 points.")if s then snail.small("Run with the d-pad, or tap the field beside the runner.")else snail.small("RIGHT runs upfield, LEFT back; the side keys UP and")snail.small("DOWN change lanes.")end snail.small("Arrows under the field mark the first down and the goal line.")snail.small("Four quarters; the clock runs while the ball is live.")snail.hint("OK start BACK leave")return end if not s then snail.small(aw)end local N=Z if i=="huddle"and q==0 then N=az[G].." & "..(I>=100 and"GOAL"or tostring(I-P)).."  "..aR(P)end if x>0 then N="GAME "..(m==1 and"A"or"B")end if B then N="PAUSED"end if l=="over"then local aO=p>j and"WIN"or(p<j and"LOSS"or"TIE")N=string.format("FINAL %d-%d %s%s",p,j,aO,ag and"  BEST!"or"")end snail.board(aB(),nil,N)if l=="over"then snail.hint("OK menu BACK leave")elseif s then snail.hint("OK pause BACK leave")else snail.hint("L R run OK pause BACK leave")end end function start()snail.ink("fast")local D=snail.load()if D then local t,F=D:match("(%d+),(%d+)")v={tonumber(t)or 0,tonumber(F)or 0}end end
