Log In  

Cart #minsnakegame-3 | 2022-04-29 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1


An attempt at size-optimizing the classic game of snake.
The final code was 416 in characters.

m={}x=3y=2r=1c=0o=0d=2^7f=flip
l=3w=16h=w::_::cls()for i=1,w*h do
m[i]=m[i]or 0if(m[i]>0)m[i]-=1
if(o)k=flr(rnd(w*h-l))+1o=nil
if(m[i]==0)k-=1m[i]=(k==0)and -8/3 or 0
p=(i%w)*d/w
q=flr((i-1)/h)*d/h
rect(p,q,p+d/w-1,q+d/h-1,3*min(m[i],1))?l-3,0,0,7
end
b=btn()t=(b&2)/2-(b&1)if(t~=0)r,c=t,0
t=(b&8)/8-(b&4)/4if(t~=0)c,r=t,0
x,y=(x+r)%w,(y+c)%h
n=x+w*y+1if(m[n]<0)l+=1o=0
if(m[n]<=0)m[n]=l f()f()f()goto _
?"game over"

Here is the commented version.

Cart #minsnakegame_commented-0 | 2022-04-29 | Code ▽ | Embed ▽ | No License
1


Feel free to post any suggestions!

P#111066 2022-04-29 17:47


[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 10:09:40 | 0.010s | Q:18