'),svgDataURL100(''),svgDataURL100(''),svgDataURL100(''),svgDataURL100('')]),{render:g,tileHeight:f,tileWidth:p,cleanUp:m}=A(s,{onWindowResize:t=>d(t),onKeyDown:e=>{let i;d(o=>{if(o.gameOver)return;let l=0,r=0;switch(e){case 37:case 65:r--,i="left";break;case 38:case 87:l--,i="up";break;case 39:case 68:r++,i="right";break;case 40:case 83:l++,i="down";break;default:return}const s={row:o.position.row+l,col:o.position.col+r};let d=o.remainingFoods,h=o.canExit;const u=a(s,0,0)[0][0];if(u.canEnter){u.itemId!=I&&u.itemId!=E||(u.itemId=null,d-=1,t()),0!=d||h||(c(),h=!0);let e=o.gameOver;return u.displayId==T&&(e=!0,setTimeout(()=>{m(),n()},2e3)),{position:s,remainingFoods:d,canExit:h,gameOver:e,facing:i}}})}},o,h);s({position:{row:9,col:10},facing:"down",remainingFoods:o,canExit:!1,gameOver:!1}),i()},w=t(),b=t(),k=t(),v=t(),y=t(),S=t(),I=t(),E=t(),T=t(),x="#111327",C=(t,e,a)=>{const o=[];function c(t,e){return{displayId:t,canEnter:t>y,itemId:null,imgData:e}}const r=(()=>{const[,t]=h("canvas");t.canvas.width=t.canvas.height=100,t.fillStyle="#154364",t.fillRect(0,0,100,100);return t.lineWidth=2,[[-7,86,"#0987A3"],[-3,50,"#38B2CC"],[-13,17,"#388ECC"]].forEach(e=>{let n=e[0],i=e[1];for(t.strokeStyle=e[2];n<100;)t.beginPath(),t.ellipse(n+10,i,10,10,0,0,Math.PI),n+=20,t.stroke()}),t.getImageData(0,0,100,100)})(),s=(()=>{const[,t]=h("canvas");t.canvas.width=t.canvas.height=100,t.fillStyle="#154364",t.fillRect(0,0,100,100),t.fillStyle="#630";for(let e=0;e<100;e+=20)t.fillRect(10,e,80,18);return t.getImageData(0,0,100,100)})();const d=[[k,b],[b,b],[b,b],[b,b]];const u=(()=>{const[,t]=h();function e(e,n){t.beginPath(),t.fillStyle="red",t.filter="blur(1px)",t.fillRect(e+15,n-2,6,5),t.filter="none",t.fillRect(e+16,n,4,3);t.strokeStyle="blue",t.lineWidth=2,t.strokeRect(e+8,n+3,25,9),t.fillStyle="blue",t.fillRect(e,n+10,40,12),t.fillStyle="#fff",t.fillRect(e+12,n+10,17,12),t.fillStyle="#bbb",t.arc(e+8,n+22,5,0,l),t.fill(),t.arc(e+31,n+22,5,0,l),t.fill(),t.beginPath(),t.fillStyle="#ff0",t.arc(e+3,n+13,2,0,l),t.fill(),t.closePath()}return t.canvas.height=100,t.canvas.width=100,t.fillStyle=x,t.fillRect(0,0,100,100),e(5,19),e(55,53),t.getImageData(0,0,100,100)})(),g=[],f=[1,2];function p(t,e,n,i,a){const o=t[e][n],l=t[e+i.length-1][n+i[0].length-1];o&&l&&i.forEach((i,o)=>{i.forEach((i,l)=>{t[e+o][n+l]=c(i,a[o][l])})})}function m(){let t=[];return o.forEach(e=>{e.forEach(e=>{e.canEnter&&t.push(e)})}),t}["#01ADC4","#700","#6805F2","#CB0036","#F2E530"].forEach(t=>f.forEach(e=>g.push(((t,e)=>{const[,n]=h();return t.map((t,i)=>t.map((t,a)=>(n.putImageData(e,-100*a,-100*i),n.getImageData(0,0,100,100))))})(d,function(t,e){const[,n]=h("canvas");n.canvas.width=200,n.canvas.height=400;const i=t=>{n.fillStyle=t},a=(...t)=>n.moveTo(...t),o=(...t)=>n.lineTo(...t),c=(...t)=>n.quadraticCurveTo(...t),r=()=>n.fill(),s=(...t)=>n.fillRect(...t),d=()=>n.beginPath(),u=()=>n.closePath();if(i(x),n.fillRect(0,0,200,400),i("#686868"),a(5,354),o(195,354),c(200,354,200,359),o(200,395),c(200,400,195,400),o(5,400),c(0,400,0,395),o(0,359),c(0,354,5,354),r(),d(),i("#DFD8C1"),n.ellipse(16,390,12,4,0,0,l),r(),d(),i("#014404"),n.fillRect(14,370,4,20),d(),i("#FE8"),n.arc(16,372,4,0,l),r(),d(),n.fillStyle=t,a(8,10),o(48,0),o(192,0),o(192,391),o(48,391),o(8,358),u(),r(),d(),i("rgba(0,0,0,0.3)"),a(8,10),o(48,0),o(48,391),o(8,358),u(),r(),1==e)for(let t=25;t<=241;t+=27)s(61,t,115,16);else if(2==e)for(let t=61;t<=160;t+=33)s(t,25,20,321);return n.getImageData(0,0,200,400)}(t,e))))),function(t,e){for(let n=0;n{t.itemId=i()<.5?I:E}),{getMapView:function(t,e,n){return function(t,e,n,i){const a=[],l=c(w,r);for(var s=t;s<=e;s++){a[s-t]=[];for(var d=n;d<=i;d++){let e=l;try{o[s][d]&&(e=o[s][d])}catch(t){}a[s-t].push(e)}}return a}(t.row-e,t.row+e,t.col-n,t.col+n)},numFoods:D,enableExit:function(){o.push([c(T,s)])}}},A=(t,{onWindowResize:e,onKeyDown:n},i,o)=>{const[l,r]=h(),s=100,u=100,[g,f,p,m,w]=o;window.kongRight=m;const b={[S]:x},[k,v]=d("Pizzas Eaten");root.appendChild(k),root.appendChild(l);const C=[c(window,"resize",()=>e({width:a.clientWidth,height:a.clientHeight})),c(window,"keydown",t=>{n(t.which)})];return t({width:a.clientWidth,height:a.clientHeight}),{render:function(t,e){return new Promise((n,a)=>{try{!function(t,e){l.width=e.width,l.height=e.height;const n=t[0].length*u,i=t.length*s,a=(e.height-i)/2,o=(e.width-n)/2;for(let e=0;e{root.removeChild(l),root.removeChild(k),C.forEach(t=>t())}}},R=async(t,e,n)=>{let a=!1;const o={trex:"kong",kong:"trex"};let c;const l={},r=(t,e,n)=>{l[t]=setTimeout(()=>{l[t]=null,n()},e)};const d=()=>{const t=p();V(50,t.kong,t.trex,c).then(()=>m()&&d())},{initialKongState:h,initialTrexState:g}=P(25,50),{getState:f,getSnapshot:p,isUpdated:m,setState:w}=K(),b=(...t)=>w(...t)&&d(),k=(t,e,n=f())=>t<50&&t>=0&&t!==n[o[e]].location,v=(e,i=s)=>l=>{l[e].currentAction==D&&i(),l[e].currentAction==M&&(l[e].health<=0?(a=!0,r(e,250,()=>(function(t){c=t,r("",5e3,()=>{B(),n()})})(o[e]))):(t(),r(e,750,()=>T(e,i))))};function y(t,e,n=s){f()[e].currentAction===D&&b(n=>{const i=n[e];let a,o=i.location;switch(t){case"left":o--,a=F;break;case"right":o++,a=W}return k(o,e,n)||(o=i.location),I(e,{...n,[e]:{...i,direction:a,location:o}})},v(e,n))}function S(t){f()[t].currentAction===D&&b(e=>{if(e[t].currentAction==D)return{[t]:{...e[t],currentAction:L}}})}function I(t,n=f()){const i=n[t],a=n[o[t]];if(a.currentAction!==U)return n;if(i.currentAction==L)return e(),n;const c=a.location+(a.direction==F?-1:1);if(i.location!==c)return n;let r;return function(t){clearTimeout(l[t])}(t),r=a.locationI(t,{...e,[t]:{...e[t],currentAction:D}}),v(t,e))}function T(t,e=s){b(e=>I(t,{...e,[t]:{...e[t],currentAction:D}}),v(t,e))}function x(t,e=s){b(e=>I(o[t],{...e,[t]:{...e[t],currentAction:U}}),n=>{v(o[t],"trex"==o[t]?A:s)(n),r(t,250,()=>(function(t,e=s){b(e=>({[t]:{...e[t],currentAction:M}}),e)})(t,()=>r(t,500,()=>T(t,e))))})}function C(t,e=s){f()[t].currentAction===D&&b(e=>({[t]:{...e[t],currentAction:H}}),()=>r(t,250,()=>x(t,e)))}function A(){a||function(){const t=f();t.trex.location-t.kong.location>1?r("trex",300*i()+100,()=>y("left","trex",A)):i()<.5?(S("trex"),r("trex",500,()=>E("trex",A))):C("trex",A)}()}const R=await u([svgDataURL150(''),svgDataURL100(''),svgDataURL100(''),svgDataURL150(''),svgDataURL100(''),svgDataURL100(''),svgDataURL100(''),svgDataURL('')]);R.push(window.kongRight);const{cleanUp:B,render:V}=z(function(t){if(!a)switch(t){case 37:case 65:y("left","kong");break;case 39:case 68:y("right","kong");break;case 40:case 83:S("kong");break;case 32:C("kong");break;default:return}},function(t){switch(t){case 40:case 83:E("kong");break;default:return}},function(){C("kong")},R);b({kong:h,trex:g}),A()},D=t(),L=t(),H=t(),U=t(),M=t(),F=t(),W=t(),P=(t,e)=>{return{initialKongState:{currentAction:D,location:t,direction:W,health:100,initialHealth:100},initialTrexState:{currentAction:D,location:e,direction:F,health:100,initialHealth:100}}},z=(t,e,n,i)=>{const[l,r]=h(),s=o("div");s.className="progress-wrapper";const[u,g]=d("Kong Health"),[f,p]=d("TRex Health"),m=document.getElementById("root");m.appendChild(l),s.appendChild(u),s.appendChild(f),m.appendChild(s);const w=o("div"),[b,k,v,y,S,I,E,T,x]=i,C=[];function A(t,e,n,i,o){r.fillStyle="green",r.fillRect(i.location*-n+300,t-110,e,110),function(t){const e=T.height/T.width*a.clientWidth;r.drawImage(T,50*(50-t)-1500,a.clientHeight-110-e,a.clientWidth,e)}(i.location),R("kong",i,n),R("trex",o,n,i.location*-n+300)}function R(t,e,n,i){let a,o=1;if("trex"==t){switch(e.currentAction){case U:a=y;break;case L:a=S;break;case M:a=I;break;case D:default:a=E}o=-1,r.scale(-1,1),r.translate(-a.width,0),r.drawImage(a,o*(i+e.location*n-a.width+n),l.height-2*n)}else{switch(e.currentAction){case U:a=b;break;case L:a=k;break;case M:a=v;break;case D:default:a=x}e.direction==F&&(o=-1,r.scale(-1,1),o=-1,r.translate(-a.width,0)),r.drawImage(a,o*(3*n),l.height-2*n)}r.setTransform(1,0,0,1,0,0)}return C.push(c(window,"keydown",e=>t(e.which))),C.push(c(window,"keyup",t=>e(t.which))),C.push(c(window,"click",t=>n(t))),{cleanUp:()=>{C.forEach(t=>t()),m.removeChild(l),m.removeChild(s),m.removeChild(w)},render:function(t,e,n,i){return new Promise(o=>{i?function(t){const e=document.createElement("h2"),n=document.createElement("p"),i="kong"===t?x:E;w.className="win",e.innerHTML="kong"===t?"Congratulations!":"Sorry...",t=t[0].toUpperCase()+t.slice(1),n.innerHTML=`${t} wins`,w.appendChild(e),w.appendChild(n),document.getElementById("root").appendChild(w),r.drawImage(T,0,0,a.clientWidth,a.clientHeight),r.drawImage(i,a.clientWidth/2.5,a.clientHeight/2.5,300,300)}(i):(l.height=a.clientHeight,l.width=100*t,r.fillStyle="#7E8390",r.fillRect(0,0,r.canvas.width,r.canvas.height),A(l.height,l.width,100,e,n),function(t,e){g.style.width=t.health+"%",t.health<60&&g.classList.add("below-60"),t.health<30&&g.classList.add("below-30"),p.style.width=e.health+"%",e.health<60&&p.classList.add("below-60"),e.health<30&&p.classList.add("below-30")}(e,n),o())})}}},K=()=>{const t={};let e=!1;const n=()=>t;return window.getState=n,{getState:n,getSnapshot:()=>(e=!1,t),isUpdated:()=>e,setState:(n,i=s)=>{let a=n;return"function"==typeof n&&(a=n(t)),a&&a!=t?(a&&(Object.assign(t,a),e=!0),i(t),!0):(i(t),!1)}}};(()=>{let t=0;const{playMusic:e,pizzaSound:a,punchSound:o,blockSound:c}=function(){let t,e,a={drum:1,synth:1};function o(n,i,a,o,c,l=.5){var r=t.createOscillator();r.type=i;let s=t.createGain();s.gain.cancelScheduledValues(n),s.gain.setValueAtTime(0,n),s.gain.linearRampToValueAtTime(l,n+.01),s.gain.linearRampToValueAtTime(0,n+a),r.frequency.setValueAtTime(o,n),c&&r.frequency.exponentialRampToValueAtTime(c,n+a),r.connect(s).connect(e).connect(t.destination),r.start(n),r.stop(n+a)}function c(t){o(t,"sine",1,200)}function l(t){const e=[200,236,284,300];o(t,"triangle",10*i()+1,e[n(i()*e.length)])}function r(t,e){return a[e]+t}function s(e,n,i){const o=t.currentTime;for(;o+2>a[i];){const t=r(e,i);n(t),a[i]=t}}function d(){s(.5,c,"drum");const t=[.25,.5,.75,1,1.25,1.5];s(t[n(i()*t.length)],l,"synth")}return{playMusic:()=>(t=new(window.AudioContext||window.webkitAudioContext),(e=t.createGain()).gain.value=.5,setInterval(d,100),!0),pizzaSound(){o(t.currentTime,"triangle",.25,350,440)},punchSound(){o(t.currentTime,"square",.15,200,100)},blockSound(){o(t.currentTime,"triangle",.5,100,50,5)}}}(),l=[t=>g("intro",t),t=>e()&&t(),t=>m(a,t),t=>g("pre-lvl-3",t),t=>R(o,c,t),()=>g("credits")];!function e(){r(()=>l[t++](e))}()})()})();