Advertisement
Guest User

Untitled

a guest
Dec 11th, 2020
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. s=[l={x:20,y:20}],v=1,h=t=0,focus(),(D=document).body.append(w=D.createElement`canvas`),w.width=w.height=50,w.style.width=w.style.height="300px",w.style.border="6px solid",c=w.getContext`2d`,onkeydown=b=>{f={d:[0,1],a:[0,-1],w:[-1,0],s:[1,0]}[b.key],f?(v=f[0],h=f[1]):0},k=(o,a,b,d,e)=>{c.fillStyle=e,c.fillRect(o,a,b,d,e)},m=()=>{g=4,i=0|48*(R=Math.random)()+1,j=0|48*R()+1,s.map(b=>{b.x==i&&b.y==j?m():0})},m(),z=setInterval(()=>{k(0,0,80,80,"#fff"),s.push(l={x:l.x+h,y:l.y+v}),s.splice(0,0>g--),l.x==i&&l.y==j?(m(),t++):0,s.map(b=>{z&&(0>l.x||0>l.y||49<l.x||49<l.y||b!=l&&b.x==l.x&&b.y==l.y)?(clearInterval(z),z=alert("Score:"+t)):k(b.x,b.y,1,1,"#000")}),k(i,j,1,1,"#f0f")},75)
Advertisement
RAW Paste Data Copied
Advertisement