forked from venam/js13k-Reverse-Car
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.min.js
22 lines (22 loc) · 10.9 KB
/
main.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var b=!0,g=!1,h={};addEventListener("keydown",function(a){h[a.keyCode]=b},g);addEventListener("keyup",function(a){delete h[a.keyCode]},g);
var l,n,q,r=[],t,u=[],v=0,y=0,z=70,A=0,C=0,D=0,E=0,F=0,G=new Audio("data:audio/wav;base64,UklGRoYIAABXQVZFZm10IBAAAAABAAEAiBUAAIgVAAABAAgAZGF0YWIIAABGPBA+O1+00dD//92qtl2bsz5wOgAAEyg7iXZui4FytMjMzeDm2dbTsLB3bFAnJ2pul7+/0tXQYmIRAAAuhIT/396hoaGRVVVhUk5dY1hVZmZRR0lQUFhbWTAwP29zxbipeHdwgoKThYV0b29xhYeRbFFAKIOD7ryoiFRmZnWGnp6/rZORZXCHh6ancnFOOlVzeKurzdvq///YwKt1dW1ZWT89PS8kIAwMDDyLj//////LrZJRUVFRX3x8o6alpaWUSEgACFpavsa+vnl8oVe1g2x7XIKMTmSDa6q0UVFaRqzHwsza2dHQy0hIcoiWo6NDQD0wMGmJrHh4R4CA///+1L2viIiJm6iqurV7e4B+q9rYr6+TkJJnZxMAABMTRoeIyr+2sLO8fXhIm5/q/Pvthm41AAAAACIiSWVrenpGRgk+a4fTxsG6sKqopaF3XkkdNGhptLSloZiOi0xMGgoOSUl6h4dvaFhJSVuoqP7//+6Xly4oKChGSV5zhoehf2xZNlxjfZCOjoyMlZedor3O3fv15OTOzMCkVmEkNX90f4qKgW5wZl5XW19ifMLCrKmdn6WMmqea1N3Z1dq8epaZnPDx5OPa24JpdoCGh4IODiExS5CQgmxNTEyku9LLyq2pqp2Lfmdoaqy66LOhYm17oJqFb0g9Oy04OEE7NjIrRUZcbIGFobC+xtvbzo+PR0VGaH6UinlbLSkdPEpoaFlILCYjL4mJ+OPfzqh0ZyR2i8rrubmEg4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1,R=579-L;function S(a,c){return Math.floor(Math.random()*(c-a+1)+a)}
function T(a,c,f,d,k){for(var e=0;e<a.length;e++)switch(a[e][0]){case "cr":if(!(c>a[e][1]+N||d<a[e][1]||f>a[e][2]+M||k<a[e][2]))return g;break;case "cl":if(!(c>a[e][1]+N||d<a[e][1]||f>a[e][2]+M||k<a[e][2]))return g;break;case "cu":if(!(c>a[e][1]+M||d<a[e][1]||f>a[e][2]+N||k<a[e][2]))return g;break;case "cd":if(!(c>a[e][1]+M||d<a[e][1]||f>a[e][2]+N||k<a[e][2]))return g;break;case "o":if(!(c>a[e][1]+O||d<a[e][1]||f>a[e][2]+O||k<a[e][2]))return g;break;case "w":if(!(c>a[e][1]+L||d<a[e][1]||f>a[e][2]+
L||k<a[e][2]))return g}return b}
function V(a,c,f){for(var d=0;d<a.length;d++)switch(a[d][0]){case "w":if(c>=a[d][1]&&c<=a[d][1]+L&&f>=a[d][2]&&f<=a[d][2]+L)return b;break;case "o":if(c>=a[d][1]&&c<=a[d][1]+O&&f>=a[d][2]&&f<=a[d][2]+O)return b;break;case "cu":if(c>=a[d][1]&&c<=a[d][1]+M&&f>=a[d][2]&&f<=a[d][2]+N)return b;break;case "cd":if(c>=a[d][1]&&c<=a[d][1]+M&&f>=a[d][2]&&f<=a[d][2]+N)return b;break;case "cr":if(c>=a[d][1]&&c<=a[d][1]+N&&f>=a[d][2]&&f<=a[d][2]+M)return b;break;case "cl":if(c>=a[d][1]&&c<=a[d][1]+N&&f>=a[d][2]&&
f<=a[d][2]+M)return b}return g}
function W(){l=document.getElementById("game").firstElementChild;n=l.getContext("2d");q=0;r=[];H=[];var a=r,c=H;I=1E3;var f,d;f=S(1,4);d=S(4,25);c.push(f);c.push(d);for(c=0;30>c;c++)if(c>=d&&c<d+3)switch(f){case 1:a.push(["w",c*L,610-L]);a.push(["w",0,c*L]);a.push(["w",610-L,c*L]);break;case 2:a.push(["w",c*L,0]);a.push(["w",0,c*L]);a.push(["w",610-L,c*L]);break;case 3:a.push(["w",c*L,0]);a.push(["w",c*L,610-L]);a.push(["w",610-L,c*L]);break;case 4:a.push(["w",c*L,0]),a.push(["w",c*L,610-L]),a.push(["w",
0,c*L])}else a.push(["w",c*L,0]),a.push(["w",c*L,610-L]),a.push(["w",0,c*L]),a.push(["w",610-L,c*L]);a:{f=S(1,3);for(var k,c=d=0;c<f;c++){var e=0,m=0,p=0,w=0,x=S(2,5),B=S(1,2);if(1==S(0,1)){for(;!T(a,e-30-N,m-30-N,p+30+N,w+30+N);){I--;if(0==I){W();break a}e=S(P,R);m=S(P,R);p=e+M*x+15*(x-1);w=m+N*B+15*(B-1)}w=e;0==c&&(k=S(0,x-1),2==B&&(d=S(0,1)));for(j=0;j<B;j++){for(var s=0;s<x;s++)s==k&&j==d&&0==c?a.push(["pv",e,m]):(p=0==j?"cd":"cu",a.push([p,e,m])),e+=M+15;e=w;m+=N+15}}else{for(;!T(a,e-30-N,m-
30-N,p+30+N,w+30+N);){I--;if(0==I){W();break a}e=S(P,R);m=S(P,R);p=e+N*B+15*(B-1);w=m+M*x+15*(x-1)}0==c&&(k=S(0,x-1),2==B&&(d=S(0,1)));w=m;for(j=0;j<B;j++){for(s=0;s<x;s++)s==k&&j==d&&0==c?a.push(["ph",e,m]):(p=0==j?"cr":"cl",a.push([p,e,m])),m+=M+15;m=w;e+=N+15}}}for(s=0;s<a.length;s++)if("ph"==a[s][0]||"pv"==a[s][0])K=s}a:{c=d=f=k=0;e=S(10,20);for(m=0;m<e;m++){for(;!T(a,k-30-N,f-30-N,d+30+N,c+30+N);){I--;if(0==I){W();break a}k=S(P,R);f=S(P,R);d=k+O;c=f+O}a.push(["o",k,f])}}t=F=E=0;for(var J in"Reverse Parking")u.push("Reverse Parking"[J]),
u.push(30*J+75),u.push(2*Math.random()-1),u.push(0.5<Math.random());switch(H[0]){case 1:A=Math.floor((H[1]+1.5)*L);D=C=0;break;case 2:A=Math.floor((H[1]+1.5)*L);C=610;D=Math.PI;break;case 3:A=-M/2;C=Math.floor((H[1]+1.5)*L)+M/2;D=-Math.PI/2;break;case 4:A=610-M/2,C=Math.floor((H[1]+1.5)*L)+M/2,D=Math.PI/2}}
function X(a,c,f,d,k){n.translate(a+10,c);n.rotate(f);n.translate(-10,0);n.fillStyle="#000000";n.translate(0,10);n.rotate(30*-d);n.translate(-3,-20/3);n.fillRect(0,0,20/3,20/1.5);n.translate(3,20/3);n.rotate(30*d);n.translate(0,-10);n.translate(20,10);n.rotate(30*-d);n.translate(-4,-20/3);n.fillRect(0,0,20/3,20/1.5);n.translate(4,20/3);n.rotate(30*d);n.translate(-20,-10);n.fillRect(-2,26,20/3,20/1.8);n.fillRect(20-20/3+2,26,20/3,20/1.8);d=n.createLinearGradient(0,0,0,20);d.addColorStop(0,k?"#FAD8B0":
"#B0F8AF");d.addColorStop(1,k?"#BF3819":"#1938BF");n.fillStyle=d;n.fillRect(0,0,20,40);n.fillStyle="#1F3351";n.beginPath();n.moveTo(4,40/3+1);n.quadraticCurveTo(10,40/3-20/6,16,40/3+1);n.lineTo(15,23);n.quadraticCurveTo(10,15,5,23);n.fill();n.beginPath();n.moveTo(20/7,17);n.lineTo(20/7,34);n.quadraticCurveTo(20/3.5,32,20/7,17);n.fill();n.beginPath();n.moveTo(20-20/7,17);n.lineTo(20-20/7,34);n.quadraticCurveTo(20-20/3.5,32,20-20/7,17);n.fill();n.fillRect(20/5.5,36,20-2*(20/5.5),20/7);n.translate(10,
0);n.rotate(-f);n.translate(-a-10,-c)}function Y(a,c,f){n.strokeStyle="#F8F596";n.fillStyle=n.strokeStyle;f?n.strokeRect(a,c,M,N):n.strokeRect(a,c,N,M);n.font="12px monospace";f?n.fillText("P",a+M/2-4,c+N/2+3):n.fillText("P",a+N/2-3,c+M/2+3)}
function Z(){if(0==q){y++;var a=r,c=C,f=D,d,k,e,m,p,w,x,B,s,J,U,Q;Q=A+M/2;d=Math.floor(Q-M/2*Math.cos(f));k=Math.floor(c+Math.sin(f)*M/2);e=Math.floor(Q+M/2*Math.cos(f));m=Math.floor(c-Math.sin(f)*M/2);w=Math.floor(Q-M/2*Math.cos(f)-N*Math.sin(f));x=Math.floor(c+M/2*Math.sin(f)+N*Math.cos(f));p=Math.floor(Q+M/2*Math.cos(f)-N*Math.sin(f));f=Math.floor(c-M/2*Math.sin(f)+N*Math.cos(f));B=(e+p)/2;s=(m+f)/2;J=(d+w)/2;U=(k+x)/2;if(V(a,Q,c)||V(a,d,k)||V(a,e,m)||V(a,w,x)||V(a,p,f)||V(a,B,s)||V(a,J,U)||V(a,
(p+w)/2,(f+x)/2)||V(a,(d+J)/2,(k+U)/2)||V(a,(w+J)/2,(x+U)/2)||V(a,(e+B)/2,(m+s)/2)||V(a,(p+B)/2,(f+s)/2))G.play(),q=1;Math.floor(y/60)>=z&&(q=1);k=r;m=C;p=D;a=E;e=A+M/2;c=e-M/2*Math.cos(p);d=m+Math.sin(p)*M/2;e=e+M/2*Math.cos(p)-N*Math.sin(p);m=m-M/2*Math.sin(p)+N*Math.cos(p);"ph"==k[K][0]?(p=k[K][1]+N/2,k=k[K][2]+M/2):(p=k[K][1]+M/2,k=k[K][2]+N/2);3>=Math.abs(p-(c+e)/2)&&(3>=Math.abs(k-(d+m)/2)&&0==a)&&(y=0,15<z?z-=10:0,q=2,v++);h[37]&&(-0.0133771>F?F=-0.0133771:F-=1.6E-4);h[39]&&(0.0133771<F?F=
0.0133771:F+=1.6E-4);h[38]?(E+=0.01,2.8<E?E=2.8:0,D+=F/2):(E-=0.001*Math.abs(1500*F),0>E?E=0:E);h[40]&&(E-=0.015,0>E?E=0:0);!h[40]&&!h[38]&&(E=0.005>E?0:E-0.0075*Math.sqrt(E));0<E?D+=F/2:0;A-=E*Math.sin(D);C+=E*Math.cos(D)}else if(1==q)60>t?t+=10:0,h[32]&&(z=70,v=y=0,W());else if(-1==q){for(a=0;a<u.length;a+=4)u[a+3]?u[a+2]+=0.1:u[a+2]-=0.1,1<u[a+2]?(u[a+3]=g,u[a+2]-=0.1):-1>u[a+2]&&(u[a+3]=b,u[a+2]+=0.1);h[32]&&(q=0)}else 2==q&&(120>t?t+=10:0,h[32]&&(t=0,W()));n.fillStyle="#3A393E";n.clearRect(0,
0,610,610);n.fillRect(0,0,610,610);for(a=0;a<r.length;a++)switch(r[a][0]){case "w":n.fillStyle="#E6E3C6";n.fillRect(r[a][1],r[a][2],L,L);break;case "cu":X(r[a][1],r[a][2],0,0,0);break;case "cd":X(r[a][1],r[a][2]+N,Math.PI,0,0);break;case "cr":X(N-M/2+r[a][1],M/2+r[a][2],Math.PI/2,0,0);break;case "cl":X(-M/2+r[a][1],M/2+r[a][2],-Math.PI/2,0,0);break;case "o":c=r[a][1];d=r[a][2];n.fillStyle="#FF6600";n.fillRect(c,d,14,14);n.fillStyle="#F6B482";n.fillRect(c,d,12,12);n.beginPath();n.arc(c+6,d+6,6,0,2*
Math.PI,g);k=n.createRadialGradient(c+6,d+6,5,c+6,d+6,7);k.addColorStop(0,"#FF6600");k.addColorStop(1,"#F6B482");n.fillStyle=k;n.fill();n.beginPath();n.arc(c+6,d+6,3,0,2*Math.PI,g);n.fillStyle="#E54239";n.fill();break;case "pv":Y(r[a][1],r[a][2],b);break;case "ph":Y(r[a][1],r[a][2],g)}X(A,C,D,F,1);if(1==q)n.font="50px monospace",n.fillStyle="#191919",n.fillText("Game Over",163,243+t),n.fillStyle="#19A0BF",n.fillText("Game Over",160,240+t),n.fillRect(160,250+t,270,5),n.font="18px monospace",n.fillStyle=
"#000000",n.fillText("Press To Restart",165,280+t),n.fillStyle="#19A0BF",n.fillText("<SPACE>",230,280+t);else if(-1==q){n.font="50px monospace";for(a=0;a<u.length;a+=4)n.fillStyle="#191919",n.fillText(u[a],u[a+1],5*Math.asin(u[a+2])+300),n.fillStyle="#19A0BF",n.fillText(u[a],u[a+1]+5,5*Math.asin(u[a+2])+300);n.fillRect(160,250,270,5);n.fillRect(160,320,270,5);n.font="18px monospace";n.fillStyle="#000000";n.fillText("Press To Start",180,350);n.fillStyle="#19A0BF";n.fillText("<SPACE>",
240,350)}else 2==q&&(n.font="50px monospace",n.fillStyle="#191919",n.fillText("You Parked!",30+t+4,314),n.fillStyle="#19A0BF",n.fillText("You Parked!",30+t,310),110<=t&&(n.fillStyle="#191919",n.font="18px monospace",n.fillText("Press To Continue",170,350),n.fillStyle="#19A0BF",n.fillText("<SPACE>",240,350),n.fillRect(160,250,270,5),n.fillRect(160,320,270,5)));-1!=q&&(n.font="18px monospace",n.fillStyle="#191919",a="You parked time",1<v?a+="s":0,n.fillText(a,10,15),n.fillStyle="#19A0BF",
n.fillText(v,130,15),n.fillStyle="#191919",n.fillText(Math.floor(z-y/60)+"s left",330,15));requestAnimationFrame(Z)}W();q=-1;window.requestAnimationFrame(Z);