JS1K

#2: the original

Source description for demo by Mathieu 'p01' Henri.

// the usual suspects // A is also used a keydown map // B is also used as player/entities collection A=document.body.children.c;B=A.getContext('2d'); // the keydown method is also the collision detection with the map // the map is actually a 32x32 ( 1024 ;) ) square using the charCode & 19 of uncompressed JS code % 73 // NOTE: Make sure to set _ if you want to try the uncompressed version onkeydown=function(x,y){A[x.which]=1;x|=y<<5;return(x&31)*(x&480)*(_.charCodeAt(x++%73)&19)?1:0}; // clear the keyboard mapping ( aka A ), set the keyup method for(n=A.width,i=0;n--;B[n]=[1.1,1.1,1.1,A[n]=0])onkeyup=function(x,y){A[x.which]=0}; // D is the array of wall slices raycasted + entities on screen D=[setInterval(function(x,y) { // update the width & height of the canvas to fit the window A.width=innerWidth-20;A.height=A.width/2; // raycast the walls for(n=A.width,i=0;n--;D[n]=[t,n,S,8+(S+x*9&8)|(X+y+t*s+t*c)*8&7]) { w=X=x=B[i][0];v=y=B[i][1]; z=B[i][2]; x|=y<<5; b=z+n/A.width-.5, a=s=Math.sin(b),d=y%=1; u=a<0?-a:a,F=(a<0?d:1-d)/u; G=F,r=u; a=c=Math.cos(b),d=X%=1; u=a<0?-a:a,F=(a<0?d:1-d)/u; for(;onkeydown(x);)F<G?(t=F,F+=1/u,x+=S=c/u):(t=G,G+=1/r,x+=S=32*s/r) } // process the entities for(n=A.width,i=0;i<15;i++) { // move b=B[i][2]; j=38; t=i?1:A[j]-A[j+2]; X=B[i][0]+=onkeydown(B[i][0]+Math.cos(b)*t/8,B[i][1])*Math.cos(b)*t/8; Y=B[i][1]+=onkeydown(B[i][0],B[i][1]+Math.sin(b)*t/8)*Math.sin(b)*t/8; // turn j--; t=i?Math.random()*8-4:A[j]-A[j+2]; B[i][2]=(b-1*t/16+9.42%6.28)-3.14; // angle relative to the player b=z-Math.atan2(Y-=v,X-=w); i&&Math.cos(b)>.5?D[n]=[Math.sqrt(X*X+Y*Y),A.width/2-A.width*b,i,0,++n]:0 } // sorted the array of slices & entities and render them for(D.sort(function(x,y){return+x[0]-y[0]});n--;) for(a=D[n][1],b=a/A.width-.5,F=A.width/2/Math.cos(b)/D[n][b=0],c=8,u=v=F/4+1,x=D[n][3],x?B.fillRect(a,b,u=c=1,A.width,B.fillStyle='hsl('+D[n][2]+'1,99%,0%)'):a-=F;c--;a+=F/4) for(B.fillStyle='hsl('+D[n][2]+'1,99%,'+v+'%)',d=atob('CBF+/p6f9AC9bsP/w/dqvdvb2NvD29sb').charCodeAt(x++%73),y=8,b=A.width/4,b-=F;y--;b+=F/4) d>>y&1?B.fillRect(a,b,u,v):0 },9)]