diff --git a/assets/index-BhFjL2tD.css b/assets/index-BhFjL2tD.css new file mode 100644 index 0000000..b1cc58c --- /dev/null +++ b/assets/index-BhFjL2tD.css @@ -0,0 +1 @@ +*{border:0;margin:0;padding:0}html,body{width:100%;height:100%;overflow:hidden} diff --git a/assets/index-CggOGxW4.js b/assets/index-CggOGxW4.js new file mode 100644 index 0000000..4ef1e90 --- /dev/null +++ b/assets/index-CggOGxW4.js @@ -0,0 +1,56 @@ +var bl=Object.defineProperty;var El=(t,e,r)=>e in t?bl(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var b=(t,e,r)=>El(t,typeof e!=="symbol"?e+"":e,r);(function t(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload")){return}for(const n of document.querySelectorAll('link[rel="modulepreload"]')){s(n)}new MutationObserver(n=>{for(const i of n){if(i.type!=="childList"){continue}for(const o of i.addedNodes){if(o.tagName==="LINK"&&o.rel==="modulepreload")s(o)}}}).observe(document,{childList:true,subtree:true});function r(n){const i={};if(n.integrity)i.integrity=n.integrity;if(n.referrerPolicy)i.referrerPolicy=n.referrerPolicy;if(n.crossOrigin==="use-credentials")i.credentials="include";else if(n.crossOrigin==="anonymous")i.credentials="omit";else i.credentials="same-origin";return i}function s(n){if(n.ep)return;n.ep=true;const i=r(n);fetch(n.href,i)}})();var Ml=Object.defineProperty;var a=(t,e)=>Ml(t,"name",{value:e,configurable:true});var Sl=(()=>{for(var t=new Uint8Array(128),e=0;e<64;e++)t[e<26?e+65:e<52?e+71:e<62?e-4:e*4-205]=e;return r=>{for(var s=r.length,n=new Uint8Array((s-(r[s-1]=="=")-(r[s-2]=="="))*3/4|0),i=0,o=0;i>4,n[o++]=l<<4|u>>2,n[o++]=u<<6|f}return n}})();var Z;var X=(Z=class{constructor(e,r,s){b(this,"r",255);b(this,"g",255);b(this,"b",255);this.r=Ne(e,0,255),this.g=Ne(r,0,255),this.b=Ne(s,0,255)}static fromArray(e){return new Z(e[0],e[1],e[2])}static fromHex(e){if(typeof e=="number")return new Z(e>>16&255,e>>8&255,e>>0&255);if(typeof e=="string"){let r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(!r)throw new Error("Invalid hex color format");return new Z(parseInt(r[1],16),parseInt(r[2],16),parseInt(r[3],16))}else throw new Error("Invalid hex color format")}static fromHSL(e,r,s){if(r==0)return new Z(255*s,255*s,255*s);let n=a((f,x,h)=>(h<0&&(h+=1),h>1&&(h-=1),h<1/6?f+(x-f)*6*h:h<1/2?x:h<2/3?f+(x-f)*(2/3-h)*6:f),"hue2rgb"),i=s<.5?s*(1+r):s+r-s*r,o=2*s-i,d=n(o,i,e+1/3),l=n(o,i,e),u=n(o,i,e-1/3);return new Z(Math.round(d*255),Math.round(l*255),Math.round(u*255))}clone(){return new Z(this.r,this.g,this.b)}lighten(e){return new Z(this.r+e,this.g+e,this.b+e)}darken(e){return this.lighten(-e)}invert(){return new Z(255-this.r,255-this.g,255-this.b)}mult(e){return new Z(this.r*e.r/255,this.g*e.g/255,this.b*e.b/255)}lerp(e,r){return new Z(be(this.r,e.r,r),be(this.g,e.g,r),be(this.b,e.b,r))}toHSL(){let e=this.r/255,r=this.g/255,s=this.b/255,n=Math.max(e,r,s),i=Math.min(e,r,s),o=(n+i)/2,d=o,l=o;if(n==i)o=d=0;else{let u=n-i;switch(d=l>.5?u/(2-n-i):u/(n+i),n){case e:o=(r-s)/u+(rX.fromHSL(t,e,r),"hsl2rgb");function de(t){return t*Math.PI/180}a(de,"deg2rad");function gt(t){return t*180/Math.PI}a(gt,"rad2deg");function Ne(t,e,r){return e>r?Ne(t,r,e):Math.min(Math.max(t,e),r)}a(Ne,"clamp");function be(t,e,r){if(typeof t=="number"&&typeof e=="number")return t+(e-t)*r;if(t instanceof C&&e instanceof C)return t.lerp(e,r);if(t instanceof X&&e instanceof X)return t.lerp(e,r);throw new Error(`Bad value for lerp(): ${t}, ${e}. Only number, Vec2 and Color is supported.`)}a(be,"lerp");function Le(t,e,r,s,n){return s+(t-e)/(r-e)*(n-s)}a(Le,"map");function ui(t,e,r,s,n){return Ne(Le(t,e,r,s,n),s,n)}a(ui,"mapc");var te;var C=(te=class{constructor(e=0,r=e){b(this,"x",0);b(this,"y",0);this.x=e,this.y=r}static fromAngle(e){let r=de(e);return new te(Math.cos(r),Math.sin(r))}static fromArray(e){return new te(e[0],e[1])}clone(){return new te(this.x,this.y)}add(...e){let r=E(...e);return new te(this.x+r.x,this.y+r.y)}sub(...e){let r=E(...e);return new te(this.x-r.x,this.y-r.y)}scale(...e){let r=E(...e);return new te(this.x*r.x,this.y*r.y)}dist(...e){let r=E(...e);return this.sub(r).len()}sdist(...e){let r=E(...e);return this.sub(r).slen()}static sdist(e,r){let s=e.x-r.x,n=e.y-r.y;return s*s+n*n}len(){return Math.sqrt(this.dot(this))}slen(){return this.dot(this)}unit(){let e=this.len();return e===0?new te(0):this.scale(1/e)}normal(){return new te(this.y,-this.x)}reflect(e){return this.sub(e.scale(2*this.dot(e)))}project(e){return e.scale(e.dot(this)/e.len())}reject(e){return this.sub(this.project(e))}dot(e){return this.x*e.x+this.y*e.y}static dot(e,r){return e.x*e.x+e.y*e.y}cross(e){return this.x*e.y-this.y*e.x}static cross(e,r){return e.x*r.y-e.y*r.x}angle(...e){let r=E(...e);return gt(Math.atan2(this.y-r.y,this.x-r.x))}angleBetween(...e){let r=E(...e);return gt(Math.atan2(this.cross(r),this.dot(r)))}lerp(e,r){return new te(be(this.x,e.x,r),be(this.y,e.y,r))}slerp(e,r){let s=this.dot(e),n=this.cross(e),i=Math.atan2(n,s);return this.scale(Math.sin((1-r)*i)).add(e.scale(Math.sin(r*i))).scale(1/n)}isZero(){return this.x===0&&this.y===0}toFixed(e){return new te(Number(this.x.toFixed(e)),Number(this.y.toFixed(e)))}transform(e){return e.multVec2(this)}eq(e){return this.x===e.x&&this.y===e.y}bbox(){return new ie(this,0,0)}toString(){return`vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`}toArray(){return[this.x,this.y]}},a(te,"Vec2"),b(te,"ZERO",new te(0,0)),b(te,"ONE",new te(1,1)),b(te,"LEFT",new te(-1,0)),b(te,"RIGHT",new te(1,0)),b(te,"UP",new te(0,-1)),b(te,"DOWN",new te(0,1)),te);function E(...t){if(t.length===1){if(t[0]instanceof C)return new C(t[0].x,t[0].y);if(Array.isArray(t[0])&&t[0].length===2)return new C(...t[0])}return new C(...t)}a(E,"vec2");var ht;var oe=(ht=class{constructor(e,r,s,n){b(this,"x",0);b(this,"y",0);b(this,"w",1);b(this,"h",1);this.x=e,this.y=r,this.w=s,this.h=n}scale(e){return new ht(this.x+this.w*e.x,this.y+this.h*e.y,this.w*e.w,this.h*e.h)}pos(){return new C(this.x,this.y)}clone(){return new ht(this.x,this.y,this.w,this.h)}eq(e){return this.x===e.x&&this.y===e.y&&this.w===e.w&&this.h===e.h}toString(){return`quad(${this.x}, ${this.y}, ${this.w}, ${this.h})`}},a(ht,"Quad"),ht);function he(t,e,r,s){return new oe(t,e,r,s)}a(he,"quad");var Oe;var es=(Oe=class{constructor(e,r,s,n){b(this,"a");b(this,"b");b(this,"c");b(this,"d");this.a=e,this.b=r,this.c=s,this.d=n}mul(e){return new Oe(this.a*e.a+this.b*e.c,this.a*e.b+this.b*e.d,this.c*e.a+this.d*e.c,this.c*e.b+this.d*e.d)}transform(e){return E(this.a*e.x+this.b*e.y,this.c*e.x+this.d*e.y)}get inverse(){let e=this.det;return new Oe(this.d/e,-this.b/e,-this.c/e,this.a/e)}get transpose(){return new Oe(this.a,this.c,this.b,this.d)}get eigenvalues(){let e=this.trace/2,r=this.det,s=e+Math.sqrt(e*e-r),n=e-Math.sqrt(e*e-r);return[s,n]}eigenvectors(e,r){return this.c!=0?[[e-this.d,this.c],[r-this.d,this.c]]:this.b!=0?[[this.b,e-this.a],[this.b,r-this.a]]:Math.abs(this.transform(E(1,0)).x-e)0?Math.acos(this.m[0]/e):-Math.acos(this.m[0]/e))}else if(this.m[4]!=0||this.m[5]!=0){let e=Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]);return gt(Math.PI/2-(this.m[5]>0?Math.acos(-this.m[4]/e):-Math.acos(this.m[4]/e)))}else return 0}getSkew(){if(this.m[0]!=0||this.m[1]!=0){let e=Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]);return new C(Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e),0)}else if(this.m[4]!=0||this.m[5]!=0){let e=Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]);return new C(0,Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e))}else return new C(0,0)}invert(){let e=[],r=this.m[10]*this.m[15]-this.m[14]*this.m[11],s=this.m[9]*this.m[15]-this.m[13]*this.m[11],n=this.m[9]*this.m[14]-this.m[13]*this.m[10],i=this.m[8]*this.m[15]-this.m[12]*this.m[11],o=this.m[8]*this.m[14]-this.m[12]*this.m[10],d=this.m[8]*this.m[13]-this.m[12]*this.m[9],l=this.m[6]*this.m[15]-this.m[14]*this.m[7],u=this.m[5]*this.m[15]-this.m[13]*this.m[7],f=this.m[5]*this.m[14]-this.m[13]*this.m[6],x=this.m[4]*this.m[15]-this.m[12]*this.m[7],h=this.m[4]*this.m[14]-this.m[12]*this.m[6],y=this.m[5]*this.m[15]-this.m[13]*this.m[7],p=this.m[4]*this.m[13]-this.m[12]*this.m[5],S=this.m[6]*this.m[11]-this.m[10]*this.m[7],g=this.m[5]*this.m[11]-this.m[9]*this.m[7],w=this.m[5]*this.m[10]-this.m[9]*this.m[6],R=this.m[4]*this.m[11]-this.m[8]*this.m[7],P=this.m[4]*this.m[10]-this.m[8]*this.m[6],O=this.m[4]*this.m[9]-this.m[8]*this.m[5];e[0]=this.m[5]*r-this.m[6]*s+this.m[7]*n,e[4]=-(this.m[4]*r-this.m[6]*i+this.m[7]*o),e[8]=this.m[4]*s-this.m[5]*i+this.m[7]*d,e[12]=-(this.m[4]*n-this.m[5]*o+this.m[6]*d),e[1]=-(this.m[1]*r-this.m[2]*s+this.m[3]*n),e[5]=this.m[0]*r-this.m[2]*i+this.m[3]*o,e[9]=-(this.m[0]*s-this.m[1]*i+this.m[3]*d),e[13]=this.m[0]*n-this.m[1]*o+this.m[2]*d,e[2]=this.m[1]*l-this.m[2]*u+this.m[3]*f,e[6]=-(this.m[0]*l-this.m[2]*x+this.m[3]*h),e[10]=this.m[0]*y-this.m[1]*x+this.m[3]*p,e[14]=-(this.m[0]*f-this.m[1]*h+this.m[2]*p),e[3]=-(this.m[1]*S-this.m[2]*g+this.m[3]*w),e[7]=this.m[0]*S-this.m[2]*R+this.m[3]*P,e[11]=-(this.m[0]*g-this.m[1]*R+this.m[3]*O),e[15]=this.m[0]*w-this.m[1]*P+this.m[2]*O;let T=this.m[0]*e[0]+this.m[1]*e[4]+this.m[2]*e[8]+this.m[3]*e[12];for(let A=0;A<4;A++)for(let v=0;v<4;v++)e[A*4+v]*=1/T;return new Ae(e)}clone(){return new Ae([...this.m])}toString(){return this.m.toString()}},a(Ae,"Mat4"),Ae);function Xs(t,e,r,s=n=>-Math.cos(n)){return t+(s(r)+1)/2*(e-t)}a(Xs,"wave");var Cl=1103515245;var Bl=12345;var si=2147483648;var Vt;var hi=(Vt=class{constructor(e){b(this,"seed");this.seed=e}gen(){return this.seed=(Cl*this.seed+Bl)%si,this.seed/si}genNumber(e,r){return e+this.gen()*(r-e)}genVec2(e,r){return new C(this.genNumber(e.x,r.x),this.genNumber(e.y,r.y))}genColor(e,r){return new X(this.genNumber(e.r,r.r),this.genNumber(e.g,r.g),this.genNumber(e.b,r.b))}genAny(...e){if(e.length===0)return this.gen();if(e.length===1){if(typeof e[0]=="number")return this.genNumber(0,e[0]);if(e[0]instanceof C)return this.genVec2(E(0,0),e[0]);if(e[0]instanceof X)return this.genColor(_(0,0,0),e[0])}else if(e.length===2){if(typeof e[0]=="number"&&typeof e[1]=="number")return this.genNumber(e[0],e[1]);if(e[0]instanceof C&&e[1]instanceof C)return this.genVec2(e[0],e[1]);if(e[0]instanceof X&&e[1]instanceof X)return this.genColor(e[0],e[1])}throw new Error("More than 2 arguments not supported")}},a(Vt,"RNG"),Vt);var Ts=new hi(Date.now());function di(t){return t!=null&&(Ts.seed=t),Ts.seed}a(di,"randSeed");function fe(...t){return Ts.genAny(...t)}a(fe,"rand");function zs(...t){return Math.floor(fe(...t.length>0?t:[2]))}a(zs,"randi");function ci(t){return fe()<=t}a(ci,"chance");function Ws(t){for(let e=t.length-1;e>0;e--){let r=Math.floor(Math.random()*(e+1));[t[e],t[r]]=[t[r],t[e]]}return t}a(Ws,"shuffle");function fi(t,e){return t.length<=e?t.slice():Ws(t.slice()).slice(0,e)}a(fi,"chooseMultiple");function gi(t){return t[zs(t.length)]}a(gi,"choose");function Zs(t,e){return t.pos.x+t.width>e.pos.x&&t.pos.xe.pos.y&&t.pos.y1||n<0||n>1?null:s}a(pi,"testLineLineT");function fs(t,e){let r=pi(t,e);return r?E(t.p1.x+r*(t.p2.x-t.p1.x),t.p1.y+r*(t.p2.y-t.p1.y)):null}a(fs,"testLineLine");function gs(t,e){let r=e.p2.sub(e.p1),s=Number.NEGATIVE_INFINITY,n=Number.POSITIVE_INFINITY;if(r.x!=0){let i=(t.pos.x-e.p1.x)/r.x,o=(t.pos.x+t.width-e.p1.x)/r.x;s=Math.max(s,Math.min(i,o)),n=Math.min(n,Math.max(i,o))}if(r.y!=0){let i=(t.pos.y-e.p1.y)/r.y,o=(t.pos.y+t.height-e.p1.y)/r.y;s=Math.max(s,Math.min(i,o)),n=Math.min(n,Math.max(i,o))}return n>=s&&n>=0&&s<=1}a(gs,"testRectLine");function Tr(t,e){return e.x>t.pos.x&&e.xt.pos.y&&e.yNumber.EPSILON)return false;let n=r.dot(s)/s.dot(s);return n>=0&&n<=1}a(ps,"testLinePoint");function fr(t,e){let r=t.p2.sub(t.p1),s=r.dot(r),n=t.p1.sub(e.center),i=2*r.dot(n),o=n.dot(n)-e.radius*e.radius,d=i*i-4*s*o;if(s<=Number.EPSILON||d<0)return false;if(d==0){let l=-i/(2*s);if(l>=0&&l<=1)return true}else{let l=(-i+Math.sqrt(d))/(2*s),u=(-i-Math.sqrt(d))/(2*s);if(l>=0&&l<=1||u>=0&&u<=1)return true}return Dr(e,t.p1)}a(fr,"testLineCircle");function ms(t,e){if(tt(e,t.p1)||tt(e,t.p2))return true;for(let r=0;rtt(e,r))||e.pts.some(r=>tt(t,r)))}a(_s,"testPolygonPolygon");function tt(t,e){let r=false,s=t.pts;for(let n=0,i=s.length-1;ne.y!=s[i].y>e.y&&e.x<(s[i].x-s[n].x)*(e.y-s[n].y)/(s[i].y-s[n].y)+s[n].x&&(r=!r);return r}a(tt,"testPolygonPoint");function ws(t,e){e=e.sub(t.center);let r=de(t.angle),s=Math.cos(r),n=Math.sin(r),i=e.x*s+e.y*n,o=-e.x*n+e.y*s;return i*i/(t.radiusX*t.radiusX)+o*o/(t.radiusY*t.radiusY)<1}a(ws,"testEllipsePoint");function Er(t,e){let r=e.center.sub(t.center),s=de(t.angle),n=Math.cos(s),i=Math.sin(s),o=r.x*n+r.y*i,d=-r.x*i+r.y*n;return ws(new rt(E(),t.radiusX+e.radius,t.radiusY+e.radius,0),E(o,d))}a(Er,"testEllipseCircle");function en(t,e){let r=t.toMat2().inverse;return e=new ke(r.transform(e.p1.sub(t.center)),r.transform(e.p2.sub(t.center))),fr(e,new Re(E(),1))}a(en,"testEllipseLine");function wi(t,e){if(t.radiusX===t.radiusY)return Er(e,new Re(t.center,t.radiusX));if(e.radiusX===e.radiusY)return Er(t,new Re(e.center,e.radiusX));let r=new xr(1/t.radiusX**2,0,0,0,1/t.radiusY**2,0,0,0,-1),s=new xr(1/e.radiusX**2,0,0,0,1/e.radiusY**2,0,0,0,-1),n=t.center.x,i=t.center.y,o=e.center.x,d=e.center.y,l=de(t.angle),u=de(e.angle),f=new xr(Math.cos(l),-Math.sin(l),n,Math.sin(l),Math.cos(l),i,0,0,1),x=new xr(Math.cos(u),-Math.sin(u),o,Math.sin(u),Math.cos(u),d,0,0,1),h=f.inverse,y=x.inverse,p=h.transpose.mul(r).mul(h),S=y.transpose.mul(s).mul(y),g=p.m11,w=p.m12,R=p.m13,P=p.m21,O=p.m22,T=p.m23,A=p.m31,v=p.m32,M=p.m33,k=S.m11,I=S.m12,D=S.m13,U=S.m21,N=S.m22,j=S.m23,z=S.m31,V=S.m32,Y=S.m33,ee=g*O*M-g*T*v-w*P*M+w*T*A+R*P*v-R*O*A,J=(g*O*Y-g*T*V-g*v*j+g*M*N-w*P*Y+w*T*z+w*A*j-w*M*U+R*P*V-R*O*z-R*A*N+R*v*U+P*v*D-P*M*I-O*A*D+O*M*k+T*A*I-T*v*k)/ee,W=(g*N*Y-g*j*V-w*U*Y+w*j*z+R*U*V-R*N*z-P*I*Y+P*D*V+O*k*Y-O*D*z-T*k*V+T*I*z+A*I*j-A*D*N-v*k*j+v*D*U+M*k*N-M*I*U)/ee,le=(k*N*Y-k*j*V-I*U*Y+I*j*z+D*U*V-D*N*z)/ee;if(J>=0){let G=-3*W+J**2,Xe=3*J*le+W*J**2-4*W**2,nt=-27*le**2+18*le*J*W+J**2*W**2-4*J**3*le-4*W**3;return!(G>0&&Xe<0&&nt>0)}else{let G=-3*W+J**2,Xe=-27*le**2+18*le*J*W+J**2*W**2-4*J**3*le-4*W**3;return!(G>0&&Xe>0)}}a(wi,"testEllipseEllipse");function tn(t,e){return ys(t,new Ee(e.points()))}a(tn,"testEllipseRect");function ys(t,e){let r=t.toMat2().inverse;return e=new Ee(e.pts.map(s=>r.transform(s.sub(t.center)))),Or(new Re(E(),1),e)}a(ys,"testEllipsePolygon");function yi(t,e){return t.x===e.x&&t.y===e.y}a(yi,"testPointPoint");function Ai(t,e){return e instanceof C?yi(e,t.pt):e instanceof Re?Dr(e,t.pt):e instanceof ke?ps(e,t.pt):e instanceof ie?Tr(e,t.pt):e instanceof Ee?tt(e,t.pt):e instanceof rt?ws(e,t.pt):false}a(Ai,"testPointShape");function xi(t,e){return e instanceof C?ps(t,e):e instanceof Re?fr(t,e):e instanceof ke?fs(t,e)!=null:e instanceof ie?gs(e,t):e instanceof Ee?ms(t,e):e instanceof rt?en(e,t):false}a(xi,"testLineShape");function vi(t,e){return e instanceof C?Dr(t,e):e instanceof Re?mi(t,e):e instanceof ke?fr(e,t):e instanceof ie?Js(e,t):e instanceof Ee?Or(t,e):e instanceof rt?Er(e,t):false}a(vi,"testCircleShape");function bi(t,e){return e instanceof C?Tr(t,e):e instanceof Re?Js(t,e):e instanceof ke?gs(t,e):e instanceof ie?Zs(t,e):e instanceof Ee?$s(t,e):e instanceof rt?tn(e,t):false}a(bi,"testRectShape");function Ei(t,e){return e instanceof C?tt(t,e):e instanceof Re?Or(e,t):e instanceof ke?ms(e,t):e instanceof ie?$s(e,t):e instanceof Ee?_s(e,t):e instanceof rt?ys(e,t):false}a(Ei,"testPolygonShape");function Mi(t,e){return e instanceof C?ws(t,e):e instanceof Re?Er(t,e):e instanceof ke?en(t,e):e instanceof ie?tn(t,e):e instanceof Ee?ys(t,e):e instanceof rt?wi(e,t):false}a(Mi,"testEllipseShape");function rn(t,e,r){let s=t,n=r.p1,i=r.p2,o=e,d=i.sub(n),l=o.cross(d);if(Math.abs(l)=1)return null;let x=u.cross(o)/l;if(x<=0||x>=1)return null;let h=d.normal().unit();return e.dot(h)>0&&(h.x*=-1,h.y*=-1),{point:s.add(o.scale(f)),normal:h,fraction:f}}a(rn,"raycastLine");function Si(t,e,r){let s=Number.NEGATIVE_INFINITY,n=Number.POSITIVE_INFINITY,i;if(t.x!=0){let o=(r.pos.x-t.x)/e.x,d=(r.pos.x+r.width-t.x)/e.x;i=E(-Math.sign(e.x),0),s=Math.max(s,Math.min(o,d)),n=Math.min(n,Math.max(o,d))}if(t.y!=0){let o=(r.pos.y-t.y)/e.y,d=(r.pos.y+r.height-t.y)/e.y;Math.min(o,d)>s&&(i=E(0,-Math.sign(e.y))),s=Math.max(s,Math.min(o,d)),n=Math.min(n,Math.max(o,d))}return n>=s&&s>=0&&s<=1?{point:t.add(e.scale(s)),normal:i,fraction:s}:null}a(Si,"raycastRect");function sn(t,e,r){let s=t,n=r.center,i=e,o=i.dot(i),d=s.sub(n),l=2*i.dot(d),u=d.dot(d)-r.radius*r.radius,f=l*l-4*o*u;if(o<=Number.EPSILON||f<0)return null;if(f==0){let x=-l/(2*o);if(x>=0&&x<=1){let h=s.add(i.scale(x));return{point:h,normal:h.sub(n),fraction:x}}}else{let x=(-l+Math.sqrt(f))/(2*o),h=(-l-Math.sqrt(f))/(2*o),y=null;if(x>=0&&x<=1&&(y=x),h>=0&&h<=1&&(y=Math.min(h,y??h)),y!=null){let p=s.add(i.scale(y));return{point:p,normal:p.sub(n).unit(),fraction:y}}}return null}a(sn,"raycastCircle");function qi(t,e,r){let s=r.pts,n=null,i=s[s.length-1];for(let o=0;ol.fraction)&&(n=l),i=d}return n}a(qi,"raycastPolygon");function Ci(t,e,r){let s=r.toMat2(),n=s.inverse,i=n.transform(t.sub(r.center)),o=n.transform(e),d=sn(i,o,new Re(E(),1));if(d){let l=es.rotation(de(-r.angle)),u=es.scale(r.radiusX,r.radiusY).transform(d.point),f=s.transform(d.point).add(r.center),x=f.dist(t)/e.len();return{point:f,normal:l.transform(E(r.radiusY**2*u.x,r.radiusX**2*u.y)).unit(),fraction:x}}return d}a(Ci,"raycastEllipse");function Bi(t,e,r,s=64){let n=t,i=e.len(),o=e.scale(1/i),d=0,l=E(Math.floor(t.x),Math.floor(t.y)),u=E(o.x>0?1:-1,o.y>0?1:-1),f=E(Math.abs(1/o.x),Math.abs(1/o.y)),x=E(u.x>0?l.x+1-t.x:t.x-l.x,u.y>0?l.y+1-t.y:t.y-l.y),h=E(f.x<1/0?f.x*x.x:1/0,f.y<1/0?f.y*x.y:1/0),y=-1;for(;d<=s;){let p=r(l);if(p===true)return{point:n.add(o.scale(d)),normal:E(y===0?-u.x:0,y===1?-u.y:0),fraction:d/i,gridPos:l};if(p)return p;h.xe.multVec2(r)))}bbox(){return this.clone()}area(){return this.width*this.height}clone(){return new ft(this.pos.clone(),this.width,this.height)}distToPoint(e){return Math.sqrt(this.sdistToPoint(e))}sdistToPoint(e){let r=this.pos,s=this.pos.add(this.width,this.height),n=Math.max(r.x-e.x,0,e.x-s.x),i=Math.max(r.y-e.y,0,e.y-s.y);return n*n+i*i}collides(e){return bi(this,e)}contains(e){return this.collides(e)}raycast(e,r){return Si(e,r,this)}random(){return this.pos.add(fe(this.width),fe(this.height))}},a(ft,"Rect"),ft);var Et;var Re=(Et=class{constructor(e,r){b(this,"center");b(this,"radius");this.center=e.clone(),this.radius=r}transform(e){return new rt(this.center,this.radius,this.radius).transform(e)}bbox(){return ie.fromPoints(this.center.sub(E(this.radius)),this.center.add(E(this.radius)))}area(){return this.radius*this.radius*Math.PI}clone(){return new Et(this.center,this.radius)}collides(e){return vi(this,e)}contains(e){return this.collides(e)}raycast(e,r){return sn(e,r,this)}random(){return this.center.add(C.fromAngle(fe(360)).scale(fe(this.radius)))}},a(Et,"Circle"),Et);var Ue;var rt=(Ue=class{constructor(e,r,s,n=0){b(this,"center");b(this,"radiusX");b(this,"radiusY");b(this,"angle");this.center=e.clone(),this.radiusX=r,this.radiusY=s,this.angle=n}static fromMat2(e){let r=e.inverse,s=r.transpose.mul(r),[n,i]=s.eigenvalues,[o,d]=s.eigenvectors(n,i),[l,u]=[1/Math.sqrt(n),1/Math.sqrt(i)];return l>u?new Ue(E(),l,u,gt(Math.atan2(-o[1],o[0]))):new Ue(E(),u,l,gt(Math.atan2(-d[1],d[0])))}toMat2(){let e=de(this.angle),r=Math.cos(e),s=Math.sin(e);return new es(r*this.radiusX,-s*this.radiusY,s*this.radiusX,r*this.radiusY)}transform(e){if(this.angle==0&&e.getRotation()==0)return new Ue(e.multVec2(this.center),e.m[0]*this.radiusX,e.m[5]*this.radiusY);{let r=this.toMat2(),s=e.getRotation(),n=e.getScale();r=xr.fromMat2(r).scale(n.x,n.y).rotate(s).toMat2();let i=Ue.fromMat2(r);return i.center=e.multVec2(this.center),i}}bbox(){if(this.angle==0)return ie.fromPoints(this.center.sub(E(this.radiusX,this.radiusY)),this.center.add(E(this.radiusX,this.radiusY)));{let e=de(this.angle),r=Math.cos(e),s=Math.sin(e),n=this.radiusX*r,i=this.radiusX*s,o=this.radiusY*s,d=this.radiusY*r,l=Math.sqrt(n*n+o*o),u=Math.sqrt(i*i+d*d);return ie.fromPoints(this.center.sub(E(l,u)),this.center.add(E(l,u)))}}area(){return this.radiusX*this.radiusY*Math.PI}clone(){return new Ue(this.center,this.radiusX,this.radiusY,this.angle)}collides(e){return Mi(this,e)}contains(e){e=e.sub(this.center);let r=de(this.angle),s=Math.cos(r),n=Math.sin(r),i=e.x*s+e.y*n,o=-e.x*n+e.y*s;return i*i/(this.radiusX*this.radiusX)+o*o/(this.radiusY*this.radiusY)<1}raycast(e,r){return Ci(e,r,this)}random(){return this.center}},a(Ue,"Ellipse"),Ue);function Ri(t,e,r,s){let n=e.sub(t),i=s.sub(r),o=n.cross(i);return o<1e-5&&o>-1e-5||(o=r.sub(t).cross(i)/o,o<0||o>1)?null:t.add(n.scale(o))}a(Ri,"segmentLineIntersection");var Ke;var Ee=(Ke=class{constructor(e){b(this,"pts");if(e.length<3)throw new Error("Polygons should have at least 3 vertices");this.pts=e}transform(e){return new Ke(this.pts.map(r=>e.multVec2(r)))}bbox(){let e=E(Number.MAX_VALUE),r=E(-Number.MAX_VALUE);for(let s of this.pts)e.x=Math.min(e.x,s.x),r.x=Math.max(r.x,s.x),e.y=Math.min(e.y,s.y),r.y=Math.max(r.y,s.y);return ie.fromPoints(e,r)}area(){let e=0,r=this.pts.length;for(let s=0;se.clone()))}collides(e){return Ei(this,e)}contains(e){return this.collides(e)}raycast(e,r){return qi(e,r,this)}random(){return E()}cut(e,r){new ke(e,r);let s=[],n=[],i=r.sub(e),o=this.pts[this.pts.length-1],d=o.sub(e),l=i.cross(d)>0;return this.pts.forEach(u=>{d=u.sub(e);let f=i.cross(d)>0;if(l!=f){let x=Ri(o,u,e,r);s.push(x),n.push(x),l=f}(f?s:n).push(u),o=u}),[s.length?new Ke(s):null,n.length?new Ke(n):null]}},a(Ke,"Polygon"),Ke);function Pi(t,e,r,s){let n=s*s,i=1-s,o=i*i;return t.scale(o).add(e.scale(2*i*s)).add(r.scale(n))}a(Pi,"evaluateQuadratic");function ki(t,e,r,s){let n=1-s;return e.sub(t).scale(2*n).add(r.sub(e).scale(2*s))}a(ki,"evaluateQuadraticFirstDerivative");function Ii(t,e,r,s){return r.sub(e.scale(2)).add(t).scale(2)}a(Ii,"evaluateQuadraticSecondDerivative");function As(t,e,r,s,n){let i=n*n,o=i*n,d=1-n,l=d*d,u=l*d;return t.scale(u).add(e.scale(3*l*n)).add(r.scale(3*d*i)).add(s.scale(o))}a(As,"evaluateBezier");function Fi(t,e,r,s,n){let i=n*n,o=1-n,d=o*o;return e.sub(t).scale(3*d).add(r.sub(e).scale(6*o*n)).add(s.sub(r).scale(3*i))}a(Fi,"evaluateBezierFirstDerivative");function Ti(t,e,r,s,n){let i=1-n;return r.sub(e.scale(2)).add(t).scale(6*i).add(s.sub(r.scale(2)).add(e).scale(6*n))}a(Ti,"evaluateBezierSecondDerivative");function Di(t,e,r,s,n){let i=.5*(((-n+2)*n-1)*n),o=.5*((3*n-5)*n*n+2),d=.5*(((-3*n+4)*n+1)*n),l=.5*((n-1)*n*n);return t.scale(i).add(e.scale(o)).add(r.scale(d)).add(s.scale(l))}a(Di,"evaluateCatmullRom");function Oi(t,e,r,s,n){let i=.5*((-3*n+4)*n-1),o=.5*((9*n-10)*n),d=.5*((-9*n+8)*n+1),l=.5*((3*n-2)*n);return t.scale(i).add(e.scale(o)).add(r.scale(d)).add(s.scale(l))}a(Oi,"evaluateCatmullRomFirstDerivative");function Ui(t){let e=nn(t),r=e(1);return s=>{let n=s*r,i=e(n,true);return t(i)}}a(Ui,"normalizedCurve");function nn(t,e=10,r=10){let s=[0],n=[0],i=1/(e-1)/r,o=0,d=t(0),l=0;for(let u=1;u{if(f){let x=u;if(x<=0)return 0;if(x>=o)return 1;let h=0;for(;s[h+1]=1)return s[e-1];let x=0;for(;n[x+1]{let u=l*l,f=u*l;return n*f+i*u+o*l+d}}a(gr,"hermite");function an(t,e,r,s,n,i=gr){let o=i(e.x,(1-n)*(r.x-t.x),(1-n)*(s.x-e.x),r.x),d=i(e.y,(1-n)*(r.y-t.y),(1-n)*(s.y-e.y),r.y);return l=>new C(o(l),d(l))}a(an,"cardinal");function Mr(t,e,r,s,n=gr){return an(t,e,r,s,.5,n)}a(Mr,"catmullRom");function Li(t,e,r,s,n=gr){return Mr(s.add(t.sub(e).scale(6)),t,s,t.add(s.sub(r).scale(6)),n)}a(Li,"bezier");function Ni(t,e,r,s,n,i,o,d=gr){let l=d(e.x,.5*(1-n)*(1+o)*(1+i)*(e.x-t.x)+.5*(1-n)*(1-o)*(1-i)*(r.x-e.x),.5*(1-n)*(1+o)*(1-i)*(r.x-e.x)+.5*(1-n)*(1-o)*(1+i)*(s.x-r.x),r.x),u=d(e.y,.5*(1-n)*(1+o)*(1+i)*(e.y-t.y)+.5*(1-n)*(1-o)*(1-i)*(r.y-e.y),.5*(1-n)*(1+o)*(1-i)*(r.y-e.y)+.5*(1-n)*(1-o)*(1+i)*(s.y-r.y),r.y);return f=>new C(l(f),u(f))}a(Ni,"kochanekBartels");function Gi(t,e,r,s){let n=2*t+e-2*s+r,i=-3*t+3*s-2*e+r,o=e;return d=>{let l=d*d;return 3*n*l+2*i*d+o}}a(Gi,"hermiteFirstDerivative");function Ot(t){return 0<=t&&t<=1}a(Ot,"inZeroOneDomain");function Zr(t,e){return Math.abs(t-e)<=Number.EPSILON}a(Zr,"approximately");function Ut(t){return t<0?-Math.pow(-t,1/3):Math.pow(t,1/3)}a(Ut,"cubeRoot");function Hi(t,e,r,s){let n=3*t-6*e+3*r,i=-3*t+3*e,o=t,d=-t+3*e-3*r+s;if(Zr(d,0)){if(Zr(n,0))return Zr(i,0)?[]:[-o/i].filter(Ot);let g=Math.sqrt(i*i-4*n*o),w=2*n;return[(g-i)/w,(-i-g)/w].filter(Ot)}n/=d,i/=d,o/=d;let l=(3*i-n*n)/3,u=l/3,f=(2*n*n*n-9*n*i+27*o)/27,x=f/2,h=x*x+u*u*u;if(h<0){let g=-l/3,w=g*g*g,R=Math.sqrt(w),P=-f/(2*R),O=P<-1?-1:P>1?1:P,T=Math.acos(O),A=2*Ut(R),v=A*Math.cos(T/3)-n/3,M=A*Math.cos((T+2*Math.PI)/3)-n/3,k=A*Math.cos((T+4*Math.PI)/3)-n/3;return[v,M,k].filter(Ot)}if(h===0){let g=x<0?Ut(-x):-Ut(x),w=2*g-n/3,R=-g-n/3;return[w,R].filter(Ot)}let y=Math.sqrt(h),p=Ut(y-x),S=Ut(y+x);return[p-S-n/3].filter(Ot)}a(Hi,"getCubicRoots");function ji(t,e,r,s,n){let i=Hi(t.x-n,e.x-n,r.x-n,s.x-n);return i.length>0?As(t,e,r,s,i[0]).y:NaN}a(ji,"cubicBezierYforX");function Vi(t){if(!t||t.length==0)throw new Error("Need at least one point for easingLinear.");let e=t.length;return r=>{if(r<=0||t.length==1||r<=t[0].x)return t[0].y;for(let s=0;s=r)return Le(r,t[s-1].x,t[s].x,t[s-1].y,t[s].y);return t[t.length-1].y}}a(Vi,"easingLinear");function Ki(t,e){return r=>ji(E(0,0),t,e,E(1,1),r)}a(Ki,"easingCubicBezier");function Yi(t,e="jump-end"){let r=1/t,s=e=="jump-start"||e=="jump-both",n=e=="jump-end"||e=="jump-both",i=1/(t+(n?1:0)),o=s?i:0;return d=>{let l=Math.floor(d/r);return o+l*i}}a(Yi,"easingSteps");function Qi(t,e){let r=Number.MAX_VALUE,s={normal:E(0),distance:0};for(let n of[t,e])for(let i=0;i=0}a(on,"isOrientedCcw");function Xi(t){let e=0,r=t[t.length-1];for(let s=0;s=0}a(Jr,"onSameSide");function zi(t,e,r,s){return Jr(t,e,r,s)&&Jr(t,r,e,s)&&Jr(t,s,e,r)}a(zi,"pointInTriangle");function Wi(t,e,r,s){for(let n of t)if(n!==e&&n!==r&&n!==s&&zi(n,e,r,s))return true;return false}a(Wi,"someInTriangle");function Zi(t,e,r,s){return on(t,e,r)&&!Wi(s,t,e,r)}a(Zi,"isEar");function ln(t){if(t.length<3)return[];if(t.length==3)return[t];let e=[],r=[],s=0;for(let x=0;x3;){u=e[d],f=r[d];let x=t[f],h=t[d],y=t[u];if(Zi(x,h,y,n))i.push([x,h,y]),e[f]=u,r[u]=f,n.splice(n.indexOf(h),1),--o,l=0;else if(++l>o)return[];d=u}return u=e[d],f=r[d],i.push([t[f],t[d],t[u]]),i}a(ln,"triangulate");function Ji(t){if(t.length<3)return false;let e=t.length-2,r=t.length-1,s=0,n=t[r].sub(t[e]),i=t[s].sub(t[r]),o=n.cross(i);for(;s+1?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";var xs="topleft";var Pl="monospace";var ts="monospace";var Ds="linear";var un=[{name:"a_pos",size:2},{name:"a_uv",size:2},{name:"a_color",size:4}];var kl=un.reduce((t,e)=>t+e.size,0);var _i=2048;var Il=_i*4*kl;var Fl=_i*6;var Tl=` +attribute vec2 a_pos; +attribute vec2 a_uv; +attribute vec4 a_color; + +varying vec2 v_pos; +varying vec2 v_uv; +varying vec4 v_color; + +vec4 def_vert() { + return vec4(a_pos, 0.0, 1.0); +} + +{{user}} + +void main() { + vec4 pos = vert(a_pos, a_uv, a_color); + v_pos = a_pos; + v_uv = a_uv; + v_color = a_color; + gl_Position = pos; +} +`;var Dl=` +precision mediump float; + +varying vec2 v_pos; +varying vec2 v_uv; +varying vec4 v_color; + +uniform sampler2D u_tex; + +vec4 def_frag() { + vec4 texColor = texture2D(u_tex, v_uv); + return vec4((v_color.rgb * texColor.rgb), texColor.a) * v_color.a; +} + +{{user}} + +void main() { + gl_FragColor = frag(v_pos, v_uv, v_color, u_tex); + if (gl_FragColor.a == 0.0) { + discard; + } +} +`;var Os=` +vec4 vert(vec2 pos, vec2 uv, vec4 color) { + return def_vert(); +} +`;var Us=` +vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) { + return def_frag(); +} +`;var Ol=new Set(["id","require"]);var Ul=new Set(["add","fixedUpdate","update","draw","destroy","inspect","drawInspect"]);var Ll=200;var Nl=640;var Gl=65536;var ea=Symbol.for("kaplay.cancel");var Kt;var ta=(Kt=class extends Map{constructor(){super(...arguments);b(this,"lastID",0)}push(r){let s=this.lastID;return this.set(s,r),this.lastID++,s}pushd(r){let s=this.push(r);return()=>this.delete(s)}},a(Kt,"Registry"),Kt);var Mt;var Bt=(Mt=class{constructor(e){b(this,"paused",false);b(this,"cancel");this.cancel=e}static join(e){let r=new Mt(()=>e.forEach(s=>s.cancel()));return Object.defineProperty(r,"paused",{get:a(()=>e[0].paused,"get"),set:a(s=>e.forEach(n=>n.paused=s),"set")}),r.paused=false,r}static replace(e,r){return e.cancel=()=>r.cancel(),r.paused=e.paused,Object.defineProperty(e,"paused",{get:a(()=>r.paused,"get"),set:a(s=>r.paused=s,"set")}),e}},a(Mt,"KEventController"),Mt);var Yt;var xe=(Yt=class{constructor(){b(this,"cancellers",new WeakMap);b(this,"handlers",new ta)}add(e){function r(...i){if(!n.paused)return e(...i)}a(r,"handler");let s=this.handlers.pushd(r),n=new Bt(s);return this.cancellers.set(r,s),n}addOnce(e){let r=this.add((...s)=>{r.cancel(),e(...s)});return r}next(){return new Promise(e=>this.addOnce(e))}trigger(...e){this.handlers.forEach(r=>{let s=r(...e),n;s===ea&&(n=this.cancellers.get(r))&&n()})}numListeners(){return this.handlers.size}clear(){this.handlers.clear()}},a(Yt,"KEvent"),Yt);var Qt;var Sr=(Qt=class{constructor(){b(this,"handlers",{});b(this,"registers",{})}on(e,r){return this.handlers[e]||(this.handlers[e]=new xe),this.handlers[e].add(r)}onOnce(e,r){let s=this.on(e,(...n)=>{s.cancel(),r(...n)});return s}next(e){return new Promise(r=>{this.onOnce(e,(...s)=>r(s[0]))})}trigger(e,...r){this.handlers[e]&&this.handlers[e].trigger(...r)}remove(e){delete this.handlers[e]}clear(){this.handlers={}}numListeners(e){var r;return((r=this.handlers[e])==null?void 0:r.numListeners())??0}},a(Qt,"KEventHandler"),Qt);var Hl=a(t=>t[0]instanceof X,"arrayIsColor");var jl=a(t=>t[0]instanceof C,"arrayIsVec2");var Vl=a(t=>typeof t[0]=="number","arrayIsNumber");var Xt;var ra=(Xt=class{constructor(e=(r,s)=>r0;){let r=Math.floor((e-1)/2);if(!this._compareFn(this._items[e],this._items[r])&&this._items[e]>=this._items[r])break;this.swap(e,r),e=r}}moveDown(e){for(;et.match(/^data:\w+\/\w+;base64,.+/),"isDataURL");var Kl=a(t=>t.split(".").slice(0,-1).join("."),"getFileName");function bs(t,e){if(t===e)return true;let r=typeof t,s=typeof e;if(r!==s)return false;if(r==="object"&&s==="object"&&t!==null&&e!==null){if(Array.isArray(t)!==Array.isArray(e))return false;let n=Object.keys(t),i=Object.keys(e);if(n.length!==i.length)return false;for(let o of n){let d=t[o],l=e[o];if(!bs(d,l))return false}return true}return false}a(bs,"deepEq");var ni=new Set;var Yl=a(t=>t instanceof Error?t.message:String(t),"getErrorMessage");function oa(t){ni.has(t)||(ni.add(t),console.warn(t))}a(oa,"warn");function Rt(t,e){oa(`${t} is deprecated. Use ${e} instead.`)}a(Rt,"deprecateMsg");function rs(t,e){return Number(t.toFixed(e))}a(rs,"toFixed");function ne(t,e){return(...r)=>{let s=r.length;if(s===t.length)return t(...r);if(s===e.length)return e(...r)}}a(ne,"overload2");var Ql=Object.freeze([776,2359,2367,2984,3007,3021,3633,3635,3648,3657,4352,4449,4520]);function la(t){if(typeof t!="string")throw new TypeError("string cannot be undefined or null");let e=[],r=0,s=0;for(;r=e&&t<=r}a(xt,"betweenInclusive");var Fe=a((t,e)=>Array.isArray(t)?t==null?void 0:t.includes(e):t===e,"isEqOrIncludes");var je=a((t,e)=>Array.isArray(e)?e.some(r=>t.has(r)):t.has(e),"setHasOrIncludes");var Qr=a((t,e,r)=>{var s;t.has(e)?(s=t.get(e))==null?void 0:s.push(r):t.set(e,[r])},"mapAddOrPush");var Xl=(()=>{let t=0;return()=>t++})();var zl={"Joy-Con L+R (STANDARD GAMEPAD Vendor: 057e Product: 200e)":{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","6":"ltrigger","7":"rtrigger","8":"select","9":"start","10":"lstick","11":"rstick","12":"dpad-up","13":"dpad-down","14":"dpad-left","15":"dpad-right","16":"home","17":"capture"},sticks:{left:{x:0,y:1},right:{x:2,y:3}}},"Joy-Con (L) (STANDARD GAMEPAD Vendor: 057e Product: 2006)":{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","9":"select","10":"lstick","16":"start"},sticks:{left:{x:0,y:1}}},"Joy-Con (R) (STANDARD GAMEPAD Vendor: 057e Product: 2007)":{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","9":"start","10":"lstick","16":"select"},sticks:{left:{x:0,y:1}}},"Pro Controller (STANDARD GAMEPAD Vendor: 057e Product: 2009)":{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","6":"ltrigger","7":"rtrigger","8":"select","9":"start","10":"lstick","11":"rstick","12":"dpad-up","13":"dpad-down","14":"dpad-left","15":"dpad-right","16":"home","17":"capture"},sticks:{left:{x:0,y:1},right:{x:2,y:3}}},default:{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","6":"ltrigger","7":"rtrigger","8":"select","9":"start","10":"lstick","11":"rstick","12":"dpad-up","13":"dpad-down","14":"dpad-left","15":"dpad-right","16":"home"},sticks:{left:{x:0,y:1},right:{x:2,y:3}}}};var Wl=a(()=>bt.lastInputDevice,"getLastInputDeviceType");var Zl=a(()=>{let t=bt.buttons;for(let e in t){let r=t[e].keyboard&&[t[e].keyboard].flat(),s=t[e].keyboardCode&&[t[e].keyboardCode].flat(),n=t[e].gamepad&&[t[e].gamepad].flat(),i=t[e].mouse&&[t[e].mouse].flat();r&&r.forEach(o=>{Qr(bt.buttonsByKey,o,e)}),s&&s.forEach(o=>{Qr(bt.buttonsByKeyCode,o,e)}),n&&n.forEach(o=>{Qr(bt.buttonsByGamepad,o,e)}),i&&i.forEach(o=>{Qr(bt.buttonsByMouse,o,e)})}},"parseButtonBindings");var zt;var vr=(zt=class{constructor(){b(this,"pressed",new Set([]));b(this,"pressedRepeat",new Set([]));b(this,"released",new Set([]));b(this,"down",new Set([]))}update(){this.pressed.clear(),this.released.clear(),this.pressedRepeat.clear()}press(e){this.pressed.add(e),this.pressedRepeat.add(e),this.down.add(e)}pressRepeat(e){this.pressedRepeat.add(e)}release(e){this.down.delete(e),this.pressed.delete(e),this.released.add(e)}},a(zt,"ButtonState"),zt);var Wt;var Jl=(Wt=class{constructor(){b(this,"buttonState",new vr);b(this,"stickState",new Map)}},a(Wt,"GamepadState"),Wt);var Zt;var $l=(Zt=class{constructor(){b(this,"dts",[]);b(this,"timer",0);b(this,"fps",0)}tick(e){this.dts.push(e),this.timer+=e,this.timer>=1&&(this.timer=0,this.fps=Math.round(1/(this.dts.reduce((r,s)=>r+s)/this.dts.length)),this.dts=[])}},a(Zt,"FPSCounter"),Zt);var bt;var ii=zl;var _l=a(t=>{let e=t.buttons??{};return{canvas:t.canvas,buttons:e,buttonsByKey:new Map,buttonsByMouse:new Map,buttonsByGamepad:new Map,buttonsByKeyCode:new Map,loopID:null,stopped:false,dt:0,fixedDt:1/50,restDt:0,time:0,realTime:0,fpsCounter:new $l,timeScale:1,skipTime:false,isHidden:false,numFrames:0,mousePos:new C(0),mouseDeltaPos:new C(0),keyState:new vr,mouseState:new vr,mergedGamepadState:new Jl,gamepadStates:new Map,lastInputDevice:null,buttonState:new vr,gamepads:[],charInputted:[],isMouseMoved:false,lastWidth:t.canvas.offsetWidth,lastHeight:t.canvas.offsetHeight,events:new Sr}},"initAppState");var eu=a(t=>{if(!t.canvas)throw new Error("Please provide a canvas");let e=_l(t);bt=e,Zl();function r(){return e.dt*e.timeScale}a(r,"dt");function s(){return e.fixedDt*e.timeScale}a(s,"fixedDt");function n(){return e.restDt*e.timeScale}a(n,"restDt");function i(){return e.isHidden}a(i,"isHidden");function o(){return e.time}a(o,"time");function d(){return e.fpsCounter.fps}a(d,"fps");function l(){return e.numFrames}a(l,"numFrames");function u(){return e.canvas.toDataURL()}a(u,"screenshot");function f(m){e.canvas.style.cursor=m}a(f,"setCursor");function x(){return e.canvas.style.cursor}a(x,"getCursor");function h(m){if(m)try{let q=e.canvas.requestPointerLock();q.catch&&q.catch(B=>console.error(B))}catch(q){console.error(q)}else document.exitPointerLock()}a(h,"setCursorLocked");function y(){return!!document.pointerLockElement}a(y,"isCursorLocked");function p(m){m.requestFullscreen?m.requestFullscreen():m.webkitRequestFullscreen&&m.webkitRequestFullscreen()}a(p,"enterFullscreen");function S(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullScreen&&document.webkitExitFullScreen()}a(S,"exitFullscreen");function g(m=true){m?p(e.canvas):S()}a(g,"setFullscreen");function w(){return document.fullscreenElement===e.canvas||document.webkitFullscreenElement===e.canvas}a(w,"isFullscreen");function R(){e.stopped=true;let m=Object.entries(Se),q=Object.entries(Is),B=Object.entries(Yr);for(let[F,H]of m)e.canvas.removeEventListener(F,H);for(let[F,H]of q)document.removeEventListener(F,H);for(let[F,H]of B)window.removeEventListener(F,H);ri.disconnect()}a(R,"quit");function P(m,q){e.loopID!==null&&cancelAnimationFrame(e.loopID);let B=0,F=0,H=a(se=>{if(e.stopped)return;if(document.visibilityState!=="visible"){e.loopID=requestAnimationFrame(H);return}let me=se/1e3,ue=Math.min(me-e.realTime,.25),Ze=t.maxFPS?1/t.maxFPS:0;if(e.realTime=me,F+=ue,F>Ze){if(!e.skipTime){for(B+=F,e.dt=e.fixedDt,e.restDt=0;B>e.fixedDt;)B-=e.fixedDt,B0}a(O,"isTouchscreen");function T(){return e.mousePos.clone()}a(T,"mousePos");function A(){return e.mouseDeltaPos.clone()}a(A,"mouseDeltaPos");function v(m="left"){return e.mouseState.pressed.has(m)}a(v,"isMousePressed");function M(m="left"){return e.mouseState.down.has(m)}a(M,"isMouseDown");function k(m="left"){return e.mouseState.released.has(m)}a(k,"isMouseReleased");function I(){return e.isMouseMoved}a(I,"isMouseMoved");function D(m){return m===void 0?e.keyState.pressed.size>0:je(e.keyState.pressed,m)}a(D,"isKeyPressed");function U(m){return m===void 0?e.keyState.pressedRepeat.size>0:je(e.keyState.pressedRepeat,m)}a(U,"isKeyPressedRepeat");function N(m){return m===void 0?e.keyState.down.size>0:je(e.keyState.down,m)}a(N,"isKeyDown");function j(m){return m===void 0?e.keyState.released.size>0:je(e.keyState.released,m)}a(j,"isKeyReleased");function z(m){return m===void 0?e.mergedGamepadState.buttonState.pressed.size>0:je(e.mergedGamepadState.buttonState.pressed,m)}a(z,"isGamepadButtonPressed");function V(m){return m===void 0?e.mergedGamepadState.buttonState.down.size>0:je(e.mergedGamepadState.buttonState.down,m)}a(V,"isGamepadButtonDown");function Y(m){return m===void 0?e.mergedGamepadState.buttonState.released.size>0:je(e.mergedGamepadState.buttonState.released,m)}a(Y,"isGamepadButtonReleased");function ee(m){return m===void 0?e.buttonState.pressed.size>0:je(e.buttonState.pressed,m)}a(ee,"isButtonPressed");function J(m){return m===void 0?e.buttonState.down.size>0:je(e.buttonState.down,m)}a(J,"isButtonDown");function W(m){return m===void 0?e.buttonState.released.size>0:je(e.buttonState.released,m)}a(W,"isButtonReleased");function le(m){var q;return(q=e.buttons)==null?void 0:q[m]}a(le,"getButton");function G(m,q){e.buttons[m]={...e.buttons[m],...q}}a(G,"setButton");function Xe(m){e.buttonState.press(m),e.events.trigger("buttonPress",m)}a(Xe,"pressButton");function nt(m){e.buttonState.release(m),e.events.trigger("buttonRelease",m)}a(nt,"releaseButton");function It(m){return e.events.on("resize",m)}a(It,"onResize");let pr=ne(m=>e.events.on("keyDown",m),(m,q)=>e.events.on("keyDown",B=>Fe(m,B)&&q(B))),mr=ne(m=>e.events.on("keyPress",q=>m(q)),(m,q)=>e.events.on("keyPress",B=>Fe(m,B)&&q(B))),Gr=ne(m=>e.events.on("keyPressRepeat",m),(m,q)=>e.events.on("keyPressRepeat",B=>Fe(m,B)&&q(B))),Hr=ne(m=>e.events.on("keyRelease",m),(m,q)=>e.events.on("keyRelease",B=>Fe(m,B)&&q(B))),Ft=ne(m=>e.events.on("mouseDown",q=>m(q)),(m,q)=>e.events.on("mouseDown",B=>Fe(m,B)&&q(B))),Ge=ne(m=>e.events.on("mousePress",q=>m(q)),(m,q)=>e.events.on("mousePress",B=>Fe(m,B)&&q(B))),jr=ne(m=>e.events.on("mouseRelease",q=>m(q)),(m,q)=>e.events.on("mouseRelease",B=>B===m&&q(B)));function vt(m){return e.events.on("mouseMove",()=>m(T(),A()))}a(vt,"onMouseMove");function L(m){return e.events.on("charInput",m)}a(L,"onCharInput");function K(m){return e.events.on("touchStart",m)}a(K,"onTouchStart");function Q(m){return e.events.on("touchMove",m)}a(Q,"onTouchMove");function re(m){return e.events.on("touchEnd",m)}a(re,"onTouchEnd");function ce(m){return e.events.on("scroll",m)}a(ce,"onScroll");function $(m){return e.events.on("hide",m)}a($,"onHide");function ye(m){return e.events.on("show",m)}a(ye,"onShow");let it=ne(m=>e.events.on("gamepadButtonPress",(q,B)=>m(q,B)),(m,q)=>e.events.on("gamepadButtonPress",(B,F)=>Fe(m,B)&&q(B,F))),Rs=ne(m=>e.events.on("gamepadButtonDown",(q,B)=>m(q,B)),(m,q)=>e.events.on("gamepadButtonDown",(B,F)=>Fe(m,B)&&q(B,F))),Ps=ne(m=>e.events.on("gamepadButtonRelease",(q,B)=>m(q,B)),(m,q)=>e.events.on("gamepadButtonRelease",(B,F)=>Fe(m,B)&&q(B,F)));function Vr(m,q){return e.events.on("gamepadStick",(B,F,H)=>B===m&&q(F,H))}a(Vr,"onGamepadStick");function Kr(m){e.events.on("gamepadConnect",m)}a(Kr,"onGamepadConnect");function wr(m){e.events.on("gamepadDisconnect",m)}a(wr,"onGamepadDisconnect");function De(m){return e.mergedGamepadState.stickState.get(m)||new C(0)}a(De,"getGamepadStick");function ze(){return[...e.charInputted]}a(ze,"charInputted");function Tt(){return[...e.gamepads]}a(Tt,"getGamepads");let Ie=ne(m=>e.events.on("buttonPress",q=>m(q)),(m,q)=>e.events.on("buttonPress",B=>Fe(m,B)&&q(B))),yr=ne(m=>e.events.on("buttonDown",q=>m(q)),(m,q)=>e.events.on("buttonDown",B=>Fe(m,B)&&q(B))),We=ne(m=>e.events.on("buttonRelease",q=>m(q)),(m,q)=>e.events.on("buttonRelease",B=>Fe(m,B)&&q(B)));function Ar(){e.events.trigger("input"),e.keyState.down.forEach(m=>e.events.trigger("keyDown",m)),e.mouseState.down.forEach(m=>e.events.trigger("mouseDown",m)),e.buttonState.down.forEach(m=>{e.events.trigger("buttonDown",m)}),$n()}a(Ar,"processInput");function Zn(){e.keyState.update(),e.mouseState.update(),e.buttonState.update(),e.mergedGamepadState.buttonState.update(),e.mergedGamepadState.stickState.forEach((m,q)=>{e.mergedGamepadState.stickState.set(q,new C(0))}),e.charInputted=[],e.isMouseMoved=false,e.mouseDeltaPos=new C(0),e.gamepadStates.forEach(m=>{m.buttonState.update(),m.stickState.forEach((q,B)=>{m.stickState.set(B,new C(0))})})}a(Zn,"resetInput");function ks(m){let q={index:m.index,isPressed:a(B=>{var F;return((F=e.gamepadStates.get(m.index))==null?void 0:F.buttonState.pressed.has(B))||false},"isPressed"),isDown:a(B=>{var F;return((F=e.gamepadStates.get(m.index))==null?void 0:F.buttonState.down.has(B))||false},"isDown"),isReleased:a(B=>{var F;return((F=e.gamepadStates.get(m.index))==null?void 0:F.buttonState.released.has(B))||false},"isReleased"),getStick:a(B=>{var F;return((F=e.gamepadStates.get(m.index))==null?void 0:F.stickState.get(B))||E()},"getStick")};return e.gamepads.push(q),e.gamepadStates.set(m.index,{buttonState:new vr,stickState:new Map([["left",new C(0)],["right",new C(0)]])}),q}a(ks,"registerGamepad");function Jn(m){e.gamepads=e.gamepads.filter(q=>q.index!==m.index),e.gamepadStates.delete(m.index)}a(Jn,"removeGamepad");function $n(){var m,q;for(let B of navigator.getGamepads())B&&!e.gamepadStates.has(B.index)&&ks(B);for(let B of e.gamepads){let F=navigator.getGamepads()[B.index];if(!F)continue;let H=(t.gamepads??{})[F.id]||ii[F.id]||ii.default,se=e.gamepadStates.get(B.index);if(se){for(let me=0;me{e.buttonState.press(Je),e.events.trigger("buttonPress",Je)})),e.mergedGamepadState.buttonState.press(ue),se.buttonState.press(ue),e.events.trigger("gamepadButtonPress",ue,B)}else se.buttonState.down.has(ue)&&(He&&((q=e.buttonsByGamepad.get(ue))==null?void 0:q.forEach(Je=>{e.buttonState.release(Je),e.events.trigger("buttonRelease",Je)})),e.mergedGamepadState.buttonState.release(ue),se.buttonState.release(ue),e.events.trigger("gamepadButtonRelease",ue,B))}for(let me in H.sticks){let ue=H.sticks[me];if(!ue)continue;let Ze=new C(F.axes[ue.x],F.axes[ue.y]);se.stickState.set(me,Ze),e.mergedGamepadState.stickState.set(me,Ze),e.events.trigger("gamepadStick",me,Ze,B)}}}}a($n,"processGamepad");let Se={},Is={},Yr={},_n=t.pixelDensity||1;Se.mousemove=m=>{let q=new C(m.offsetX,m.offsetY),B=new C(m.movementX,m.movementY);if(w()){let F=e.canvas.width/_n,H=e.canvas.height/_n,se=window.innerWidth,me=window.innerHeight,ue=se/me,Ze=F/H;if(ue>Ze){let He=me/H,Je=(se-F*He)/2;q.x=Le(m.offsetX-Je,0,F*He,0,F),q.y=Le(m.offsetY,0,H*He,0,H)}else{let He=se/F,Je=(me-H*He)/2;q.x=Le(m.offsetX,0,F*He,0,F),q.y=Le(m.offsetY-Je,0,H*He,0,H)}}e.events.onOnce("input",()=>{e.isMouseMoved=true,e.mousePos=q,e.mouseDeltaPos=B,e.events.trigger("mouseMove")})};let ei=["left","middle","right","back","forward"];Se.mousedown=m=>{e.events.onOnce("input",()=>{var B;let q=ei[m.button];q&&(e.lastInputDevice="mouse",e.buttonsByMouse.has(q)&&((B=e.buttonsByMouse.get(q))==null?void 0:B.forEach(F=>{e.buttonState.press(F),e.events.trigger("buttonPress",F)})),e.mouseState.press(q),e.events.trigger("mousePress",q))})},Se.mouseup=m=>{e.events.onOnce("input",()=>{var B;let q=ei[m.button];q&&(e.buttonsByMouse.has(q)&&((B=e.buttonsByMouse.get(q))==null?void 0:B.forEach(F=>{e.buttonState.release(F),e.events.trigger("buttonRelease",F)})),e.mouseState.release(q),e.events.trigger("mouseRelease",q))})};let vl=new Set([" ","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Tab"]),ti={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down"," ":"space"};Se.keydown=m=>{vl.has(m.key)&&m.preventDefault(),e.events.onOnce("input",()=>{var F,H;let q=ti[m.key]||m.key.toLowerCase(),B=m.code;if(q===void 0)throw new Error(`Unknown key: ${m.key}`);q.length===1?(e.events.trigger("charInput",q),e.charInputted.push(q)):q==="space"&&(e.events.trigger("charInput"," "),e.charInputted.push(" ")),m.repeat?(e.keyState.pressRepeat(q),e.events.trigger("keyPressRepeat",q)):(e.lastInputDevice="keyboard",e.buttonsByKey.has(q)&&((F=e.buttonsByKey.get(q))==null?void 0:F.forEach(se=>{e.buttonState.press(se),e.events.trigger("buttonPress",se)})),e.buttonsByKeyCode.has(B)&&((H=e.buttonsByKeyCode.get(B))==null?void 0:H.forEach(se=>{e.buttonState.press(se),e.events.trigger("buttonPress",se)})),e.keyState.press(q),e.events.trigger("keyPressRepeat",q),e.events.trigger("keyPress",q))})},Se.keyup=m=>{e.events.onOnce("input",()=>{var F,H;let q=ti[m.key]||m.key.toLowerCase(),B=m.code;e.buttonsByKey.has(q)&&((F=e.buttonsByKey.get(q))==null?void 0:F.forEach(se=>{e.buttonState.release(se),e.events.trigger("buttonRelease",se)})),e.buttonsByKeyCode.has(B)&&((H=e.buttonsByKeyCode.get(B))==null?void 0:H.forEach(se=>{e.buttonState.release(se),e.events.trigger("buttonRelease",se)})),e.keyState.release(q),e.events.trigger("keyRelease",q)})},Se.touchstart=m=>{m.preventDefault(),e.events.onOnce("input",()=>{var F;let q=[...m.changedTouches],B=e.canvas.getBoundingClientRect();t.touchToMouse!==false&&(e.mousePos=new C(q[0].clientX-B.x,q[0].clientY-B.y),e.lastInputDevice="mouse",e.buttonsByMouse.has("left")&&((F=e.buttonsByMouse.get("left"))==null?void 0:F.forEach(H=>{e.buttonState.press(H),e.events.trigger("buttonPress",H)})),e.mouseState.press("left"),e.events.trigger("mousePress","left")),q.forEach(H=>{e.events.trigger("touchStart",new C(H.clientX-B.x,H.clientY-B.y),H)})})},Se.touchmove=m=>{m.preventDefault(),e.events.onOnce("input",()=>{let q=[...m.changedTouches],B=e.canvas.getBoundingClientRect();if(t.touchToMouse!==false){let F=e.mousePos;e.mousePos=new C(q[0].clientX-B.x,q[0].clientY-B.y),e.mouseDeltaPos=e.mousePos.sub(F),e.events.trigger("mouseMove")}q.forEach(F=>{e.events.trigger("touchMove",new C(F.clientX-B.x,F.clientY-B.y),F)})})},Se.touchend=m=>{e.events.onOnce("input",()=>{var F;let q=[...m.changedTouches],B=e.canvas.getBoundingClientRect();t.touchToMouse!==false&&(e.mousePos=new C(q[0].clientX-B.x,q[0].clientY-B.y),e.mouseDeltaPos=new C(0,0),e.buttonsByMouse.has("left")&&((F=e.buttonsByMouse.get("left"))==null?void 0:F.forEach(H=>{e.buttonState.release(H),e.events.trigger("buttonRelease",H)})),e.mouseState.release("left"),e.events.trigger("mouseRelease","left")),q.forEach(H=>{e.events.trigger("touchEnd",new C(H.clientX-B.x,H.clientY-B.y),H)})})},Se.touchcancel=m=>{e.events.onOnce("input",()=>{let q=[...m.changedTouches],B=e.canvas.getBoundingClientRect();t.touchToMouse!==false&&(e.mousePos=new C(q[0].clientX-B.x,q[0].clientY-B.y),e.mouseState.release("left"),e.events.trigger("mouseRelease","left")),q.forEach(F=>{e.events.trigger("touchEnd",new C(F.clientX-B.x,F.clientY-B.y),F)})})},Se.wheel=m=>{m.preventDefault(),e.events.onOnce("input",()=>{e.events.trigger("scroll",new C(m.deltaX,m.deltaY))})},Se.contextmenu=m=>m.preventDefault(),Is.visibilitychange=()=>{document.visibilityState==="visible"?(e.skipTime=true,e.isHidden=false,e.events.trigger("show")):(e.isHidden=true,e.events.trigger("hide"))},Yr.gamepadconnected=m=>{let q=ks(m.gamepad);e.events.onOnce("input",()=>{e.events.trigger("gamepadConnect",q)})},Yr.gamepaddisconnected=m=>{let q=Tt().filter(B=>B.index===m.gamepad.index)[0];Jn(m.gamepad),e.events.onOnce("input",()=>{e.events.trigger("gamepadDisconnect",q)})};for(let[m,q]of Object.entries(Se))e.canvas.addEventListener(m,q);for(let[m,q]of Object.entries(Is))document.addEventListener(m,q);for(let[m,q]of Object.entries(Yr))window.addEventListener(m,q);let ri=new ResizeObserver(m=>{for(let q of m)if(q.target===e.canvas){if(e.lastWidth===e.canvas.offsetWidth&&e.lastHeight===e.canvas.offsetHeight)return;e.lastWidth=e.canvas.offsetWidth,e.lastHeight=e.canvas.offsetHeight,e.events.onOnce("input",()=>{e.events.trigger("resize")})}});return ri.observe(e.canvas),{state:e,dt:r,fixedDt:s,restDt:n,time:o,run:P,canvas:e.canvas,fps:d,numFrames:l,quit:R,isHidden:i,setFullscreen:g,isFullscreen:w,setCursor:f,screenshot:u,getGamepads:Tt,getCursor:x,setCursorLocked:h,isCursorLocked:y,isTouchscreen:O,mousePos:T,mouseDeltaPos:A,isKeyDown:N,isKeyPressed:D,isKeyPressedRepeat:U,isKeyReleased:j,isMouseDown:M,isMousePressed:v,isMouseReleased:k,isMouseMoved:I,isGamepadButtonPressed:z,isGamepadButtonDown:V,isGamepadButtonReleased:Y,getGamepadStick:De,isButtonPressed:ee,isButtonDown:J,isButtonReleased:W,setButton:G,getButton:le,pressButton:Xe,releaseButton:nt,charInputted:ze,onResize:It,onKeyDown:pr,onKeyPress:mr,onKeyPressRepeat:Gr,onKeyRelease:Hr,onMouseDown:Ft,onMousePress:Ge,onMouseRelease:jr,onMouseMove:vt,onCharInput:L,onTouchStart:K,onTouchMove:Q,onTouchEnd:re,onScroll:ce,onHide:$,onShow:ye,onGamepadButtonDown:Rs,onGamepadButtonPress:it,onGamepadButtonRelease:Ps,onGamepadStick:Vr,onGamepadConnect:Kr,onGamepadDisconnect:wr,onButtonPress:Ie,onButtonDown:yr,onButtonRelease:We,getLastInputDeviceType:Wl,events:e.events}},"initApp");function ge(){return c.app.dt()}a(ge,"dt");function ss(){return c.app.fixedDt()}a(ss,"fixedDt");function ns(){return c.app.restDt()}a(ns,"restDt");var tu=new C(-1,-1);var ru=new C(0,-1);var su=new C(1,-1);var nu=new C(-1,0);var iu=new C(0,0);var au=new C(1,0);var ou=new C(-1,1);var lu=new C(0,1);var uu=new C(1,1);function Pt(t){switch(t){case"topleft":return tu;case"top":return ru;case"topright":return su;case"left":return nu;case"center":return iu;case"right":return au;case"botleft":return ou;case"bot":return lu;case"botright":return uu;default:return t}}a(Pt,"anchorPt");function ya(t){switch(t){case"left":return 0;case"center":return .5;case"right":return 1;default:return 0}}a(ya,"alignPt");function Aa(t){return t.createBuffer(1,1,44100)}a(Aa,"createEmptyAudioBuffer");var Xr=2.5949095;var ai=1.70158+1;var oi=2*Math.PI/3;var li=2*Math.PI/4.5;var $r={linear:a(t=>t,"linear"),easeInSine:a(t=>1-Math.cos(t*Math.PI/2),"easeInSine"),easeOutSine:a(t=>Math.sin(t*Math.PI/2),"easeOutSine"),easeInOutSine:a(t=>-(Math.cos(Math.PI*t)-1)/2,"easeInOutSine"),easeInQuad:a(t=>t*t,"easeInQuad"),easeOutQuad:a(t=>1-(1-t)*(1-t),"easeOutQuad"),easeInOutQuad:a(t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,"easeInOutQuad"),easeInCubic:a(t=>t*t*t,"easeInCubic"),easeOutCubic:a(t=>1-Math.pow(1-t,3),"easeOutCubic"),easeInOutCubic:a(t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,"easeInOutCubic"),easeInQuart:a(t=>t*t*t*t,"easeInQuart"),easeOutQuart:a(t=>1-Math.pow(1-t,4),"easeOutQuart"),easeInOutQuart:a(t=>t<.5?8*t*t*t*t:1-Math.pow(-2*t+2,4)/2,"easeInOutQuart"),easeInQuint:a(t=>t*t*t*t*t,"easeInQuint"),easeOutQuint:a(t=>1-Math.pow(1-t,5),"easeOutQuint"),easeInOutQuint:a(t=>t<.5?16*t*t*t*t*t:1-Math.pow(-2*t+2,5)/2,"easeInOutQuint"),easeInExpo:a(t=>t===0?0:Math.pow(2,10*t-10),"easeInExpo"),easeOutExpo:a(t=>t===1?1:1-Math.pow(2,-10*t),"easeOutExpo"),easeInOutExpo:a(t=>t===0?0:t===1?1:t<.5?Math.pow(2,20*t-10)/2:(2-Math.pow(2,-20*t+10))/2,"easeInOutExpo"),easeInCirc:a(t=>1-Math.sqrt(1-Math.pow(t,2)),"easeInCirc"),easeOutCirc:a(t=>Math.sqrt(1-Math.pow(t-1,2)),"easeOutCirc"),easeInOutCirc:a(t=>t<.5?(1-Math.sqrt(1-Math.pow(2*t,2)))/2:(Math.sqrt(1-Math.pow(-2*t+2,2))+1)/2,"easeInOutCirc"),easeInBack:a(t=>ai*t*t*t-1.70158*t*t,"easeInBack"),easeOutBack:a(t=>1+ai*Math.pow(t-1,3)+1.70158*Math.pow(t-1,2),"easeOutBack"),easeInOutBack:a(t=>t<.5?Math.pow(2*t,2)*((Xr+1)*2*t-Xr)/2:(Math.pow(2*t-2,2)*((Xr+1)*(t*2-2)+Xr)+2)/2,"easeInOutBack"),easeInElastic:a(t=>t===0?0:t===1?1:-Math.pow(2,10*t-10)*Math.sin((t*10-10.75)*oi),"easeInElastic"),easeOutElastic:a(t=>t===0?0:t===1?1:Math.pow(2,-10*t)*Math.sin((t*10-.75)*oi)+1,"easeOutElastic"),easeInOutElastic:a(t=>t===0?0:t===1?1:t<.5?-(Math.pow(2,20*t-10)*Math.sin((20*t-11.125)*li))/2:Math.pow(2,-20*t+10)*Math.sin((20*t-11.125)*li)/2+1,"easeInOutElastic"),easeInBounce:a(t=>1-$r.easeOutBounce(1-t),"easeInBounce"),easeOutBounce:a(t=>t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375,"easeOutBounce"),easeInOutBounce:a(t=>t<.5?(1-$r.easeOutBounce(1-2*t))/2:(1+$r.easeOutBounce(2*t-1))/2,"easeInOutBounce")};var qr=$r;function xa(t,e,r){let s=[],n=e;for(s.push(n);n!==t;){if(n=r.get(n),n==null)return null;s.push(n)}return s.reverse()}a(xa,"buildPath");function va(t,e,r){var o;let s=new ra((d,l)=>d.coste.y!=s.a.y>e.y&&e.x<(s.a.x-s.b.x)*(e.y-s.b.y)/(s.a.y-s.b.y)+s.b.x&&(r=!r);return r}},a($t,"NavPolygon"),$t);var _t;var cu=(_t=class{constructor(){b(this,"_polygons");b(this,"_pointCache");b(this,"_edgeCache");this._polygons=[],this._pointCache={},this._edgeCache={}}_addPoint(e){let r=this._pointCache[`${e.x}_${e.y}`];return r||(r=e.clone(),this._pointCache[`${e.x}_${e.y}`]=r,r)}_addEdge(e){let r=`${e.a.x}_${e.a.y}-${e.b.x}_${e.b.y}`;return this._edgeCache[r]=e,e}_findEdge(e,r){let s=`${e.x}_${e.y}-${r.x}_${r.y}`;return this._edgeCache[s]}_findCommonEdge(e,r){for(let s of e.edges){let n=this._findEdge(s.b,s.a);if(n&&n.polygon.deref().id===r.id)return n}return null}addPolygon(e){let r=new du(this._polygons.length),s=e.map((n,i)=>new hu(n,e[(i+1)%e.length],r));r.edges=s,this._polygons.push(r);for(let n of r.edges)this._addEdge(n);return r}addRect(e,r){let s=this._addPoint(e),n=this._addPoint(e.add(r.x,0)),i=this._addPoint(e.add(r)),o=this._addPoint(e.add(0,r.y));return this.addPolygon([s,n,i,o])}_getLocation(e){for(let r of this._polygons)if(r.contains(e))return r;return null}getNeighbours(e){let r=[];for(let s of this._polygons[e].edges){let n=this._findEdge(s.b,s.a);if(n){let i=n.polygon.deref();i&&r.push(i.id)}}return r}getCost(e,r){return 1}getHeuristic(e,r){let s=this._polygons[e],n=this._polygons[r],i=s.centroid.x-n.centroid.x,o=s.centroid.y-n.centroid.y;return Math.sqrt(i*i+o*o)}getPath(e,r){return e===void 0||r===void 0?[]:e===r?[e,r]:va(this,e,r)}getWaypointPath(e,r,s){let n=(s==null?void 0:s.type)||"centroids",i=this._getLocation(e),o=this._getLocation(r);if(i===void 0||o===void 0)return[];let d=this.getPath(i.id,o.id);if(!d)return[];if(n==="edges"){let l=[];for(let u=1;uthis._polygons[l].centroid),r]}},a(_t,"NavMesh"),_t);function Gt(t){let e=new Qe;return t.pos&&e.translate(t.pos),t.scale&&e.scale(t.scale),t.angle&&e.rotate(t.angle),t.parent?e.mult(t.parent.transform):e}a(Gt,"calcTransform");function ba(t){return new C(t.x/pe()*2-1,-t.y/we()*2+1)}a(ba,"screen2ndc");function Lt(t,e,r,s,n,i=1){s=de(s%360),n=de(n%360),n<=s&&(n+=Math.PI*2);let o=[],d=Math.ceil((n-s)/de(8)*i),l=(n-s)/d,u=E(Math.cos(s),Math.sin(s)),f=E(Math.cos(l),Math.sin(l));for(let x=0;x<=d;x++)o.push(t.add(e*u.x,r*u.y)),u=E(u.x*f.x-u.y*f.y,u.x*f.y+u.y*f.x);return o}a(Lt,"getArcPts");function Ea(...t){let e=_(...t),r=t[3]??1;c.gfx.bgColor=e,c.gfx.bgAlpha=r,c.gfx.ggl.gl.clearColor(e.r/255,e.g/255,e.b/255,r)}a(Ea,"setBackground");function Ma(){var t,e;return((e=(t=c.gfx.bgColor)==null?void 0:t.clone)==null?void 0:e.call(t))??null}a(Ma,"getBackground");function ae(...t){if(t[0]===void 0)return;let e=E(...t);e.x===0&&e.y===0||c.gfx.transform.translate(e)}a(ae,"pushTranslate");function qe(){c.gfx.transformStack.push(c.gfx.transform.clone())}a(qe,"pushTransform");function Sa(t){c.gfx.transform=t.clone()}a(Sa,"pushMatrix");function dr(...t){if(t[0]===void 0)return;let e=E(...t);e.x===1&&e.y===1||c.gfx.transform.scale(e)}a(dr,"pushScale");function Ct(t){t&&c.gfx.transform.rotate(t)}a(Ct,"pushRotate");function ve(){c.gfx.transformStack.length>0&&(c.gfx.transform=c.gfx.transformStack.pop())}a(ve,"popTransform");function Ce(){c.gfx.renderer.flush()}a(Ce,"flush");function pe(){return c.gfx.width}a(pe,"width");function we(){return c.gfx.height}a(we,"height");function dn(){return(c.gfx.viewport.width+c.gfx.viewport.height)/(c.gfx.width+c.gfx.height)}a(dn,"getViewportScale");function qa(t){return new C(t.x*c.gfx.viewport.width/c.gfx.width,t.y*c.gfx.viewport.height/c.gfx.height)}a(qa,"contentToView");function Ca(t){return new C((t.x-c.gfx.viewport.x)*pe()/c.gfx.viewport.width,(t.y-c.gfx.viewport.y)*we()/c.gfx.viewport.height)}a(Ca,"windowToContent");function cn(){return Ca(c.app.mousePos())}a(cn,"mousePos");function Cr(){return E(pe()/2,we()/2)}a(Cr,"center");var er;var fu=(er=class{constructor(e,r,s,n){b(this,"lastTextureId",0);b(this,"textures",[]);b(this,"bigTextures",[]);b(this,"texturesPosition",new Map);b(this,"canvas");b(this,"c2d");b(this,"x",0);b(this,"y",0);b(this,"curHeight",0);b(this,"gfx");b(this,"padding");this.gfx=e,this.canvas=document.createElement("canvas"),this.canvas.width=r,this.canvas.height=s,this.textures=[lt.fromImage(e,this.canvas)],this.bigTextures=[],this.padding=n;let i=this.canvas.getContext("2d");if(!i)throw new Error("Failed to get 2d context");this.c2d=i}add(e){let r=e.width+this.padding*2,s=e.height+this.padding*2;if(r>this.canvas.width||s>this.canvas.height){let o=lt.fromImage(this.gfx,e);return this.bigTextures.push(o),[o,new oe(0,0,1,1),0]}this.x+r>this.canvas.width&&(this.x=0,this.y+=this.curHeight,this.curHeight=0),this.y+s>this.canvas.height&&(this.c2d.clearRect(0,0,this.canvas.width,this.canvas.height),this.textures.push(lt.fromImage(this.gfx,this.canvas)),this.x=0,this.y=0,this.curHeight=0);let n=this.textures[this.textures.length-1],i=new C(this.x+this.padding,this.y+this.padding);return this.x+=r,s>this.curHeight&&(this.curHeight=s),e instanceof ImageData?this.c2d.putImageData(e,i.x,i.y):this.c2d.drawImage(e,i.x,i.y),n.update(this.canvas),this.texturesPosition.set(this.lastTextureId,{position:i,size:new C(e.width,e.height),texture:n}),this.lastTextureId++,[n,new oe(i.x/this.canvas.width,i.y/this.canvas.height,e.width/this.canvas.width,e.height/this.canvas.height),this.lastTextureId-1]}free(){for(let e of this.textures)e.free();for(let e of this.bigTextures)e.free()}},a(er,"TexPacker"),er);function Pe(t){return typeof t!="string"||aa(t)?t:c.assets.urlPrefix+t}a(Pe,"fixURL");var St;var Te=(St=class{constructor(e){b(this,"loaded",false);b(this,"data",null);b(this,"error",null);b(this,"onLoadEvents",new xe);b(this,"onErrorEvents",new xe);b(this,"onFinishEvents",new xe);e.then(r=>{this.loaded=true,this.data=r,this.onLoadEvents.trigger(r)}).catch(r=>{if(this.error=r,this.onErrorEvents.numListeners()>0)this.onErrorEvents.trigger(r);else throw r}).finally(()=>{this.onFinishEvents.trigger(),this.loaded=true})}static loaded(e){let r=new St(Promise.resolve(e));return r.data=e,r.loaded=true,r}onLoad(e){return this.loaded&&this.data?e(this.data):this.onLoadEvents.add(e),this}onError(e){return this.loaded&&this.error?e(this.error):this.onErrorEvents.add(e),this}onFinish(e){return this.loaded?e():this.onFinishEvents.add(e),this}then(e){return this.onLoad(e)}catch(e){return this.onError(e)}finally(e){return this.onFinish(e)}},a(St,"Asset"),St);var tr;var Dt=(tr=class{constructor(){b(this,"assets",new Map);b(this,"lastUID",0)}add(e,r){let s=e??this.lastUID+++"",n=new Te(r);return this.assets.set(s,n),n}addLoaded(e,r){let s=e??this.lastUID+++"",n=Te.loaded(r);return this.assets.set(s,n),n}get(e){return this.assets.get(e)}progress(){if(this.assets.size===0)return 1;let e=0;return this.assets.forEach(r=>{r.loaded&&e++}),e/this.assets.size}getFailedAssets(){return Array.from(this.assets.keys()).filter(e=>this.assets.get(e).error!==null).map(e=>[e,this.assets.get(e)])}},a(tr,"AssetBucket"),tr);function Ms(t){return fetch(t).then(e=>{if(!e.ok)throw new Error(`Failed to fetch "${t}"`);return e})}a(Ms,"fetchURL");function Ur(t){return Ms(t).then(e=>e.json())}a(Ur,"fetchJSON");function Ba(t){return Ms(t).then(e=>e.text())}a(Ba,"fetchText");function Ra(t){return Ms(t).then(e=>e.arrayBuffer())}a(Ra,"fetchArrayBuffer");function Pa(t){return t!==void 0&&(c.assets.urlPrefix=t),c.assets.urlPrefix}a(Pa,"loadRoot");function ka(t,e){return c.assets.custom.add(t,Ur(Pe(e)))}a(ka,"loadJSON");function Lr(t){let e=new Image;return e.crossOrigin="anonymous",e.src=t,new Promise((r,s)=>{e.onload=()=>r(e),e.onerror=()=>s(new Error(`Failed to load image from "${t}"`))})}a(Lr,"loadImg");function pt(){let t=[c.assets.sprites,c.assets.sounds,c.assets.shaders,c.assets.fonts,c.assets.bitmapFonts,c.assets.custom];return t.reduce((e,r)=>e+r.progress(),0)/t.length}a(pt,"loadProgress");function fn(){return[c.assets.sprites,c.assets.sounds,c.assets.shaders,c.assets.fonts,c.assets.bitmapFonts,c.assets.custom].reduce((t,e)=>t.concat(e.getFailedAssets()),[])}a(fn,"getFailedAssets");function Ia(t){return c.assets.custom.get(t)??null}a(Ia,"getAsset");function is(t){return c.assets.custom.add(null,t)}a(is,"load");var gu=a((t,e)=>({urlPrefix:"",sprites:new Dt,fonts:new Dt,bitmapFonts:new Dt,sounds:new Dt,shaders:new Dt,custom:new Dt,music:{},packer:new fu(t,2048,2048,e),loaded:false}),"initAssets");var pu="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD0AAAA1CAYAAADyMeOEAAAAAXNSR0IArs4c6QAAAoVJREFUaIHdm7txwkAQhheGAqACiCHzOKQDQrqgILpwSAeEDBnEUAF0gCMxZ7G72qce/mec2Lpf9+3unaS78wgSNZ8uX5729+d1FNWXUuGmXlBOUUEIMckEpeQJgBu6C+BSFngztBR2vd+ovY+7g+p6LbgaWgJrAeUkDYIUXgXdBBwNi6kpABJwMTQH3AZsXRR8GHTfgEth8E3gjdAUcNewpbTgY85sCMCUuOokozE0YM0YRzM9NGAAXd8+omAF5h4lnmBRvpSnZHyLoLEbaN+aKB9KWv/KWw0tAbbANnlG+UvB2dm77NxxdwgBpjrF/d7rW9cbmpvio2A5z8iAYpVU8pGZlo6/2+MSco2lHfd3rv9jAP038e1xef9o2mjvYb2OqpqKE81028/jeietlSEVO5FRWsxWsJit1G3aFpW8iWe5RwpiCZAk25QvV6nz6fIlynRGuTd5WqpJ4guAlDfVKBK87hXljflgv1ON6fV+4+5gVlA17SfeG0heKqQd4l4jI/wrmaA9N9R4ar+wpHJDZyrrfcH0nB66PqAzPi76pn+faSyJk/vzOorYhGurQrzj/P68jtBMawHaHBIR9xoD5O34dy0qQOSYHvqExq2TpT2nf76+w7y251OYF0CRaU+J920TwLUa6inx6OxE6g80lu2ux7Y2eJLF/rCXE6zEPdnenk9o+4ih9AEdnW2q81HXl5LuU6OTl2fXUhqganbXAGq3g6jJOWV/OnoesO6YqqEB/GdNsjf7uHtwj2DzmRNpp7iOZfm6D9oAxB6Yi1gC4oIYeo4MIPdopEQRB+cAko5J1tW386HpB2Kz1eop4Epdwls/kgZ1sh8gZsEjdcWkr//D8Qu3Z3l5Nl1NtAAAAABJRU5ErkJggg==";var Ye;var mt=(Ye=class{constructor(e,r,s={},n=null){b(this,"tex");b(this,"frames",[new oe(0,0,1,1)]);b(this,"anims",{});b(this,"slice9",null);this.tex=e,r&&(this.frames=r),this.anims=s,this.slice9=n}get width(){return this.tex.width*this.frames[0].w}get height(){return this.tex.height*this.frames[0].h}static from(e,r={}){return typeof e=="string"?Ye.fromURL(e,r):Promise.resolve(Ye.fromImage(e,r))}static fromImage(e,r={}){let[s,n]=c.assets.packer.add(e),i=r.frames?r.frames.map(o=>new oe(n.x+o.x*n.w,n.y+o.y*n.h,o.w*n.w,o.h*n.h)):pn(r.sliceX||1,r.sliceY||1,n.x,n.y,n.w,n.h);return new Ye(s,i,r.anims,r.slice9)}static fromURL(e,r={}){return Lr(e).then(s=>Ye.fromImage(s,r))}},a(Ye,"SpriteData"),Ye);function br(t){if(typeof t=="string"){let e=gn(t);if(e)return e;if(pt()<1)return null;throw new Error(`Sprite not found: ${t}`)}else{if(t instanceof mt)return Te.loaded(t);if(t instanceof Te)return t;throw new Error(`Invalid sprite: ${t}`)}}a(br,"resolveSprite");function gn(t){return c.assets.sprites.get(t)??null}a(gn,"getSprite");function Ht(t,e,r={sliceX:1,sliceY:1,anims:{}}){return e=Pe(e),Array.isArray(e)?e.some(s=>typeof s=="string")?c.assets.sprites.add(t,Promise.all(e.map(s=>typeof s=="string"?Lr(s):Promise.resolve(s))).then(s=>Gs(s,r))):c.assets.sprites.addLoaded(t,Gs(e,r)):typeof e=="string"?c.assets.sprites.add(t,mt.from(e,r)):c.assets.sprites.addLoaded(t,mt.fromImage(e,r))}a(Ht,"loadSprite");function pn(t=1,e=1,r=0,s=0,n=1,i=1){let o=[],d=n/t,l=i/e;for(let u=0;u{d instanceof ImageData?i.putImageData(d,l*s,0):i.drawImage(d,l*s,0)});let o=i.getImageData(0,0,t.length*s,n);return mt.fromImage(o,{...e,sliceX:t.length,sliceY:1})}a(Gs,"createSpriteSheet");function Fa(t="bean"){return Ht(t,pu)}a(Fa,"loadBean");function Ta(t,e,r){e=Pe(e),r=Pe(r),typeof e=="string"&&!r&&(r=Kl(e)+".json");let s=typeof r=="string"?Ur(r):Promise.resolve(r);return c.assets.sprites.add(t,s.then(n=>{let i=n.meta.size,o=n.frames.map(l=>new oe(l.frame.x/i.w,l.frame.y/i.h,l.frame.w/i.w,l.frame.h/i.h)),d={};for(let l of n.meta.frameTags)l.from===l.to?d[l.name]=l.from:d[l.name]={from:l.from,to:l.to,speed:10,loop:true,pingpong:l.direction==="pingpong"};return mt.from(e,{frames:o,anims:d})}))}a(Ta,"loadAseprite");var rr;var _r=(rr=class{constructor(e,r={}){b(this,"fontface");b(this,"filter",Ds);b(this,"outline",null);b(this,"size",64);if(this.fontface=e,this.filter=r.filter??Ds,this.size=r.size??64,this.size>256)throw new Error(`Max font size: ${256}`);r.outline&&(this.outline={width:1,color:_(0,0,0)},typeof r.outline=="number"?this.outline.width=r.outline:typeof r.outline=="object"&&(r.outline.width&&(this.outline.width=r.outline.width),r.outline.color&&(this.outline.color=r.outline.color)))}},a(rr,"FontData"),rr);function mn(t){if(!t)return mn(c.globalOpt.font??Pl);if(typeof t=="string"){let e=yn(t),r=wn(t);if(e)return e.data??e;if(r)return r.data??r;if(document.fonts.check(`${64}px ${t}`))return t;if(pt()<1)return null;throw new Error(`Font not found: ${t}`)}else if(t instanceof Te)return t.data?t.data:t;return t}a(mn,"resolveFont");function wn(t){return c.assets.fonts.get(t)??null}a(wn,"getFont");function Da(t,e,r={}){let s=Pe(e),n=new FontFace(t,typeof e=="string"?`url(${s})`:s);return document.fonts.add(n),c.assets.fonts.add(t,n.load().catch(i=>{throw new Error(`Failed to load font from "${s}": ${i}`)}).then(i=>new _r(i,r)))}a(Da,"loadFont");function Oa(t,e,r,s){let n=t.width/e,i={},o=s.split("").entries();for(let[d,l]of o)i[l]=new oe(d%n*e,Math.floor(d/n)*r,e,r);return{tex:t,map:i,size:r}}a(Oa,"makeFont");function yn(t){return c.assets.bitmapFonts.get(t)??null}a(yn,"getBitmapFont");function Ua(t,e,r,s,n={}){let i=Pe(e);return c.assets.bitmapFonts.add(t,Lr(i).then(o=>Oa(lt.fromImage(c.gfx.ggl,o,n),r,s,n.chars??$i)))}a(Ua,"loadBitmapFont");function La(t,e){return e=Pe(e),c.assets.sprites.add(t,new Promise(async r=>{let s=typeof e=="string"?await Ur(e):e,n=await Promise.all(s.frames.map(Lr)),i=document.createElement("canvas");i.width=s.width,i.height=s.height*s.frames.length;let o=i.getContext("2d");if(!o)throw new Error("Failed to create canvas context");n.forEach((l,u)=>{o.drawImage(l,0,u*s.height)});let d=await Ht(null,i,{sliceY:s.frames.length,anims:s.anims});r(d)}))}a(La,"loadPedit");var sr;var mu=(sr=class{constructor(e,r,s,n){b(this,"ctx");b(this,"glProgram");this.ctx=e,e.onDestroy(()=>this.free());let i=e.gl,o=i.createShader(i.VERTEX_SHADER),d=i.createShader(i.FRAGMENT_SHADER);if(!o||!d)throw new Error("Failed to create shader");i.shaderSource(o,r),i.shaderSource(d,s),i.compileShader(o),i.compileShader(d);let l=i.createProgram();if(this.glProgram=l,i.attachShader(l,o),i.attachShader(l,d),n.forEach((u,f)=>i.bindAttribLocation(l,f,u)),i.linkProgram(l),!i.getProgramParameter(l,i.LINK_STATUS)){let u=i.getShaderInfoLog(o);if(u)throw new Error("VERTEX SHADER "+u);let f=i.getShaderInfoLog(d);if(f)throw new Error("FRAGMENT SHADER "+f)}i.deleteShader(o),i.deleteShader(d)}bind(){this.ctx.pushProgram(this.glProgram)}unbind(){this.ctx.popProgram()}send(e){let r=this.ctx.gl;for(let s in e){let n=e[s],i=r.getUniformLocation(this.glProgram,s);if(typeof n=="number")r.uniform1f(i,n);else if(n instanceof Qe)r.uniformMatrix4fv(i,false,new Float32Array(n.m));else if(n instanceof X)r.uniform3f(i,n.r,n.g,n.b);else if(n instanceof C)r.uniform2f(i,n.x,n.y);else if(Array.isArray(n)){n[0];Vl(n)?r.uniform1fv(i,n):jl(n)?r.uniform2fv(i,n.map(o=>[o.x,o.y]).flat()):Hl(n)&&r.uniform3fv(i,n.map(o=>[o.r,o.g,o.b]).flat())}else throw new Error("Unsupported uniform data type")}}free(){this.ctx.gl.deleteProgram(this.glProgram)}},a(sr,"Shader"),sr);function Ss(t,e=Os,r=Us){let s=Tl.replace("{{user}}",e??Os),n=Dl.replace("{{user}}",r??Us);try{return new mu(t,s,n,un.map(i=>i.name))}catch(i){let o=/(?^\w+) SHADER ERROR: 0:(?\d+): (?.+)/,d=Yl(i).match(o);if(!(d==null?void 0:d.groups))throw i;let l=Number(d.groups.line)-14,u=d.groups.msg.trim(),f=d.groups.type.toLowerCase();throw new Error(`${f} shader line ${l}: ${u}`)}}a(Ss,"makeShader");function Na(t){if(!t)return c.gfx.defShader;if(typeof t=="string"){let e=An(t);if(e)return e.data??e;if(pt()<1)return null;throw new Error(`Shader not found: ${t}`)}else if(t instanceof Te)return t.data?t.data:t;return t}a(Na,"resolveShader");function An(t){return c.assets.shaders.get(t)??null}a(An,"getShader");function Ga(t,e,r){return c.assets.shaders.addLoaded(t,Ss(c.gfx.ggl,e,r))}a(Ga,"loadShader");function Ha(t,e,r){e=Pe(e),r=Pe(r);let s=a(i=>i?Ba(i):Promise.resolve(null),"resolveUrl"),n=Promise.all([s(e),s(r)]).then(([i,o])=>Ss(c.gfx.ggl,i,o));return c.assets.shaders.add(t,n)}a(Ha,"loadShaderURL");var _e;var Br=(_e=class{constructor(e){b(this,"buf");this.buf=e}static fromArrayBuffer(e){return new Promise((r,s)=>c.audio.ctx.decodeAudioData(e,r,s)).then(r=>new _e(r))}static fromURL(e){return aa(e)?_e.fromArrayBuffer(na(e)):Ra(e).then(r=>_e.fromArrayBuffer(r))}},a(_e,"SoundData"),_e);function ja(t){if(typeof t=="string"){let e=xn(t);if(e)return e;if(pt()<1)return null;throw new Error(`Sound not found: ${t}`)}else{if(t instanceof Br)return Te.loaded(t);if(t instanceof Te)return t;throw new Error(`Invalid sound: ${t}`)}}a(ja,"resolveSound");function xn(t){return c.assets.sounds.get(t)??null}a(xn,"getSound");function Va(t,e){return e=Pe(e),c.assets.sounds.add(t,typeof e=="string"?Br.fromURL(e):Br.fromArrayBuffer(e))}a(Va,"loadSound");function Ka(t,e){let r=Pe(e),s=new Audio(r);return s.preload="auto",c.assets.music[t]=r}a(Ka,"loadMusic");function vn(t,e){return t=Pe(t),typeof e=="string"?is(new Promise((r,s)=>{Ur(e).then(n=>{vn(t,n).then(r).catch(s)})})):is(mt.from(t).then(r=>{let s={};for(let n in e){let i=e[n],o=r.frames[0],d=2048*o.w,l=2048*o.h,u=i.frames?i.frames.map(x=>new oe(o.x+(i.x+x.x)/d*o.w,o.y+(i.y+x.y)/l*o.h,x.w/d*o.w,x.h/l*o.h)):pn(i.sliceX||1,i.sliceY||1,o.x+i.x/d*o.w,o.y+i.y/l*o.h,i.width/d*o.w,i.height/l*o.h),f=new mt(r.tex,u,i.anims);c.assets.sprites.addLoaded(n,f),s[n]=f}return s}))}a(vn,"loadSpriteAtlas");function st(t,e,r=false,s,n,i={}){let o=s??c.gfx.defTex,d=n??c.gfx.defShader,l=Na(d);if(!l||l instanceof Te)return;let u=c.gfx.fixed||r?c.gfx.transform:c.game.cam.transform.mult(c.gfx.transform),f=[];for(let x of t){let h=ba(u.multVec2(x.pos));f.push(h.x,h.y,x.uv.x,x.uv.y,x.color.r/255,x.color.g/255,x.color.b/255,x.opacity)}c.gfx.renderer.push(c.gfx.ggl.gl.TRIANGLES,f,e,l,o,i)}a(st,"drawRaw");function et(t){if(!t.pts)throw new Error('drawPolygon() requires property "pts".');let e=t.pts.length;if(!(e<3)){if(qe(),ae(t.pos),dr(t.scale),Ct(t.angle),ae(t.offset),t.fill!==false){let r=t.color??X.WHITE,s=t.pts.map((i,o)=>({pos:new C(i.x,i.y),uv:t.uv?t.uv[o]:new C(0,0),color:t.colors&&t.colors[o]?t.colors[o].mult(r):r,opacity:t.opacity??1})),n;t.triangulate?n=ln(t.pts).map(i=>i.map(o=>t.pts.indexOf(o))).flat():n=[...Array(e-2).keys()].map(i=>[0,i+1,i+2]).flat(),st(s,t.indices??n,t.fixed,t.uv?t.tex:c.gfx.defTex,t.shader,t.uniform??void 0)}t.outline&&qs({pts:[...t.pts,t.pts[0]],radius:t.radius,width:t.outline.width,color:t.outline.color,join:t.outline.join,uniform:t.uniform,fixed:t.fixed,opacity:t.opacity??t.outline.opacity}),ve()}}a(et,"drawPolygon");function bn(t){if(t.radiusX===void 0||t.radiusY===void 0)throw new Error('drawEllipse() requires properties "radiusX" and "radiusY".');if(t.radiusX===0||t.radiusY===0)return;let e=t.start??0,r=t.end??360,s=Pt(t.anchor??"center").scale(new C(-t.radiusX,-t.radiusY)),n=Lt(s,t.radiusX,t.radiusY,e,r,t.resolution);n.unshift(s);let i=Object.assign({},t,{pts:n,radius:0,...t.gradient?{colors:[t.gradient[0],...Array(n.length-1).fill(t.gradient[1])]}:{}});if(r-e>=360&&t.outline){t.fill!==false&&et(Object.assign({},i,{outline:null})),et(Object.assign({},i,{pts:n.slice(1),fill:false}));return}et(i)}a(bn,"drawEllipse");function kt(t){if(typeof t.radius!="number")throw new Error('drawCircle() requires property "radius".');t.radius!==0&&bn(Object.assign({},t,{radiusX:t.radius,radiusY:t.radius,angle:0}))}a(kt,"drawCircle");function Nt(t){let{p1:e,p2:r}=t;if(!e||!r)throw new Error('drawLine() requires properties "p1" and "p2".');let s=t.width||1,n=r.sub(e).unit().normal().scale(s*.5),i=[e.sub(n),e.add(n),r.add(n),r.sub(n)].map(o=>({pos:new C(o.x,o.y),uv:new C(0),color:t.color??X.WHITE,opacity:t.opacity??1}));st(i,[0,1,3,1,2,3],t.fixed,c.gfx.defTex,t.shader,t.uniform??void 0)}a(Nt,"drawLine");function Ya(t){let e=t.pts,r=[],s=(t.width||1)*.5,n=e[0]===e[e.length-1]||e[0].eq(e[e.length-1]),i=t.pos||E(0,0),o;n?o=e[0].sub(e[e.length-2]):o=e[1].sub(e[0]);let d=o.len(),l=o.normal().scale(-s/d),u,f=e[0];if(!n)switch(t.cap){case"square":{let p=o.scale(-s/d);r.push(f.add(p).add(l)),r.push(f.add(p).sub(l));break}case"round":{let p=Math.max(s,10),S=Math.PI/p,g=l.scale(-1),w=Math.cos(S),R=Math.sin(S);for(let P=0;P0?(r.push(u.add(O)),r.push(u.sub(l)),r.push(u.add(O)),r.push(u.sub(w))):(r.push(u.add(l)),r.push(u.sub(O)),r.push(u.add(w)),r.push(u.sub(O))),o=S,d=g,l=w}if(!n)switch(r.push(f.add(l)),r.push(f.sub(l)),t.cap){case"square":{let p=o.scale(s/d);r.push(f.add(p).add(l)),r.push(f.add(p).sub(l));break}case"round":{let p=Math.max(s,10),S=Math.PI/p,g=l.scale(1),w=Math.cos(S),R=Math.sin(S);for(let P=0;P({pos:i.add(p),uv:E(),color:t.color||X.WHITE,opacity:t.opacity??1})),h=[],y=0;for(let p=0;p0){let T=u.add(O),A=Math.max(s,10),v=de(l.angleBetween(w)/A),M=l,k=Math.cos(v),I=Math.sin(v);for(let D=0;D({pos:i.add(p),uv:E(),color:t.color||X.WHITE,opacity:t.opacity??1})),h=[],y=0;for(let p=0;p({pos:i.add(p),uv:E(),color:t.color||X.WHITE,opacity:t.opacity??1})),h=[],y=0;for(let p=0;p2)switch(t.join){case"bevel":return Ya(t);case"round":return Qa(t);case"miter":return Xa(t)}if(t.radius&&e.length>=3){Nt(Object.assign({},t,{p1:e[0],p2:e[1]}));for(let s=1;sAs(t.pt1,t.pt2,t.pt3,t.pt4,e),t)}a(za,"drawBezier");var qt;var lt=(qt=class{constructor(e,r,s,n={}){b(this,"ctx");b(this,"src",null);b(this,"glTex");b(this,"width");b(this,"height");this.ctx=e;let i=e.gl,o=e.gl.createTexture();if(!o)throw new Error("Failed to create texture");this.glTex=o,e.onDestroy(()=>this.free()),this.width=r,this.height=s;let d={linear:i.LINEAR,nearest:i.NEAREST}[n.filter??e.opts.texFilter??"nearest"],l={repeat:i.REPEAT,clampToEdge:i.CLAMP_TO_EDGE}[n.wrap??"clampToEdge"];this.bind(),r&&s&&i.texImage2D(i.TEXTURE_2D,0,i.RGBA,r,s,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,d),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,d),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,l),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,l),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,true),this.unbind()}static fromImage(e,r,s={}){let n=new qt(e,r.width,r.height,s);return n.update(r),n.src=r,n}update(e,r=0,s=0){let n=this.ctx.gl;this.bind(),n.texSubImage2D(n.TEXTURE_2D,0,r,s,n.RGBA,n.UNSIGNED_BYTE,e),this.unbind()}bind(){this.ctx.pushTexture2D(this.glTex)}unbind(){this.ctx.popTexture2D()}free(){this.ctx.gl.deleteTexture(this.glTex)}},a(qt,"Texture"),qt);var nr;var as=(nr=class{constructor(e,r,s,n={}){b(this,"ctx");b(this,"tex");b(this,"glFramebuffer");b(this,"glRenderbuffer");this.ctx=e;let i=e.gl;e.onDestroy(()=>this.free()),this.tex=new lt(e,r,s,n);let o=i.createFramebuffer(),d=i.createRenderbuffer();if(!o||!d)throw new Error("Failed to create framebuffer");this.glFramebuffer=o,this.glRenderbuffer=d,this.bind(),i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_STENCIL,r,s),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,this.tex.glTex,0),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.RENDERBUFFER,this.glRenderbuffer),this.unbind()}get width(){return this.tex.width}get height(){return this.tex.height}toImageData(){let e=this.ctx.gl,r=new Uint8ClampedArray(this.width*this.height*4);this.bind(),e.readPixels(0,0,this.width,this.height,e.RGBA,e.UNSIGNED_BYTE,r),this.unbind();let s=this.width*4,n=new Uint8Array(s);for(let i=0;i<(this.height/2|0);i++){let o=i*s,d=(this.height-i-1)*s;n.set(r.subarray(o,o+s)),r.copyWithin(o,d,d+s),r.set(n,d)}return new ImageData(r,this.width,this.height)}toDataURL(){let e=document.createElement("canvas"),r=e.getContext("2d");if(e.width=this.width,e.height=this.height,!r)throw new Error("Failed to get 2d context");return r.putImageData(this.toImageData(),0,0),e.toDataURL()}clear(){let e=this.ctx.gl;e.clear(e.COLOR_BUFFER_BIT)}draw(e){this.bind(),e(),this.unbind()}bind(){this.ctx.pushFramebuffer(this.glFramebuffer),this.ctx.pushRenderbuffer(this.glRenderbuffer),this.ctx.pushViewport({x:0,y:0,w:this.width,h:this.height})}unbind(){this.ctx.popFramebuffer(),this.ctx.popRenderbuffer(),this.ctx.popViewport()}free(){let e=this.ctx.gl;e.deleteFramebuffer(this.glFramebuffer),e.deleteRenderbuffer(this.glRenderbuffer),this.tex.free()}},a(nr,"FrameBuffer"),nr);var ir;var wu=(ir=class{constructor(e,r,s,n){b(this,"ctx");b(this,"glVBuf");b(this,"glIBuf");b(this,"vqueue",[]);b(this,"iqueue",[]);b(this,"stride");b(this,"maxVertices");b(this,"maxIndices");b(this,"vertexFormat");b(this,"numDraws",0);b(this,"curPrimitive",null);b(this,"curTex",null);b(this,"curShader",null);b(this,"curUniform",{});let i=e.gl;this.vertexFormat=r,this.ctx=e,this.stride=r.reduce((d,l)=>d+l.size,0),this.maxVertices=s,this.maxIndices=n;let o=i.createBuffer();if(!o)throw new Error("Failed to create vertex buffer");this.glVBuf=o,e.pushArrayBuffer(this.glVBuf),i.bufferData(i.ARRAY_BUFFER,s*4,i.DYNAMIC_DRAW),e.popArrayBuffer(),this.glIBuf=i.createBuffer(),e.pushElementArrayBuffer(this.glIBuf),i.bufferData(i.ELEMENT_ARRAY_BUFFER,n*4,i.DYNAMIC_DRAW),e.popElementArrayBuffer()}push(e,r,s,n,i=null,o={}){(e!==this.curPrimitive||i!==this.curTex||n!==this.curShader||!bs(this.curUniform,o)||this.vqueue.length+r.length*this.stride>this.maxVertices||this.iqueue.length+s.length>this.maxIndices)&&this.flush();let d=this.vqueue.length/this.stride;for(let l of r)this.vqueue.push(l);for(let l of s)this.iqueue.push(l+d);this.curPrimitive=e,this.curShader=n,this.curTex=i,this.curUniform=o}flush(){var r,s;if(!this.curPrimitive||!this.curShader||this.vqueue.length===0||this.iqueue.length===0)return;let e=this.ctx.gl;this.ctx.pushArrayBuffer(this.glVBuf),e.bufferSubData(e.ARRAY_BUFFER,0,new Float32Array(this.vqueue)),this.ctx.pushElementArrayBuffer(this.glIBuf),e.bufferSubData(e.ELEMENT_ARRAY_BUFFER,0,new Uint16Array(this.iqueue)),this.ctx.setVertexFormat(this.vertexFormat),this.curShader.bind(),this.curShader.send(this.curUniform),(r=this.curTex)==null?void 0:r.bind(),e.drawElements(this.curPrimitive,this.iqueue.length,e.UNSIGNED_SHORT,0),(s=this.curTex)==null?void 0:s.unbind(),this.curShader.unbind(),this.ctx.popArrayBuffer(),this.ctx.popElementArrayBuffer(),this.vqueue=[],this.iqueue=[],this.numDraws++}free(){let e=this.ctx.gl;e.deleteBuffer(this.glVBuf),e.deleteBuffer(this.glIBuf)}},a(ir,"BatchRenderer"),ir);function at(t){let e=[],r=a(i=>{e.push(i),t(i)},"push"),s=a(()=>{e.pop(),t(n()??null)},"pop"),n=a(()=>e[e.length-1],"cur");return[r,s,n]}a(at,"genStack");function Wa(t,e={}){let r=[];function s(T){r.push(T)}a(s,"onDestroy");function n(){r.forEach(A=>A());let T=t.getExtension("WEBGL_lose_context");T&&T.loseContext()}a(n,"destroy");let i=null;function o(T){if(bs(T,i))return;i=T;let A=T.reduce((v,M)=>v+M.size,0);T.reduce((v,M,k)=>(t.vertexAttribPointer(k,M.size,t.FLOAT,false,A*4,v),t.enableVertexAttribArray(k),v+M.size*4),0)}a(o,"setVertexFormat");let[d,l]=at(T=>t.bindTexture(t.TEXTURE_2D,T)),[u,f]=at(T=>t.bindBuffer(t.ARRAY_BUFFER,T)),[x,h]=at(T=>t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,T)),[y,p]=at(T=>t.bindFramebuffer(t.FRAMEBUFFER,T)),[S,g]=at(T=>t.bindRenderbuffer(t.RENDERBUFFER,T)),[w,R]=at(T=>{if(!T)return;let{x:A,y:v,w:M,h:k}=T;t.viewport(A,v,M,k)}),[P,O]=at(T=>t.useProgram(T));return w({x:0,y:0,w:t.drawingBufferWidth,h:t.drawingBufferHeight}),{gl:t,opts:e,onDestroy:s,destroy:n,pushTexture2D:d,popTexture2D:l,pushArrayBuffer:u,popArrayBuffer:f,pushElementArrayBuffer:x,popElementArrayBuffer:h,pushFramebuffer:y,popFramebuffer:p,pushRenderbuffer:S,popRenderbuffer:g,pushViewport:w,popViewport:R,pushProgram:P,popProgram:O,setVertexFormat:o}}a(Wa,"initGfx");var Fs={};function Hs(t,e){if(e.override){Object.assign(t,e);return}e.pos&&(t.pos=t.pos.add(e.pos)),e.scale&&(t.scale=t.scale.scale(E(e.scale))),e.angle&&(t.angle+=e.angle),e.color&&t.ch.length===1&&(t.color=t.color.mult(e.color)),e.opacity!=null&&(t.opacity*=e.opacity)}a(Hs,"applyCharTransform");function os(t){let e={},r="",s=[],n=String(t),i=a(o=>{s.length>0&&(e[r.length]=s.slice()),r+=o},"emit");for(;n!=="";){if(n[0]==="\\"){if(n.length===1)throw new Error("Styled text error: \\ at end of string");i(n[1]),n=n.slice(2);continue}if(n[0]==="["){let o=/^\[(\/)?(\w+?)\]/.exec(n);if(!o){i(n[0]),n=n.slice(1);continue}let[d,l,u]=o;if(l!==void 0){let f=s.pop();if(f!==u)throw f!==void 0?new Error(`Styled text error: mismatched tags. Expected [/${f}], got [/${u}]`):new Error(`Styled text error: stray end tag [/${u}]`)}else s.push(u);n=n.slice(d.length);continue}i(n[0]),n=n.slice(1)}if(s.length>0)throw new Error(`Styled text error: unclosed tags ${s}`);return{charStyleMap:e,text:r}}a(os,"compileStyledText");function wt(t){var P,O,T;if(t.text===void 0)throw new Error('formatText() requires property "text".');let e=mn(t.font);if(!t.text||t.text===""||e instanceof Te||!e)return{width:0,height:0,chars:[],opt:t,renderedText:""};let{charStyleMap:r,text:s}=os(t.text+""),n=la(s);if(e instanceof _r||typeof e=="string"){let A=e instanceof _r?e.fontface.family:e,v=e instanceof _r?{outline:e.outline,filter:e.filter}:{outline:null,filter:Ds},M=Fs[A]??{font:{tex:new lt(c.gfx.ggl,2048,2048,{filter:v.filter}),map:{},size:64},cursor:new C(0),maxHeight:0,outline:v.outline};Fs[A]||(Fs[A]=M),e=M.font;for(let k of n)if(!M.font.map[k]){let I=c.fontCacheC2d;if(!I)throw new Error("fontCacheC2d is not defined.");if(!c.fontCacheCanvas)throw new Error("fontCacheCanvas is not defined.");I.clearRect(0,0,c.fontCacheCanvas.width,c.fontCacheCanvas.height),I.font=`${e.size}px ${A}`,I.textBaseline="top",I.textAlign="left",I.fillStyle="#ffffff";let D=I.measureText(k),U=Math.ceil(D.width);if(!U)continue;let N=Math.ceil(Math.abs(D.actualBoundingBoxAscent))+Math.ceil(Math.abs(D.actualBoundingBoxDescent));M.outline&&M.outline.width&&M.outline.color&&(I.lineJoin="round",I.lineWidth=M.outline.width*2,I.strokeStyle=M.outline.color.toHex(),I.strokeText(k,M.outline.width,M.outline.width),U+=M.outline.width*2,N+=M.outline.width*3),I.fillText(k,((P=M.outline)==null?void 0:P.width)??0,((O=M.outline)==null?void 0:O.width)??0);let j=I.getImageData(0,0,U,N);if(M.cursor.x+U>2048&&(M.cursor.x=0,M.cursor.y+=M.maxHeight,M.maxHeight=0,M.cursor.y>2048))throw new Error("Font atlas exceeds character limit");e.tex.update(j,M.cursor.x,M.cursor.y),e.map[k]=new oe(M.cursor.x,M.cursor.y,U,N),M.cursor.x+=U+1,M.maxHeight=Math.max(M.maxHeight,N)}}let i=t.size||e.size,o=E(t.scale??1).scale(i/e.size),d=t.lineSpacing??0,l=t.letterSpacing??0,u=0,f=0,x=0,h=[],y=[],p=0,S=null,g=0,w;for(;pt.width&&(x+=i+d,S!=null&&(p-=y.length-S,A=n[p],v=e.map[A],M=v.w*o.x,y=y.slice(0,S-1),u=g),S=null,g=0,h.push({width:u-l,chars:y}),u=w??0,y=[]),y.push({tex:e.tex,width:v.w,height:v.h,quad:new oe(v.x/e.tex.width,v.y/e.tex.height,v.w/e.tex.width,v.h/e.tex.height),ch:A,pos:new C(u,x),opacity:t.opacity??1,color:t.color??X.WHITE,scale:E(o),angle:0}),A===" "&&(S=y.length,g=u),t.indentAll&&w===void 0&&/\S/.test(A)&&(w=u),u+=M,f=Math.max(f,u),u+=l}}p++}h.push({width:u-l,chars:y}),x+=i,t.width&&(f=t.width);let R=[];for(let A=0;A{cr({tex:e.tex,width:e.width,height:e.height,pos:e.pos,scale:e.scale,angle:e.angle,color:e.color,opacity:e.opacity,quad:e.quad,anchor:"center",uniform:t.opt.uniform,shader:t.opt.shader,fixed:t.opt.fixed})}),ve()}a(yt,"drawFormattedText");function Be(t){if(t.width===void 0||t.height===void 0)throw new Error('drawRect() requires property "width" and "height".');if(t.width<=0||t.height<=0)return;let e=t.width,r=t.height,s=Pt(t.anchor||xs).add(1,1).scale(new C(e,r).scale(-.5)),n=[new C(0,0),new C(e,0),new C(e,r),new C(0,r)];if(t.radius){let i=Math.min(e,r)/2,o=Array.isArray(t.radius)?t.radius.map(d=>Math.min(i,d)):new Array(4).fill(Math.min(i,t.radius));n=[new C(o[0],0),...o[1]?Lt(new C(e-o[1],o[1]),o[1],o[1],270,360):[E(e,0)],...o[2]?Lt(new C(e-o[2],r-o[2]),o[2],o[2],0,90):[E(e,r)],...o[3]?Lt(new C(o[3],r-o[3]),o[3],o[3],90,180):[E(0,r)],...o[0]?Lt(new C(o[0],o[0]),o[0],o[0],180,270):[]]}et(Object.assign({},t,{offset:s,pts:n,...t.gradient?{colors:t.horizontal?[t.gradient[0],t.gradient[1],t.gradient[1],t.gradient[0]]:[t.gradient[0],t.gradient[0],t.gradient[1],t.gradient[1]]}:{}}))}a(Be,"drawRect");function $e(t){Ce();let e=c.gfx.width,r=c.gfx.height;c.gfx.width=c.gfx.viewport.width,c.gfx.height=c.gfx.viewport.height,t(),Ce(),c.gfx.width=e,c.gfx.height=r}a($e,"drawUnscaled");function js(t,e){$e(()=>{let r=E(8);qe(),ae(t);let s=wt({text:e,font:ts,size:16,pos:r,color:_(255,255,255),fixed:true}),n=s.width+r.x*2,i=s.height+r.x*2;t.x+n>=pe()&&ae(E(-n,0)),t.y+i>=we()&&ae(E(0,-i)),Be({width:n,height:i,color:_(0,0,0),radius:4,opacity:.8,fixed:true}),yt(s),ve()})}a(js,"drawInspectText");function Mn(t){if(!t.p1||!t.p2||!t.p3)throw new Error('drawTriangle() requires properties "p1", "p2" and "p3".');return et(Object.assign({},t,{pts:[t.p1,t.p2,t.p3]}))}a(Mn,"drawTriangle");function Za(){if(c.debug.inspect){let t=null;for(let e of c.game.root.get("*",{recursive:true}))if(e.c("area")&&e.isHovering()){t=e;break}if(c.game.root.drawInspect(),t){let e=[],r=t.inspect();for(let s in r)r[s]?e.push(`${r[s]}`):e.push(`${s}`);js(qa(cn()),e.join(` +`))}js(E(8),`FPS: ${c.debug.fps()}`)}c.debug.paused&&$e(()=>{qe(),ae(pe(),0),ae(-8,8);let t=32;Be({width:t,height:t,anchor:"topright",color:_(0,0,0),opacity:.8,radius:4,fixed:true});for(let e=1;e<=2;e++)Be({width:4,height:t*.6,anchor:"center",pos:E(-t/3*e,t*.5),color:_(255,255,255),radius:2,fixed:true});ve()}),c.debug.timeScale!==1&&$e(()=>{qe(),ae(pe(),we()),ae(-8,-8);let t=8,e=wt({text:c.debug.timeScale.toFixed(1),font:ts,size:16,color:_(255,255,255),pos:E(-t),anchor:"botright",fixed:true});Be({width:e.width+t*2+t*4,height:e.height+t*2,anchor:"botright",color:_(0,0,0),opacity:.8,radius:4,fixed:true});for(let r=0;r<2;r++){let s=c.debug.timeScale<1;Mn({p1:E(-e.width-t*(s?2:3.5),-t),p2:E(-e.width-t*(s?2:3.5),-t-e.height),p3:E(-e.width-t*(s?3.5:2),-t-e.height/2),pos:E(-r*t*1+(s?-t*.5:0),0),color:_(255,255,255),fixed:true})}yt(e),ve()}),c.debug.curRecording&&$e(()=>{qe(),ae(0,we()),ae(24,-24),kt({radius:12,color:_(255,0,0),opacity:Xs(0,1,c.app.time()*4),fixed:true}),ve()}),c.debug.showLog&&c.game.logs.length>0&&$e(()=>{qe(),ae(0,we()),ae(8,-8);let t=8,e=[];for(let s of c.game.logs){let n="",i=s.msg instanceof Error?"error":"info";n+=`[time]${s.time.toFixed(2)}[/time]`,n+=" ",n+=`[${i}]${ls(s.msg)}[/${i}]`,e.push(n)}c.game.logs=c.game.logs.filter(s=>c.app.time()-s.time<(c.globalOpt.logTime||4));let r=wt({text:e.join(` +`),font:ts,pos:E(t,-t),anchor:"botleft",size:16,width:pe()*.6,lineSpacing:t/2,fixed:true,styles:{time:{color:_(127,127,127)},info:{color:_(255,255,255)},error:{color:_(255,0,127)}}});Be({width:r.width+t*2,height:r.height+t*2,anchor:"botleft",color:_(0,0,0),radius:4,opacity:.8,fixed:true}),yt(r),ve()})}a(Za,"drawDebug");function ls(t,e=false,r=new Set){if(r.has(t))return"";var s="",n;return e&&typeof t=="string"&&(t=JSON.stringify(t)),Array.isArray(t)&&(s=["[",t.map(i=>ls(i,true,r.union(new Set([t])))).join(", "),"]"].join(""),t=s),t===null?"null":(typeof t=="object"&&t.toString===Object.prototype.toString&&(t.constructor!==Object&&(s+=t.constructor.name+" "),s+=["{",(n=Object.getOwnPropertyNames(t).map(i=>`${/^\w+$/.test(i)?i:JSON.stringify(i)}: ${ls(t[i],true,r.union(new Set([t])))}`).join(", "))?` ${n} `:"","}"].join(""),t=s),String(t).replaceAll(new RegExp("(?0?c.game.events.trigger("loading",t):$e(()=>{let e=pe()/2,r=24,s=E(pe()/2,we()/2).sub(E(e/2,r/2));Be({pos:E(0),width:pe(),height:we(),color:_(0,0,0)}),Be({pos:s,width:e,height:r,fill:false,outline:{width:4}}),Be({pos:s,width:e*t,height:r})})}a($a,"drawLoadScreen");function Sn(t,e,r){let s=c.gfx.ggl.gl;Ce(),s.clear(s.STENCIL_BUFFER_BIT),s.enable(s.STENCIL_TEST),s.stencilFunc(s.NEVER,1,255),s.stencilOp(s.REPLACE,s.REPLACE,s.REPLACE),e(),Ce(),s.stencilFunc(r,1,255),s.stencilOp(s.KEEP,s.KEEP,s.KEEP),t(),Ce(),s.disable(s.STENCIL_TEST)}a(Sn,"drawStenciled");function _a(t,e){let r=c.gfx.ggl.gl;Sn(t,e,r.EQUAL)}a(_a,"drawMasked");function Rr(t){var i,o;if(!t.tex)throw new Error('drawTexture() requires property "tex".');let e=t.quad??new oe(0,0,1,1),r=t.tex.width*e.w,s=t.tex.height*e.h,n=new C(1);if(t.tiled){let d=Pt(t.anchor||xs);(((i=t.pos)==null?void 0:i.x)||0)-(d.x+1)*.5*(t.width||r);(((o=t.pos)==null?void 0:o.y)||0)-(d.y+1)*.5*(t.height||s);let l=(t.width||r)/r,u=(t.height||s)/s,f=Math.floor(l),x=Math.floor(u),h=l-f,y=u-x,p=(f+h?1:0)*(x+y?1:0),S=new Array(p*6),g=new Array(p*4),w=0,R=a((P,O,T,A,v)=>{S[w*6+0]=w*4+0,S[w*6+1]=w*4+1,S[w*6+2]=w*4+3,S[w*6+3]=w*4+1,S[w*6+4]=w*4+2,S[w*6+5]=w*4+3,g[w*4+0]={pos:new C(P-d.x,O-d.y),uv:new C(v.x,v.y),color:t.color||X.WHITE,opacity:t.opacity||1},g[w*4+1]={pos:new C(P+T-d.x,O-d.y),uv:new C(v.x+v.w,v.y),color:t.color||X.WHITE,opacity:t.opacity||1},g[w*4+2]={pos:new C(P+T-d.x,O+A-d.y),uv:new C(v.x+v.w,v.y+v.h),color:t.color||X.WHITE,opacity:t.opacity||1},g[w*4+3]={pos:new C(P-d.x,O+A-d.y),uv:new C(v.x,v.y+v.h),color:t.color||X.WHITE,opacity:t.opacity||1},w++},"addQuad");for(let P=0;P{let r=Ss(e,Os,Us),s=t.pixelDensity??1,n=t.scale??1,{gl:i}=e,o=lt.fromImage(e,new ImageData(new Uint8ClampedArray([255,255,255,255]),1,1)),d=t.width&&t.height?new as(e,t.width*s*n,t.height*s*n):new as(e,i.drawingBufferWidth,i.drawingBufferHeight),l=null,u=1;t.background&&(typeof t.background=="string"?l=_(t.background):(l=_(...t.background),u=t.background[3]??1),i.clearColor(l.r/255,l.g/255,l.b/255,u??1)),i.enable(i.BLEND),i.blendFuncSeparate(i.ONE,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA);let f=new wu(e,un,Il,Fl),x=lt.fromImage(e,new ImageData(new Uint8ClampedArray([128,128,128,255,190,190,190,255,190,190,190,255,128,128,128,255]),2,2),{wrap:"repeat",filter:"nearest"});return{lastDrawCalls:0,ggl:e,defShader:r,defTex:o,frameBuffer:d,postShader:null,postShaderUniform:null,renderer:f,transform:new Qe,transformStack:[],bgTex:x,bgColor:l,bgAlpha:u,width:t.width??i.drawingBufferWidth/s/n,height:t.height??i.drawingBufferHeight/s/n,viewport:{x:0,y:0,width:i.drawingBufferWidth,height:i.drawingBufferHeight},fixed:false}},"initAppGfx");function qn(){let t=c.pixelDensity,e=c.gfx.ggl.gl.drawingBufferWidth/t,r=c.gfx.ggl.gl.drawingBufferHeight/t;if(c.globalOpt.letterbox){if(!c.globalOpt.width||!c.globalOpt.height)throw new Error("Letterboxing requires width and height defined.");let s=e/r,n=c.globalOpt.width/c.globalOpt.height;if(s>n){let i=r*n,o=(e-i)/2;c.gfx.viewport={x:o,y:0,width:i,height:r}}else{let i=e/n,o=(r-i)/2;c.gfx.viewport={x:0,y:o,width:e,height:i}}return}if(c.globalOpt.stretch&&(!c.globalOpt.width||!c.globalOpt.height))throw new Error("Stretching requires width and height defined.");c.gfx.viewport={x:0,y:0,width:e,height:r}}a(qn,"updateViewport");function ut(t){return t.fixed?true:t.parent?ut(t.parent):false}a(ut,"isFixed");function At(t){return{color:t.color,opacity:t.opacity,anchor:t.anchor,outline:t.outline,shader:t.shader,uniform:t.uniform}}a(At,"getRenderProps");function ro(t,e={}){return{id:"circle",radius:t,draw(){kt(Object.assign(At(this),{radius:this.radius,fill:e.fill}))},renderArea(){return new ie(new C(this.anchor?0:-this.radius),this.radius*2,this.radius*2)},inspect(){return`radius: ${Math.ceil(this.radius)}`}}}a(ro,"circle");function Cn(...t){return{id:"color",color:_(...t),inspect(){return`color: ${this.color.toString()}`}}}a(Cn,"color");function so(t){return{add(){this.canvas=t}}}a(so,"drawon");function no(t=1){let e,r=0,s=false;return{require:["opacity"],add(){e=this.opacity,this.opacity=0},update(){s||(r+=ge(),this.opacity=Le(r,0,t,0,e),r>=t&&(this.opacity=e,s=true))}}}a(no,"fadeIn");function io(t="intersect"){return{id:"mask",mask:t}}a(io,"mask");function Bn(t){return{id:"opacity",opacity:t??1,fadeIn(e=1,r=c.k.easings.linear){return c.game.root.tween(0,this.opacity,e,s=>this.opacity=s,r)},fadeOut(e=1,r=c.k.easings.linear){return c.game.root.tween(this.opacity,0,e,s=>this.opacity=s,r)},inspect(){return`opacity: ${rs(this.opacity,1)}`}}}a(Bn,"opacity");function ao(t=1,e=_(0,0,0),r=1,s="miter",n=10,i="butt"){return{id:"outline",outline:{width:t,color:e,opacity:r,join:s,miterLimit:n,cap:i},inspect(){return`outline: ${this.outline.width}px, ${this.outline.color}`}}}a(ao,"outline");var ar;var Au=(ar=class{constructor(){b(this,"pos",E(0));b(this,"vel",E(0));b(this,"acc",E(0));b(this,"angle",0);b(this,"angularVelocity",0);b(this,"damping",0);b(this,"t");b(this,"lt",null);b(this,"gc");this.t=0,this.gc=true}get progress(){return this.lt?this.t/this.lt:this.t}},a(ar,"Particle"),ar);function oo(t,e){let r=e.lifetime,s=[],n=t.colors||[X.WHITE],i=t.opacities||[1],o=t.quads||[new oe(0,0,1,1)],d=t.scales||[1],l=t.lifeTime,u=e.direction,f=e.spread,x=t.speed||[0,0],h=t.angle||[0,0],y=t.angularVelocity||[0,0],p=t.acceleration||[E(0),E(0)],S=t.damping||[0,0],g=[],w=new Array(t.max),R=0,P=0;for(let A=0;A=v.lt){v.gc=true,R--;continue}v.vel=v.vel.add(v.acc.scale(A)).scale(1-v.damping*A),v.pos=v.pos.add(v.vel.scale(A)),v.angle+=v.angularVelocity*A}for(r!==void 0&&(r-=A,r<=0&&O.trigger()),P+=A;Re.rate;)this.emit(1),R++,P-=e.rate},draw(){if(!(r!==void 0&&r<=0)){for(let A=0;A`[${r.x},${r.y}]`).join(",")}`}}}a(lo,"polygon");function Rn(t,e,r){let s;return c.game.root.get("area").forEach(n=>{if(r&&r.some(o=>n.is(o)))return;let i=n.worldArea().raycast(t,e);i&&(s?i.fractionA.x+A.y*n,"tile2Hash"),f=a(A=>E(Math.floor(A%n),Math.floor(A/n)),"hash2Tile"),x=a(()=>{i=[];for(let A of r.children)h(A)},"createSpatialMap"),h=a(A=>{let v=u(A.tilePos);i[v]?i[v].push(A):i[v]=[A]},"insertIntoSpatialMap"),y=a(A=>{let v=u(A.tilePos);if(i[v]){let M=i[v].indexOf(A);M>=0&&i[v].splice(M,1)}},"removeFromSpatialMap"),p=a(()=>{let A=false;for(let v of r.children){let M=r.pos2Tile(v.pos);(v.tilePos.x!=M.x||v.tilePos.y!=M.y)&&(A=true,y(v),v.tilePos.x=M.x,v.tilePos.y=M.y,h(v))}A&&r.trigger("spatialMapChanged")},"updateSpatialMap"),S=a(()=>{let A=r.getSpatialMap(),v=r.numRows()*r.numColumns();o?o.length=v:o=new Array(v),o.fill(1,0,v);for(let M=0;M{let A=r.getSpatialMap(),v=r.numRows()*r.numColumns();d?d.length=v:d=new Array(v),d.fill(15,0,v);for(let M=0;M{let A=r.numRows()*r.numColumns(),v=a((k,I)=>{let D=[];for(D.push(k);D.length>0;){let U=D.pop();O(U).forEach(N=>{l[N]<0&&(l[N]=I,D.push(N))})}},"traverse");l?l.length=A:l=new Array(A),l.fill(-1,0,A);let M=0;for(let k=0;k=0){M++;continue}v(k,M),M++}},"createConnectivityMap"),R=a((A,v)=>o[v],"getCost"),P=a((A,v)=>{let M=f(A),k=f(v);return M.dist(k)},"getHeuristic"),O=a((A,v)=>{let M=[],k=Math.floor(A%n),I=k>0&&d[A]&1&&o[A-1]!==1/0,D=A>=n&&d[A]&2&&o[A-n]!==1/0,U=k{if(typeof A=="string"){if(e.tiles[A]){if(typeof e.tiles[A]!="function")throw new Error("Level symbol def must be a function returning a component list");return e.tiles[A](M)}else if(e.wildcardTile)return e.wildcardTile(A,M)}else{if(Array.isArray(A))return A;throw new Error("Expected a symbol or a component list")}})();if(!k)return null;let I=false,D=false;for(let N of k)N.id==="tile"&&(D=true),N.id==="pos"&&(I=true);I||k.push(Pr(this.tile2Pos(M))),D||k.push(Yn());let U=r.add(k);return I&&(U.tilePosOffset=U.pos.clone()),U.tilePos=M,U.transform=Gt(U),i&&(h(U),this.trigger("spatialMapChanged"),this.trigger("navigationMapInvalid")),U},numColumns(){return n},numRows(){return s},levelWidth(){return n*this.tileWidth()},levelHeight(){return s*this.tileHeight()},tile2Pos(...A){return E(...A).scale(this.tileWidth(),this.tileHeight())},pos2Tile(...A){let v=E(...A);return E(Math.floor(v.x/this.tileWidth()),Math.floor(v.y/this.tileHeight()))},getSpatialMap(){return i||x(),i},removeFromSpatialMap:y,insertIntoSpatialMap:h,onSpatialMapChanged(A){return this.on("spatialMapChanged",A)},onNavigationMapInvalid(A){return this.on("navigationMapInvalid",A)},getAt(A){i||x();let v=u(A);return i[v]||[]},raycast(A,v){let M=this.toWorld(A),k=this.toWorld(A.add(v)).sub(M),I=1/this.tileWidth(),D=A.scale(I),U=Bi(D,v,N=>{let j=this.getAt(N);if(j.some(V=>V.isObstacle))return true;let z=null;for(let V of j)if(V.has("area")){let Y=V.worldArea().raycast(M,k);Y&&(z?Y.fraction=n||A.y<0||A.y>=s||v.x<0||v.x>=n||v.y<0||v.y>=s)return null;let k=u(A),I=u(v);if(o[I]===1/0)return null;if(k===I)return[];if(l[k]!=-1&&l[k]!==l[I])return null;let D=new ra((ee,J)=>ee.costU.scale(k,I).add(k/2,I/2)),v]:null}};return r.use(T),r.onNavigationMapInvalid(()=>{r.invalidateNavigationMap(),r.trigger("navigationMapChanged")}),t.forEach((A,v)=>{let M=A.split("");n=Math.max(M.length,n),M.forEach((k,I)=>{r.spawn(k,E(I,v))})}),r}a(ho,"addLevel");function Me(t,e,r){return c.game.objEvents.registers[t]||(c.game.objEvents.registers[t]=new ta),c.game.objEvents.on(t,(s,...n)=>{s.is(e)&&r(s,...n)})}a(Me,"on");var xu=a((t,e,...r)=>{for(let s of c.game.root.children)s.is(e)&&s.trigger(t)},"trigger");var vu=ne(t=>{let e=c.game.root.add([{fixedUpdate:t}]);return{get paused(){return e.paused},set paused(r){e.paused=r},cancel:a(()=>e.destroy(),"cancel")}},(t,e)=>Me("fixedUpdate",t,e));var bu=ne(t=>{let e=c.game.root.add([{update:t}]);return{get paused(){return e.paused},set paused(r){e.paused=r},cancel:a(()=>e.destroy(),"cancel")}},(t,e)=>Me("update",t,e));var Eu=ne(t=>{let e=c.game.root.add([{draw:t}]);return{get paused(){return e.hidden},set paused(r){e.hidden=r},cancel:a(()=>e.destroy(),"cancel")}},(t,e)=>Me("draw",t,e));var co=ne(t=>c.game.events.on("add",t),(t,e)=>Me("add",t,e));var Mu=ne(t=>c.game.events.on("destroy",t),(t,e)=>Me("destroy",t,e));var Su=ne(t=>c.game.events.on("use",t),(t,e)=>Me("use",t,e));var qu=ne(t=>c.game.events.on("unuse",t),(t,e)=>Me("unuse",t,e));var fo=ne(t=>c.game.events.on("tag",t),(t,e)=>Me("tag",t,e));var Cu=ne(t=>c.game.events.on("untag",t),(t,e)=>Me("untag",t,e));function po(t,e,r){return Me("collide",t,(s,n,i)=>n.is(e)&&r(s,n,i))}a(po,"onCollide");function mo(t,e,r){return Me("collideUpdate",t,(s,n,i)=>n.is(e)&&r(s,n,i))}a(mo,"onCollideUpdate");function wo(t,e,r){return Me("collideEnd",t,(s,n,i)=>n.is(e)&&r(s,n,i))}a(wo,"onCollideEnd");function Nr(t,e){c.game.root.get(t,{recursive:true}).forEach(e),co(t,e),fo((r,s)=>{s===t&&e(r)})}a(Nr,"forAllCurrentAndFuture");var Bu=ne(t=>c.app.onMousePress(t),(t,e)=>{let r=[];return Nr(t,s=>{if(!s.area)throw new Error("onClick() requires the object to have area() component");r.push(s.onClick(()=>e(s)))}),Bt.join(r)});function yo(t,e){let r=[];return Nr(t,s=>{if(!s.area)throw new Error("onHover() requires the object to have area() component");r.push(s.onHover(()=>e(s)))}),Bt.join(r)}a(yo,"onHover");function Ao(t,e){let r=[];return Nr(t,s=>{if(!s.area)throw new Error("onHoverUpdate() requires the object to have area() component");r.push(s.onHoverUpdate(()=>e(s)))}),Bt.join(r)}a(Ao,"onHoverUpdate");function xo(t,e){let r=[];return Nr(t,s=>{if(!s.area)throw new Error("onHoverEnd() requires the object to have area() component");r.push(s.onHoverEnd(()=>e(s)))}),Bt.join(r)}a(xo,"onHoverEnd");function vo(t){c.game.events.on("loading",t)}a(vo,"onLoading");function bo(t){c.app.onResize(t)}a(bo,"onResize");function Eo(t){c.game.events.on("error",t)}a(Eo,"onError");function Cs(t){c.assets.loaded?t():c.game.events.on("load",t)}a(Cs,"onLoad");function Mo(t){if(c.assets.loaded)fn().forEach(e=>t(...e));else return c.game.events.on("loadError",t)}a(Mo,"onLoadError");function kn(...t){c.game.cam.pos=E(...t)}a(kn,"setCamPos");function In(){return c.game.cam.pos?c.game.cam.pos.clone():Cr()}a(In,"getCamPos");function Fn(...t){c.game.cam.scale=E(...t)}a(Fn,"setCamScale");function Tn(){return c.game.cam.scale.clone()}a(Tn,"getCamScale");function Dn(t){c.game.cam.angle=t}a(Dn,"setCamRot");function On(){return c.game.cam.angle}a(On,"getCamRot");function So(){return c.game.cam.transform.clone()}a(So,"getCamTransform");function Un(t=_(255,255,255),e=1){let r=c.game.root.add([Pn(pe(),we()),Cn(t),Bn(1),Wn()]),s=r.fadeOut(e);return s.onEnd(()=>Kn(r)),s}a(Un,"flash");function qo(){return c.game.cam.transform.clone()}a(qo,"camTransform");function Co(t=12){c.game.cam.shake+=t}a(Co,"shake");function us(t){return c.game.cam.transform.multVec2(t)}a(us,"toScreen");function Ln(t){return c.game.cam.transform.invert().multVec2(t)}a(Ln,"toWorld");function Bo(...t){return Rt("camPos","setCamPos / getCamPos"),t.length>0&&kn(...t),In()}a(Bo,"camPos");function Ro(...t){return Rt("camScale","setCamScale / getCamScale"),t.length>0&&Fn(...t),Tn()}a(Ro,"camScale");function Po(t){return Rt("camRot","setCamRot / getCamRot"),t!==void 0&&Dn(t),On()}a(Po,"camRot");function ko(t=_(255,255,255),e=1){return Rt("camFlash","flash"),Un(t,e)}a(ko,"camFlash");function Bs(t=[]){let e=new Map,r=[],s={},n=new Sr,i=[],o=new Set("*"),d=c.globalOpt.tagsAsComponents,l=null,u=false,f={id:Xl(),hidden:false,transform:new Qe,children:[],parent:null,set paused(h){if(h!==u){u=h;for(let y of i)y.paused=h}},get paused(){return u},get tags(){return Array.from(o)},add(h){let y=Array.isArray(h)?Bs(h):h;if(y.parent)throw new Error("Cannot add a game obj that already has a parent.");return y.parent=this,y.transform=Gt(y),this.children.push(y),y.trigger("add",y),c.game.events.trigger("add",y),y},readd(h){let y=this.children.indexOf(h);return y!==-1&&(this.children.splice(y,1),this.children.push(h)),h},remove(h){let y=this.children.indexOf(h);if(y!==-1){h.parent=null,this.children.splice(y,1);let p=a(S=>{S.trigger("destroy"),c.game.events.trigger("destroy",S),S.children.forEach(g=>p(g))},"trigger");p(h)}},removeAll(h){if(h)this.get(h).forEach(y=>this.remove(y));else for(let y of[...this.children])this.remove(y)},fixedUpdate(){this.paused||(this.children.forEach(h=>h.fixedUpdate()),this.trigger("fixedUpdate"))},update(){this.paused||(this.children.forEach(h=>h.update()),this.trigger("update"))},draw(){if(this.hidden)return;this.canvas&&(Ce(),this.canvas.bind());let h=c.gfx.fixed;this.fixed&&(c.gfx.fixed=true),qe(),ae(this.pos),dr(this.scale),Ct(this.angle);let y=this.children.sort((p,S)=>{let g=p.layerIndex??c.game.defaultLayerIndex,w=S.layerIndex??c.game.defaultLayerIndex;return g-w||(p.z??0)-(S.z??0)});if(this.mask){let p={intersect:c.k.drawMasked,subtract:c.k.drawSubtracted}[this.mask];if(!p)throw new Error(`Invalid mask func: "${this.mask}"`);p(()=>{y.forEach(S=>S.draw())},()=>{this.trigger("draw")})}else this.trigger("draw"),y.forEach(p=>p.draw());ve(),c.gfx.fixed=h,this.canvas&&(Ce(),this.canvas.unbind())},drawInspect(){this.hidden||(qe(),ae(this.pos),dr(this.scale),Ct(this.angle),this.children.forEach(h=>h.drawInspect()),this.trigger("drawInspect"),ve())},use(h){var S;if(typeof h=="string")return o.add(h);if(!h||typeof h!="object")throw new Error(`You can only pass a component or a string to .use(), you passed a "${typeof h}"`);let y=[];h.id?(this.unuse(h.id),s[h.id]=[],y=s[h.id],e.set(h.id,h),d&&o.add(h.id)):r.push(h);for(let g in h){if(Ol.has(g))continue;let w=Object.getOwnPropertyDescriptor(h,g);if(w)if(typeof w.value=="function"&&(h[g]=h[g].bind(this)),w.set&&Object.defineProperty(h,g,{set:w.set.bind(this)}),w.get&&Object.defineProperty(h,g,{get:w.get.bind(this)}),Ul.has(g)){let R=g==="add"?()=>{var P;l=a(O=>y.push(O),"onCurCompCleanup"),(P=h[g])==null?void 0:P.call(h),l=null}:h[g];y.push(this.on(g,R).cancel)}else if(this[g]===void 0)Object.defineProperty(this,g,{get:a(()=>h[g],"get"),set:a(R=>h[g]=R,"set"),configurable:true,enumerable:true}),y.push(()=>delete this[g]);else{let R=(S=e.values().find(P=>P[g]!==void 0))==null?void 0:S.id;throw new Error(`Duplicate component property: "${g}" while adding component "${h.id}"`+(R?` (originally added by "${R}")`:""))}}let p=a(()=>{if(h.require){for(let g of h.require)if(!this.c(g))throw new Error(`Component "${h.id}" requires component "${g}"`)}},"checkDeps");h.destroy&&y.push(h.destroy.bind(this)),this.exists()?(p(),h.add&&(l=a(g=>y.push(g),"onCurCompCleanup"),h.add.call(this),l=null),h.id&&(this.trigger("use",h.id),c.game.events.trigger("use",this,h.id))):h.require&&y.push(this.on("add",p).cancel)},unuse(h){if(e.has(h)){for(let y of e.values())if(y.require&&y.require.includes(h))throw new Error(`Can't unuse. Component "${y.id}" requires component "${h}"`);e.delete(h),this.trigger("unuse",h),c.game.events.trigger("unuse",this,h)}else d&&o.has(h)&&o.delete(h);s[h]&&(s[h].forEach(y=>y()),delete s[h])},c(h){return e.get(h)??null},get(h,y={}){let p=a((g,w)=>y.only==="comps"?g.has(w):y.only==="tags"?g.is(w):g.is(w)||g.has(w),"checkTagsOrComps"),S=y.recursive?this.children.flatMap(a(function g(w){return[w,...w.children.flatMap(g)]},"recurse")):this.children;if(S=S.filter(g=>h?p(g,h):true),y.liveUpdate){let g=a(R=>y.recursive?this.isAncestorOf(R):R.parent===this,"isChild"),w=[];w.push(c.k.onAdd(R=>{g(R)&&p(R,h)&&S.push(R)})),w.push(c.k.onDestroy(R=>{if(g(R)&&p(R,h)){let P=S.findIndex(O=>O.id===R.id);P!==-1&&S.splice(P,1)}})),this.onDestroy(()=>{for(let R of w)R.cancel()})}return S},query(h){let y=h.hierarchy||"children",p=h.include,S=h.exclude,g=[];switch(y){case"children":g=this.children;break;case"siblings":g=this.parent?this.parent.children.filter(R=>R!==this):[];break;case"ancestors":let w=this.parent;for(;w;)g.push(w),w=w.parent;break;case"descendants":g=this.children.flatMap(a(function R(P){return[P,...P.children.flatMap(R)]},"recurse"));break}if(p&&((h.includeOp||"and")==="and"||!Array.isArray(h.include)?g=g.filter(w=>w.is(p)):g=g.filter(w=>h.include.some(R=>w.is(R)))),S&&((h.includeOp||"and")==="and"||!Array.isArray(h.include)?g=g.filter(w=>!w.is(S)):g=g.filter(w=>!h.exclude.some(R=>w.is(R)))),h.visible===true&&(g=g.filter(w=>w.visible)),h.distance){if(!this.pos)throw Error("Can't do a distance query from an object without pos");let w=h.distanceOp||"near",R=h.distance*h.distance;w==="near"?g=g.filter(P=>P.pos&&this.pos.sdist(P.pos)<=R):g=g.filter(P=>P.pos&&this.pos.sdist(P.pos)>R)}return h.name&&(g=g.filter(w=>w.name===h.name)),g},isAncestorOf(h){return h.parent?h.parent===this||this.isAncestorOf(h.parent):false},exists(){return c.game.root.isAncestorOf(this)},is(h,y="and"){return Array.isArray(h)?y==="and"?h.every(p=>o.has(p)):h.some(p=>o.has(p)):o.has(h)},tag(h){if(Array.isArray(h))for(let y of h)o.add(y),this.trigger("tag",y),c.game.events.trigger("tag",this,y);else o.add(h),this.trigger("tag",h),c.game.events.trigger("tag",this,h)},untag(h){if(Array.isArray(h))for(let y of h)o.delete(y),this.trigger("untag",y),c.game.events.trigger("untag",this,y);else o.delete(h),this.trigger("untag",h),c.game.events.trigger("untag",this,h)},has(h,y="and"){return Array.isArray(h)?y==="and"?h.every(p=>e.has(p)):h.some(p=>e.has(p)):e.has(h)},on(h,y){let p=n.on(h,y.bind(this));return l&&l(()=>p.cancel()),p},trigger(h,...y){n.trigger(h,...y),c.game.objEvents.trigger(h,this,...y)},destroy(){this.parent&&this.parent.remove(this)},inspect(){var y;let h={};for(let[p,S]of e)h[p]=((y=S.inspect)==null?void 0:y.call(S))??null;for(let[p,S]of r.entries()){if(S.inspect){h[p]=S.inspect();continue}for(let[g,w]of Object.entries(S))typeof w!="function"&&(h[g]=`${g}: ${w}`)}return h},onAdd(h){return this.on("add",h)},onFixedUpdate(h){return this.on("fixedUpdate",h)},onUpdate(h){return this.on("update",h)},onDraw(h){return this.on("draw",h)},onDestroy(h){return this.on("destroy",h)},onUse(h){return this.on("use",h)},onUnuse(h){return this.on("unuse",h)},clearEvents(){n.clear()}},x=["onKeyPress","onKeyPressRepeat","onKeyDown","onKeyRelease","onMousePress","onMouseDown","onMouseRelease","onMouseMove","onCharInput","onMouseMove","onTouchStart","onTouchMove","onTouchEnd","onScroll","onGamepadButtonPress","onGamepadButtonDown","onGamepadButtonRelease","onGamepadStick","onButtonPress","onButtonDown","onButtonRelease"];for(let h of x)f[h]=(...y)=>{var S,g;let p=(g=(S=c.app)[h])==null?void 0:g.call(S,...y);return i.push(p),f.onDestroy(()=>p.cancel()),f.on("sceneEnter",()=>{var R,P;i.splice(i.indexOf(p),1);let w=(P=(R=c.app)[h])==null?void 0:P.call(R,...y);Bt.replace(p,w),i.push(p)}),p};for(let h of t)f.use(h);return f}a(Bs,"make");var Ru=a(()=>({events:new Sr,objEvents:new Sr,root:Bs([]),gravity:null,scenes:{},currentScene:null,layers:null,defaultLayerIndex:0,logs:[],cam:{pos:null,scale:new C(1),angle:0,shake:0,transform:new Qe}}),"initGame");function Io(t){c.game.gravity=t?(c.game.gravity||E(0,1)).unit().scale(t):null}a(Io,"setGravity");function Fo(){return c.game.gravity?c.game.gravity.len():0}a(Fo,"getGravity");function To(t){c.game.gravity=t.unit().scale(c.game.gravity?c.game.gravity.len():1)}a(To,"setGravityDirection");function jt(){return c.game.gravity?c.game.gravity.unit():E(0,1)}a(jt,"getGravityDirection");var Pu=Sl("//uUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAATAAAeAAANDQ0NDRoaGhoaKCgoKCg1NTU1NTVDQ0NDQ1BQUFBQXl5eXl5ra2tra2t5eXl5eYaGhoaGlJSUlJShoaGhoaGvr6+vr7y8vLy8ysrKysrX19fX19fl5eXl5fLy8vLy//////8AAAA5TEFNRTMuMTAwAaoAAAAAAAAAABSAJAOPhgAAgAAAHgBaqIlmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//uUBAAP8h1kPIABR4BEDGeQAEbkSb2RAACBFMEyMiAAASJw4xjgwAGyRvfIoZT2QKGV5YNw/tKID9+X93qXtBQUFBQ/e+EFKTQUT/dy3f5dK/3d04rkXHpufCClDAaH7jDMgFAQEGfPt+jI352U9vU4GLRpzkUDeeeTQggQe2ggF3d7/3j697DnhCH5iGf38//iNj9oy2Jk71oj+CBAABGNB4RJNMwgCABCB//8//l////1z6XEGd73az07sOkwZD9VYgjzjmQ6j4EMfZM86OJ7GUWw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8p48BQUTWPDTbNjkPn8+1VXKvJ7dJ5Gb2mESWLjnHOYNH07r6//////////icK81KXqTXuvQEteLGdY0DKwrjQVTIMKbgE0b41Egi1KxtuNwUpf9X+bNqTUlXbDClWgIlS4wMVc1F0QZc3/N/yto/7eUShjGUstRgIUZXKUrFYwU5SgKOxgYE+krfVkf6St/VpnMaYwpwoCjoZwoCZwqFC4LH//uUBD+P4jNjPwAjN8I7THfwAEnqR8mAugCAcQkHsheEERr40LUwj//hIzL//9k/9rJZ9lks+yyVDL/////81YHZUMj//yZZLHIy7/5qwMHHIyZZL/sslQyNWt/I1DBQYRxPYaxS/////5kn///6on0VEVP/6on/7OVFVO5QwUGEOzyhgaoqKhQwMGCUjt////8qaLdr/qTiyzLxaJxpRTt6RBhIhDZMQU1FMy4xMDCqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");var ku=a(()=>(()=>{let t=new(window.AudioContext||window.webkitAudioContext),e=t.createGain();e.connect(t.destination);let r=new Br(Aa(t));return t.decodeAudioData(Pu.buffer.slice(0)).then(s=>{r.buf=s}).catch(s=>{console.error("Failed to load burp: ",s)}),{ctx:t,masterNode:e,burpSnd:r}})(),"initAudio");function Do(t,e={}){let r=new xe,s=new Audio(t);s.crossOrigin="anonymous",s.loop=!!e.loop,c.audio.ctx.createMediaElementSource(s).connect(c.audio.masterNode);function n(){c.debug.paused||c.app.isHidden()&&!c.globalOpt.backgroundAudio||c.audio.ctx.resume()}a(n,"resumeAudioCtx");function i(){n(),s.play()}return a(i,"play"),e.paused||i(),s.onended=()=>r.trigger(),{play(){i()},seek(o){s.currentTime=o},stop(){s.pause(),this.seek(0)},set loop(o){s.loop=o},get loop(){return s.loop},set paused(o){o?s.pause():i()},get paused(){return s.paused},time(){return s.currentTime},duration(){return s.duration},set volume(o){s.volume=Ne(o,0,1)},get volume(){return s.volume},set speed(o){s.playbackRate=Math.max(o,0)},get speed(){return s.playbackRate},set detune(o){},get detune(){return 0},onEnd(o){return r.add(o)},then(o){return this.onEnd(o)}}}a(Do,"playMusic");function Oo(t,e={}){if(typeof t=="string"&&c.assets.music[t])return Do(c.assets.music[t],e);let r=c.audio.ctx,s=e.paused??false,n=r.createBufferSource(),i=new xe,o=r.createGain(),d=r.createStereoPanner(),l=e.seek??0,u=0,f=0,x=false;n.loop=!!e.loop,n.detune.value=e.detune??0,n.playbackRate.value=e.speed??1,n.connect(d),n.onended=()=>{var g;p()>=(((g=n.buffer)==null?void 0:g.duration)??Number.POSITIVE_INFINITY)&&i.trigger()},d.pan.value=e.pan??0,d.connect(o),o.connect(c.audio.masterNode),o.gain.value=e.volume??1;let h=a(g=>{n.buffer=g.buf,s||(u=r.currentTime,n.start(0,l),x=true)},"start"),y=ja(t);y instanceof Te&&y.onLoad(h);let p=a(()=>{if(!n.buffer)return 0;let g=s?f-u:r.currentTime-u,w=n.buffer.duration;return n.loop?g%w:Math.min(g,w)},"getTime"),S=a(g=>{let w=r.createBufferSource();return w.buffer=g.buffer,w.loop=g.loop,w.playbackRate.value=g.playbackRate.value,w.detune.value=g.detune.value,w.onended=g.onended,w.connect(d),w},"cloneNode");return{stop(){this.paused=true,this.seek(0)},set paused(g){if(s!==g)if(s=g,g)x&&(n.stop(),x=false),f=r.currentTime;else{n=S(n);let w=f-u;n.start(0,w),x=true,u=r.currentTime-w,f=0}},get paused(){return s},play(g=0){this.seek(g),this.paused=false},seek(g){var w;((w=n.buffer)==null?void 0:w.duration)&&(g>n.buffer.duration||(s?(n=S(n),u=f-g):(n.stop(),n=S(n),u=r.currentTime-g,n.start(0,g),x=true,f=0)))},set speed(g){n.playbackRate.value=g},get speed(){return n.playbackRate.value},set detune(g){n.detune.value=g},get detune(){return n.detune.value},set volume(g){o.gain.value=Math.max(g,0)},get volume(){return o.gain.value},set pan(g){d.pan.value=g},get pan(){return d.pan.value},set loop(g){n.loop=g},get loop(){return n.loop},duration(){var g;return((g=n.buffer)==null?void 0:g.duration)??0},time(){return p()%this.duration()},onEnd(g){return i.add(g)},then(g){return this.onEnd(g)}}}a(Oo,"play");function Nn(t){return c.k.play(c.audio.burpSnd,t)}a(Nn,"burp");function Gn(t){c.audio.masterNode.gain.value=t}a(Gn,"setVolume");function Hn(){return c.audio.masterNode.gain.value}a(Hn,"getVolume");function Uo(t){return Rt("volume","setVolume / getVolume"),t!==void 0&&Gn(t),Hn()}a(Uo,"volume");function jn(){c.app.onHide(()=>{c.globalOpt.backgroundAudio||c.audio.ctx.suspend()}),c.app.onShow(()=>{!c.globalOpt.backgroundAudio&&!c.debug.paused&&c.audio.ctx.resume()}),c.app.onResize(()=>{if(c.app.isFullscreen())return;let t=c.globalOpt.width&&c.globalOpt.height;t&&!c.globalOpt.stretch&&!c.globalOpt.letterbox||(c.canvas.width=c.canvas.offsetWidth*c.pixelDensity,c.canvas.height=c.canvas.offsetHeight*c.pixelDensity,qn(),t||(c.gfx.frameBuffer.free(),c.gfx.frameBuffer=new as(c.gfx.ggl,c.gfx.ggl.gl.drawingBufferWidth,c.gfx.ggl.gl.drawingBufferHeight),c.gfx.width=c.gfx.ggl.gl.drawingBufferWidth/c.pixelDensity/c.gscale,c.gfx.height=c.gfx.ggl.gl.drawingBufferHeight/c.pixelDensity/c.gscale))}),c.globalOpt.debug!==false&&(c.app.onKeyPress(c.globalOpt.debugKey??"f1",()=>c.debug.inspect=!c.debug.inspect),c.app.onKeyPress("f2",()=>c.debug.clearLog()),c.app.onKeyPress("f8",()=>c.debug.paused=!c.debug.paused),c.app.onKeyPress("f7",()=>{c.debug.timeScale=rs(Ne(c.debug.timeScale-.2,0,2),1)}),c.app.onKeyPress("f9",()=>{c.debug.timeScale=rs(Ne(c.debug.timeScale+.2,0,2),1)}),c.app.onKeyPress("f10",()=>c.debug.stepFrame())),c.globalOpt.burp&&c.app.onKeyPress("b",()=>Nn())}a(jn,"initEvents");function Lo(t,e={}){let r=c.game.root.add([Pr(t),zn()]),s=(e.speed||1)*5,n=e.scale||1;r.add([hs(c.boomSprite),kr(0),cs("center"),Ys(s,n),...e.comps??[]]);let i=r.add([hs(c.kaSprite),kr(0),cs("center"),ds(),...e.comps??[]]);return i.wait(.4/s,()=>i.use(Ys(s,n))),i.onDestroy(()=>r.destroy()),r}a(Lo,"addKaboom");function Vn(t,e){if(c.game.layers)throw Error("Layers can only be assigned once.");let r=t.indexOf(e);if(r==-1)throw Error("The default layer name should be present in the layers list.");c.game.layers=t,c.game.defaultLayerIndex=r}a(Vn,"setLayers");function No(){return c.game.layers}a(No,"getLayers");function Go(){var t;return((t=c.game.layers)==null?void 0:t[c.game.defaultLayerIndex])??null}a(Go,"getDefaultLayer");function Ho(t,e){Rt("layers","setLayers"),Vn(t,e)}a(Ho,"layers");function Kn(t){t.destroy()}a(Kn,"destroy");function jo(){return c.game.root}a(jo,"getTreeRoot");function Vo(t,e){c.game.scenes[t]=e}a(Vo,"scene");function Ko(t,...e){if(!c.game.scenes[t])throw new Error(`Scene not found: ${t}`);c.game.events.onOnce("frameEnd",()=>{c.game.events.trigger("sceneLeave",t),c.app.events.clear(),c.game.events.clear(),c.game.objEvents.clear(),[...c.game.root.children].forEach(r=>{!r.stay||r.scenesToStay&&!r.scenesToStay.includes(t)?c.game.root.remove(r):r.trigger("sceneEnter",t)}),c.game.root.clearEvents(),jn(),c.game.cam={pos:null,scale:E(1),angle:0,shake:0,transform:new Qe},c.game.scenes[t](...e)}),c.game.currentScene=t}a(Ko,"go");function Yo(t){return c.game.events.on("sceneLeave",t)}a(Yo,"onSceneLeave");function Qo(){return c.game.currentScene}a(Qo,"getSceneName");function hs(t,e={}){let r=null,s=null,n=null,i=new xe;if(!t)throw new Error("Please pass the resource name or data to sprite()");let o=a((l,u,f,x)=>{let h=E(1,1);return f&&x?(h.x=f/(l.width*u.w),h.y=x/(l.height*u.h)):f?(h.x=f/(l.width*u.w),h.y=h.x):x&&(h.y=x/(l.height*u.h),h.x=h.y),h},"calcTexScale"),d=a((l,u)=>{if(!u)return;let f=u.frames[0].clone();e.quad&&(f=f.scale(e.quad));let x=o(u.tex,f,e.width,e.height);l.width=u.tex.width*f.w*x.x,l.height=u.tex.height*f.h*x.y,e.anim&&l.play(e.anim),r=u,i.trigger(r)},"setSpriteData");return{id:"sprite",width:0,height:0,frame:e.frame||0,quad:e.quad||new oe(0,0,1,1),animSpeed:e.animSpeed??1,flipX:e.flipX??false,flipY:e.flipY??false,get sprite(){return t.toString()},set sprite(l){let u=br(l);u&&u.onLoad(f=>d(this,f))},get animFrame(){if(!r||!s||n===null)return this.frame;let l=r.anims[s.name];return typeof l=="number"?l:this.frame-Math.min(l.from,l.to)},draw(){if(!r)return;let l=r.frames[this.frame??0];if(!l)throw new Error(`Frame not found: ${this.frame??0}`);if(r.slice9){let{left:u,right:f,top:x,bottom:h}=r.slice9,y=r.tex.width*l.w,p=r.tex.height*l.h,S=this.width-u-f,g=this.height-x-h,w=u/y,R=f/y,P=1-w-R,O=x/p,T=h/p,A=1-O-T,v=[he(0,0,w,O),he(w,0,P,O),he(w+P,0,R,O),he(0,O,w,A),he(w,O,P,A),he(w+P,O,R,A),he(0,O+A,w,T),he(w,O+A,P,T),he(w+P,O+A,R,T),he(0,0,u,x),he(u,0,S,x),he(u+S,0,f,x),he(0,x,u,g),he(u,x,S,g),he(u+S,x,f,g),he(0,x+g,u,h),he(u,x+g,S,h),he(u+S,x+g,f,h)];for(let M=0;M<9;M++){let k=v[M],I=v[M+9];Rr(Object.assign(At(this),{pos:I.pos(),tex:r.tex,quad:l.scale(k),flipX:this.flipX,flipY:this.flipY,tiled:e.tiled,width:I.w,height:I.h}))}}else Rr(Object.assign(At(this),{tex:r.tex,quad:l.scale(this.quad??new oe(0,0,1,1)),flipX:this.flipX,flipY:this.flipY,tiled:e.tiled,width:this.width,height:this.height}))},add(){let l=br(t);l?l.onLoad(u=>d(this,u)):Cs(()=>d(this,br(t).data))},update(){if(!r||!s||n===null)return;let l=r.anims[s.name];if(typeof l=="number"){this.frame=l;return}if(l.speed===0)throw new Error("Sprite anim speed cannot be 0");s.timer+=ge()*this.animSpeed,s.timer>=1/s.speed&&(s.timer=0,this.frame+=n,(this.frameMath.max(l.from,l.to))&&(s.loop?s.pingpong?(this.frame-=n,n*=-1,this.frame+=n):this.frame=l.from:s.pingpong?n===Math.sign(l.to-l.from)?(this.frame=l.to,n*=-1,this.frame+=n):(this.frame=l.from,s.onEnd(),this.stop()):(this.frame=l.to,s.onEnd(),this.stop())))},play(l,u={}){if(!r){i.add(()=>this.play(l,u));return}let f=r.anims[l];if(f===void 0)throw new Error(`Anim not found: ${l}`);s&&this.stop(),s=typeof f=="number"?{name:l,timer:0,loop:false,pingpong:false,speed:0,onEnd:a(()=>{},"onEnd")}:{name:l,timer:0,loop:u.loop??f.loop??false,pingpong:u.pingpong??f.pingpong??false,speed:u.speed??f.speed??10,onEnd:u.onEnd??(()=>{})},n=typeof f=="number"?null:f.fromr(this))},draw(){yt(r(this))},renderArea(){return new ie(E(0),this.width,this.height)}};return r(s),s}a(Xo,"text");function zo(t,e){return{id:"rect",width:t,height:e,draw(){cr(Object.assign(At(this),{width:this.width,height:this.height}))},renderArea(){return new ie(E(0),this.width,this.height)},inspect(){return`uvquad: (${Math.ceil(this.width)}w, ${Math.ceil(this.height)})h`}}}a(zo,"uvquad");function Wo(t={}){let e=null,r=null,s=null,n=null;return{id:"agent",require:["pos","tile"],agentSpeed:t.speed??100,allowDiagonals:t.allowDiagonals??true,getDistanceToTarget(){return e?this.pos.dist(e):0},getNextLocation(){return r&&s?r[s]:null},getPath(){return r?r.slice():null},getTarget(){return e},isNavigationFinished(){return r?s===null:true},isTargetReachable(){return r!==null},isTargetReached(){return e?this.pos.eq(e):true},setTarget(i){e=i,r=this.getLevel().getPath(this.pos,e,{allowDiagonals:this.allowDiagonals}),s=r?0:null,r&&s!==null?(n||(n=this.getLevel().onNavigationMapChanged(()=>{e&&r&&s!==null&&(r=this.getLevel().getPath(this.pos,e,{allowDiagonals:this.allowDiagonals}),r?(s=0,this.trigger("navigationNext",this,r[s])):(s=null,this.trigger("navigationEnded",this)))}),this.onDestroy(()=>n==null?void 0:n.cancel())),this.trigger("navigationStarted",this),this.trigger("navigationNext",this,r[s])):this.trigger("navigationEnded",this)},update(){if(e&&r&&s!==null){if(this.pos.sdist(r[s])<2)if(s===r.length-1){this.pos=e.clone(),s=null,this.trigger("navigationEnded",this),this.trigger("targetReached",this);return}else s++,this.trigger("navigationNext",this,r[s]);this.moveTo(r[s],this.agentSpeed)}},onNavigationStarted(i){return this.on("navigationStarted",i)},onNavigationNext(i){return this.on("navigationNext",i)},onNavigationEnded(i){return this.on("navigationEnded",i)},onTargetReached(i){return this.on("targetReached",i)},inspect(){return"agent: "+JSON.stringify({target:JSON.stringify(e),path:JSON.stringify(r)})}}}a(Wo,"agent");function Zo(t){let e=t.graph;return{id:"pathfinder",require:["pos"],navigateTo(r){var s;return(s=this.graph)==null?void 0:s.getWaypointPath(this.pos,r,t.navigationOpt)},get graph(){if(e)return e;let r=this.parent;for(;r;){if(r.has("pathfinderMap"))return r.graph;r=r.parent}},set graph(r){e=r}}}a(Zo,"pathfinder");function Jo(t={}){let e=t.waypoints,r=t.speed||100,s=t.endBehavior||"stop",n=0,i=e!=null;return{id:"patrol",require:["pos"],get patrolSpeed(){return r},set patrolSpeed(o){r=o},get waypoints(){return e},set waypoints(o){e=o,n=0,i=false},get nextLocation(){return e?e[n]:void 0},update(){let o=this.nextLocation;if(!(!e||!o||i)&&(this.moveTo(o,r),this.pos.sdist(o)<9))switch(s){case"loop":n=(n+1)%e.length;break;case"ping-pong":n=n+1,n==e.length&&(e.reverse(),n=0);break;case"stop":n=Math.min(n+1,e.length-1),n==e.length-1&&(i=true,this.trigger("patrolFinished"));break}},onPatrolFinished(o){return this.on("patrolFinished",o)}}}a(Jo,"patrol");function $o(t,e={}){let r=typeof t=="function"?t:()=>c.game.root.query(t),s=e.checkFrequency||1,n=typeof e.direction=="number"?C.fromAngle(e.direction):e.direction,i=0;return{id:"sentry",require:["pos"],direction:typeof e.direction=="number"?C.fromAngle(e.direction):e.direction,spotted:[],set directionAngle(o){this.direction=o!==void 0?C.fromAngle(o):void 0},get directionAngle(){return this.direction?this.direction.angle():void 0},fieldOfView:e.fieldOfView||200,isWithinFieldOfView(o,d,l){let u=(typeof d=="number"?C.fromAngle(d):d)||n,f=l||e.fieldOfView;if(!u||!f||f>=360)return true;let x=f/2;return o.pos&&u.angleBetween(o.pos.sub(this.pos))<=x},hasLineOfSight(o){let d=Rn(this.pos,o.pos.sub(this.pos),e.raycastExclude);return d!=null&&d.object===o},update(){if(i+=ge(),i>s){i-=s;let o=r();if(o.length&&n&&this.fieldOfView&&this.fieldOfView<360){let d=this.fieldOfView/2;o=o.filter(l=>l.pos&&n.angleBetween(l.pos.sub(this.pos))<=d)}o.length&&e.lineOfSight&&(o=o.filter(d=>d.pos&&this.hasLineOfSight(d))),o.length>0&&(this.spotted=o,this.trigger("objectSpotted",o))}},onObjectsSpotted(o){return this.on("objectSpotted",o)}}}a($o,"sentry");function Yn(t={}){let e=E(0),r=t.isObstacle??false,s=t.cost??0,n=t.edges??[],i=a(()=>{let d={left:1,top:2,right:4,bottom:8};return n.map(l=>d[l]||0).reduce((l,u)=>l|u,0)},"getEdgeMask"),o=i();return{id:"tile",tilePosOffset:t.offset??E(0),set tilePos(d){let l=this.getLevel();e=d.clone(),this.pos=E(this.tilePos.x*l.tileWidth(),this.tilePos.y*l.tileHeight()).add(this.tilePosOffset)},get tilePos(){return e},set isObstacle(d){r!==d&&(r=d,this.getLevel().invalidateNavigationMap())},get isObstacle(){return r},set cost(d){s!==d&&(s=d,this.getLevel().invalidateNavigationMap())},get cost(){return s},set edges(d){n=d,o=i(),this.getLevel().invalidateNavigationMap()},get edges(){return n},get edgeMask(){return o},getLevel(){return this.parent},tileMove(d){let l=this.getLevel();l.removeFromSpatialMap(this),this.tilePos=this.tilePos.add(d),l.insertIntoSpatialMap(this),l.trigger("spatialMapChanged")},moveLeft(){this.tileMove(E(-1,0))},moveRight(){this.tileMove(E(1,0))},moveUp(){this.tileMove(E(0,-1))},moveDown(){this.tileMove(E(0,1))}}}a(Yn,"tile");var or;var Qn=(or=class{constructor(e,r,s){b(this,"name");b(this,"duration");b(this,"loops");b(this,"direction");b(this,"easing");b(this,"interpolation");b(this,"isFinished");b(this,"timing");b(this,"easings");b(this,"relative");this.name=e,this.duration=r.duration,this.loops=r.loops||0,this.direction=r.direction||"forward",this.easing=r.easing||qr.linear,this.interpolation=r.interpolation||"linear",this.isFinished=false,this.timing=r.timing,this.easings=r.easings,this.relative=s}update(e,r){return true}getLowerKeyIndexAndRelativeTime(e,r,s){let n=r-1,i=e/this.duration;if(this.loops!==0&&i>=this.loops)return[n,0,true];let o=Math.trunc(i);if(i-=o,(this.direction=="reverse"||this.direction=="ping-pong"&&o&1)&&(i=1-i),s){let d=0;for(;s[d+1]!==void 0&&s[d+1]=n?[n,0,true]:[d,(i-s[d])/(s[d+1]-s[d]),false]}else{let d=Math.floor((r-1)*i);return[d,(i-d/n)*n,false]}}setValue(e,r,s){if(this.relative)switch(r){case"pos":e.pos=e.base.pos.add(s);break;case"angle":e.angle=e.base.angle+s;break;case"scale":e.scale=e.base.scale.scale(s);break;case"opacity":e.opacity=e.base.opacity*s;break;default:e[r]=s}else e[r]=s}serialize(){let e={duration:this.duration,keys:[]};return this.loops&&(e.loops=this.loops),this.direction!=="forward"&&(e.direction=this.direction),this.easing!=qr.linear&&(e.easing=this.easing.name),this.interpolation!=="linear"&&(e.interpolation=this.interpolation),this.timing&&(e.timing=this.timing),this.easings&&(e.easings=this.easings.map(r=>this.easing.name)),e}},a(or,"AnimateChannel"),or);function Ks(t,e){return e.add(e.sub(t))}a(Ks,"reflect");var lr;var Iu=(lr=class extends Qn{constructor(r,s,n,i){super(r,n,i);b(this,"keys");this.keys=s}update(r,s){let[n,i,o]=this.getLowerKeyIndexAndRelativeTime(s,this.keys.length,this.timing);if(i==0||this.interpolation==="none")this.setValue(r,this.name,this.keys[n]);else{let d=this.easings?this.easings[n]:this.easing;this.setValue(r,this.name,be(this.keys[n],this.keys[n+1],d(i)))}return o}serialize(){return Object.assign(super.serialize(),{keys:this.keys})}},a(lr,"AnimateChannelNumber"),lr);var ur;var Fu=(ur=class extends Qn{constructor(r,s,n,i,o){var d;super(r,n,i);b(this,"keys");b(this,"curves");b(this,"dcurves");if(this.keys=s,this.interpolation==="spline"){this.curves=[],o&&(this.dcurves=[]);for(let l=0;l0?this.keys[l-1]:Ks(x,u),y=f[r.x,r.y])})}},a(ur,"AnimateChannelVec2"),ur);var hr;var Tu=(hr=class extends Qn{constructor(r,s,n,i){super(r,n,i);b(this,"keys");this.keys=s}update(r,s){let[n,i,o]=this.getLowerKeyIndexAndRelativeTime(s,this.keys.length,this.timing);if(i==0||this.interpolation=="none")this.setValue(r,this.name,this.keys[n]);else{let d=this.easings?this.easings[n]:this.easing;this.setValue(r,this.name,this.keys[n].lerp(this.keys[n+1],d(i)))}return o}serialize(){return Object.assign(super.serialize(),{keys:this.keys})}},a(hr,"AnimateChannelColor"),hr);function _o(t={}){let e=[],r=0,s=false;return{id:"animate",require:t.followMotion?["rotate"]:void 0,base:{pos:E(0,0),angle:0,scale:E(1,1),opacity:1},animation:{paused:false,seek(n){r=Ne(n,0,this.duration),e.forEach(i=>{i.isFinished=false}),s=false},get duration(){return e.reduce((n,i)=>Math.max(i.duration,n),0)}},add(){t.relative&&(this.has("pos")&&(this.base.pos=this.pos.clone()),this.has("rotate")&&(this.base.angle=this.angle),this.has("scale")&&(this.base.scale=this.scale),this.has("opacity")&&(this.base.opacity=this.opacity))},update(){if(this.animation.paused)return;let n=true,i;r+=ge();for(let o of e)i=o.update(this,r),i&&!o.isFinished&&(o.isFinished=true,this.trigger("animateChannelFinished",o.name)),n&&(n=i);n&&!s&&(s=true,this.trigger("animateFinished"))},animate(n,i,o){s=false,this.unanimate(n),typeof i[0]=="number"?e.push(new Iu(n,i,o,t.relative||false)):i[0]instanceof C?e.push(new Fu(n,i,o,t.relative||false,n==="pos"&&(t.followMotion||false))):i[0]instanceof X&&e.push(new Tu(n,i,o,t.relative||false))},unanimate(n){let i=e.findIndex(o=>o.name===n);i>=0&&e.splice(i,1)},unanimateAll(){e.splice(0,e.length)},onAnimateFinished(n){return this.on("animateFinished",n)},onAnimateChannelFinished(n){return this.on("animateChannelFinished",n)},serializeAnimationChannels(){return e.reduce((n,i)=>(n[i.name]=i.serialize(),n),{})},serializeAnimationOptions(){let n={};return t.followMotion&&(n.followMotion=true),t.relative&&(n.relative=true),n}}}a(_o,"animate");function Xn(t,e){let r={name:t.name};return t.has("animate")&&(r.channels=t.serializeAnimationChannels(),Object.assign(r,t.serializeAnimationOptions())),t.children.length>0&&(r.children=t.children.filter(s=>s.has("named")).map(s=>Xn(s,s.name))),r}a(Xn,"serializeAnimation");function Ys(t=2,e=1){let r=0;return{require:["scale"],update(){let s=Math.sin(r*t)*e;s<0&&this.destroy(),this.scale=E(s),r+=ge()}}}a(Ys,"boom");function el(t,e){if(t==null)throw new Error("health() requires the initial amount of hp");return{id:"health",hurt(r=1){this.setHP(t-r),this.trigger("hurt",r)},heal(r=1){let s=t;this.setHP(t+r),this.trigger("heal",t-s)},hp(){return t},maxHP(){return e??null},setMaxHP(r){e=r},setHP(r){t=e?Math.min(e,r):r,t<=0&&this.trigger("death")},onHurt(r){return this.on("hurt",r)},onHeal(r){return this.on("heal",r)},onDeath(r){return this.on("death",r)},inspect(){return`health: ${t}`}}}a(el,"health");function tl(t,e={}){if(t==null)throw new Error("lifespan() requires time");let r=e.fade??0;return{id:"lifespan",require:["opacity"],add(){c.game.root.wait(t,()=>{this.opacity=this.opacity??1,r>0?c.game.root.tween(this.opacity,0,r,s=>this.opacity=s,qr.linear).onEnd(()=>{this.destroy()}):this.destroy()})}}}a(tl,"lifespan");function rl(t){return{id:"named",name:t}}a(rl,"named");function sl(t,e,r){if(!t)throw new Error("state() requires an initial state");let s={};function n(l){s[l]||(s[l]={enter:new xe,end:new xe,update:new xe,draw:new xe})}a(n,"initStateEvents");function i(l,u,f){return n(u),s[u][l].add(f)}a(i,"on");function o(l,u,...f){n(u),s[u][l].trigger(...f)}a(o,"trigger");let d=false;return{id:"state",state:t,enterState(l,...u){if(d=true,e&&!e.includes(l))throw new Error(`State not found: ${l}`);let f=this.state;if(r){if(!(r==null?void 0:r[f]))return;let x=typeof r[f]=="string"?[r[f]]:r[f];if(!x.includes(l))throw new Error(`Cannot transition state from "${f}" to "${l}". Available transitions: ${x.map(h=>`"${h}"`).join(", ")}`)}o("end",f,...u),this.state=l,o("enter",l,...u),o("enter",`${f} -> ${l}`,...u)},onStateTransition(l,u,f){return i("enter",`${l} -> ${u}`,f)},onStateEnter(l,u){return i("enter",l,u)},onStateUpdate(l,u){return i("update",l,u)},onStateDraw(l,u){return i("draw",l,u)},onStateEnd(l,u){return i("end",l,u)},update(){d||(o("enter",t),d=true),o("update",this.state)},draw(){o("draw",this.state)},inspect(){return`state: ${this.state}`}}}a(sl,"state");function zn(t){return{id:"stay",stay:true,scenesToStay:t}}a(zn,"stay");function nl(t=true,e){let r,s;return{id:"textInput",hasFocus:t,require:["text"],typedText:"",add(){let n=a(()=>{this.text=this.typedText.replace(/([\[\\])/g,"\\$1")},"flip");r=c.k.onCharInput(i=>{this.hasFocus&&(!e||this.typedText.length{this.hasFocus&&(this.typedText=this.typedText.slice(0,-1)),n()})},destroy(){r.cancel(),s.cancel()}}}a(nl,"textInput");function ds(t=1e3){return{id:"timer",maxLoopsPerFrame:t,loop(e,r,s=-1,n=false){let i=n?0:e,o=new xe,d=this.onUpdate(()=>{i+=c.app.state.dt;for(let l=0;i>=e&&l{}),1,true)},tween(e,r,s,n,i=qr.linear){let o=0,d=[],l=this.onUpdate(()=>{o+=c.app.state.dt;let u=Math.min(o/s,1);n(be(e,r,i(u))),u===1&&(l.cancel(),n(r),d.forEach(f=>f()))});return{get paused(){return l.paused},set paused(u){l.paused=u},onEnd(u){d.push(u)},then(u){return this.onEnd(u),this},cancel(){l.cancel()},finish(){l.cancel(),n(r),d.forEach(u=>u())}}}}}a(ds,"timer");var Qs=0;function il(){return Qs>0}a(il,"usesArea");function al(t={}){let e={},r=new Set,s=[];return{id:"area",collisionIgnore:t.collisionIgnore??[],add(){Qs++,this.area.cursor&&s.push(this.onHover(()=>c.app.setCursor(this.area.cursor))),s.push(this.onCollideUpdate((n,i)=>{if(!n.id)throw new Error("area() requires the object to have an id");e[n.id]||this.trigger("collide",n,i),i&&(e[n.id]=i,r.add(n.id))}))},destroy(){Qs--;for(let n of s)n.cancel()},fixedUpdate(){for(let n in e)r.has(Number(n))||(this.trigger("collideEnd",e[n].target),delete e[n]);r.clear()},drawInspect(){let n=this.localArea();qe(),ae(this.area.offset);let i={outline:{width:4/dn(),color:_(0,0,255)},anchor:this.anchor,fill:false,fixed:ut(this)};n instanceof ie?Be({...i,pos:n.pos,width:n.width*this.area.scale.x,height:n.height*this.area.scale.y}):n instanceof Ee?et({...i,pts:n.pts,scale:this.area.scale}):n instanceof Re&&kt({...i,pos:n.center,radius:n.radius}),ve()},area:{shape:t.shape??null,scale:t.scale?E(t.scale):E(1),offset:t.offset??E(0),cursor:t.cursor??null},isClicked(){return c.app.isMousePressed()&&this.isHovering()},isHovering(){let n=ut(this)?c.k.mousePos():c.k.toWorld(c.k.mousePos());return this.hasPoint(n)},checkCollision(n){if(!n.id)throw new Error("checkCollision() requires the object to have an id");return e[n.id]??null},getCollisions(){return Object.values(e)},isColliding(n){if(!n.id)throw new Error("isColliding() requires the object to have an id");return!!e[n.id]},isOverlapping(n){if(!n.id)throw new Error("isOverlapping() requires the object to have an id");let i=e[n.id];return i&&i.hasOverlap()},onClick(n,i="left"){let o=c.app.onMousePress(i,()=>{this.isHovering()&&n()});return s.push(o),o},onHover(n){let i=false;return this.onUpdate(()=>{i?i=this.isHovering():this.isHovering()&&(i=true,n())})},onHoverUpdate(n){return this.onUpdate(()=>{this.isHovering()&&n()})},onHoverEnd(n){let i=false;return this.onUpdate(()=>{i?this.isHovering()||(i=false,n()):i=this.isHovering()})},onCollide(n,i){if(typeof n=="function"&&i===void 0)return this.on("collide",n);if(typeof n=="string")return this.onCollide((o,d)=>{o.is(n)&&(i==null?void 0:i(o,d))});throw new Error("onCollide() requires either a function or a tag")},onCollideUpdate(n,i){if(typeof n=="function"&&i===void 0)return this.on("collideUpdate",n);if(typeof n=="string")return this.on("collideUpdate",(o,d)=>o.is(n)&&(i==null?void 0:i(o,d)));throw new Error("onCollideUpdate() requires either a function or a tag")},onCollideEnd(n,i){if(typeof n=="function"&&i===void 0)return this.on("collideEnd",n);if(typeof n=="string")return this.on("collideEnd",o=>o.is(n)&&(i==null?void 0:i(o)));throw new Error("onCollideEnd() requires either a function or a tag")},hasPoint(n){return tt(this.worldArea(),n)},resolveCollision(n){let i=this.checkCollision(n);i&&!i.resolved&&(this.pos=this.pos.add(i.displacement),i.resolved=true)},localArea(){return this.area.shape?this.area.shape:this.renderArea()},worldArea(){let n=this.localArea();if(!(n instanceof Ee||n instanceof ie))throw new Error("Only support polygon and rect shapes for now");let i=this.transform.clone().translate(this.area.offset).scale(E(this.area.scale??1));if(n instanceof ie){let o=Pt(this.anchor||xs).add(1,1).scale(-.5).scale(n.width,n.height);i.translate(o)}return n.transform(i)},screenArea(){let n=this.worldArea();return ut(this)?n:n.transform(c.game.cam.transform)},inspect(){var n,i,o,d,l,u,f;return((n=this.area.scale)==null?void 0:n.x)==((i=this.area.scale)==null?void 0:i.y)?`area: ${(d=(o=this.area.scale)==null?void 0:o.x)==null?void 0:d.toFixed(1)}x`:`area: (${(u=(l=this.area.scale)==null?void 0:l.x)==null?void 0:u.toFixed(1)}x, ${(f=this.area.scale.y)==null?void 0:f.toFixed(1)}y)`}}}a(al,"area");function ol(t={}){let e=null,r=null,s=false,n=E(0),i=null,o=null,d;return{id:"body",require:["pos"],vel:E(0),drag:t.drag??0,jumpForce:t.jumpForce??Nl,gravityScale:t.gravityScale??1,isStatic:t.isStatic??false,mass:t.mass??1,add(){if(i=this.pos.clone(),o=this.pos.clone(),d=this.pos.clone(),this.mass===0)throw new Error("Can't set body mass to 0");this.has("area")&&(this.onCollideUpdate((l,u)=>{if(!u||!l.has("body")||u.resolved)return;this.trigger("beforePhysicsResolve",u);let f=u.reverse();if(l.trigger("beforePhysicsResolve",f),!(u.resolved||f.resolved)&&!(this.isStatic&&l.isStatic)){if(!this.isStatic&&!l.isStatic){let x=this.mass+l.mass;this.pos=this.pos.add(u.displacement.scale(l.mass/x)),l.pos=l.pos.add(u.displacement.scale(-this.mass/x)),this.transform=Gt(this),l.transform=Gt(l)}else{let x=!this.isStatic&&l.isStatic?u:u.reverse();x.source.pos=x.source.pos.add(x.displacement),x.source.transform=Gt(x.source)}u.resolved=true,this.trigger("physicsResolve",u),l.trigger("physicsResolve",u.reverse())}}),this.onPhysicsResolve(l=>{if(c.game.gravity)if(l.isBottom()&&this.isFalling()){this.vel=this.vel.reject(c.game.gravity.unit());let u=e;e=l.target,u!=e&&(r=l.target.pos),s?s=false:u||(this.trigger("ground",e),l.target.trigger("land",this))}else l.isTop()&&this.isJumping()&&(this.vel=this.vel.reject(c.game.gravity.unit()),this.trigger("headbutt",l.target),l.target.trigger("headbutted",this))}))},update(){e&&this.isColliding(e)&&e.exists()&&e.has("body")&&(r&&!e.pos.eq(r)&&t.stickToPlatform!==false&&this.moveBy(e.pos.sub(r)),r=e.pos);let l=ns();l&&(this.pos.x==d.x&&(this.pos.x=be(i.x,o.x,l/ss()),d.x=this.pos.x),this.pos.y==d.y&&(this.pos.y=be(i.y,o.y,l/ss()),d.y=this.pos.y))},fixedUpdate(){if(i&&(this.pos.x==d.x&&(this.pos.x=i.x),this.pos.y==d.y&&(this.pos.y=i.y),i=null),c.game.gravity&&!this.isStatic){s&&(e=null,r=null,this.trigger("fallOff"),s=false),e&&(!this.isColliding(e)||!e.exists()||!e.has("body"))&&(s=true);let l=this.vel.clone();this.vel=this.vel.add(c.game.gravity.scale(this.gravityScale*ge()));let u=t.maxVelocity??Gl;this.vel.slen()>u*u&&(this.vel=this.vel.unit().scale(u)),l.dot(c.game.gravity)<0&&this.vel.dot(c.game.gravity)>=0&&this.trigger("fall")}if(this.vel.x+=n.x*ge(),this.vel.y+=n.y*ge(),this.vel.x*=1-this.drag*ge(),this.vel.y*=1-this.drag*ge(),this.move(this.vel),ns()){i=this.pos.clone();let l=this.vel.add(n.scale(ge()));o=this.pos.add(l.scale(ge())),d=this.pos.clone()}n.x=0,n.y=0},onPhysicsResolve(l){return this.on("physicsResolve",l)},onBeforePhysicsResolve(l){return this.on("beforePhysicsResolve",l)},curPlatform(){return e},isGrounded(){return e!==null},isFalling(){return this.vel.dot(jt())>0},isJumping(){return this.vel.dot(jt())<0},applyImpulse(l){this.isStatic||(this.vel=this.vel.add(l))},addForce(l){this.isStatic||(n.x+=l.x/this.mass,n.y+=l.y/this.mass)},jump(l){this.isStatic||(e=null,r=null,this.vel=jt().scale(-l||-this.jumpForce))},onGround(l){return this.on("ground",l)},onFall(l){return this.on("fall",l)},onFallOff(l){return this.on("fallOff",l)},onHeadbutt(l){return this.on("headbutt",l)},onLand(l){return this.on("land",l)},onHeadbutted(l){return this.on("headbutted",l)},inspect(){return`gravityScale: ${this.gravityScale}x`}}}a(ol,"body");function ll(t=2){let e=t;return{id:"doubleJump",require:["body"],numJumps:t,add(){this.onGround(()=>{e=this.numJumps})},doubleJump(r){e<=0||(e{var o;let s=r==null?void 0:r.normal.normal(),n=e.vel.project(s),i=(o=s==null?void 0:s.scale(this.speed))==null?void 0:o.sub(n);e.addForce(i==null?void 0:i.scale(e.mass*this.forceScale))})}}}a(ul,"surfaceEffector");function hl(t){return{id:"areaEffector",require:["area"],useGlobalAngle:t.useGlobalAngle||false,forceAngle:t.forceAngle,forceMagnitude:t.forceMagnitude,forceVariation:t.forceVariation??0,linearDrag:t.linearDrag??0,add(){this.onCollideUpdate("body",(e,r)=>{if(!e.has("body"))return;let s=C.fromAngle(this.forceAngle).scale(this.forceMagnitude);e.addForce(s),this.linearDrag&&e.addForce(e.vel.scale(-this.linearDrag))})}}}a(hl,"areaEffector");function dl(t){return{id:"pointEffector",require:["area","pos"],forceMagnitude:t.forceMagnitude,forceVariation:t.forceVariation??0,distanceScale:t.distanceScale??1,forceMode:t.forceMode||"inverseLinear",linearDrag:t.linearDrag??0,add(){this.onCollideUpdate("body",(e,r)=>{let s=this.pos.sub(e.pos),n=s.len(),i=n*this.distanceScale/10,o=this.forceMode==="constant"?1:this.forceMode==="inverseLinear"?1/i:1/i**2,d=s.scale(this.forceMagnitude*o/n);e.addForce(d),this.linearDrag&&e.addForce(e.vel.scale(-this.linearDrag))})}}}a(dl,"pointEffector");function cl(t){return{id:"constantForce",require:["body"],force:t.force,update(){this.force&&this.addForce(this.force)}}}a(cl,"constantForce");function fl(t){return{id:"platformEffector",require:["area","body"],surfaceArc:t.surfaceArc??180,useOneWay:t.useOneWay??false,add(){this.onBeforePhysicsResolve(e=>{let r=e.target.vel,s=jt().scale(-1).angleBetween(r);Math.abs(s)>this.surfaceArc/2&&e.preventResolution()})}}}a(fl,"platformEffector");function gl(t){return{id:"buoyancyEffector",require:["area"],surfaceLevel:t.surfaceLevel,density:t.density??1,linearDrag:t.linearDrag??1,angularDrag:t.angularDrag??.2,flowAngle:t.flowAngle??0,flowMagnitude:t.flowMagnitude??0,flowVariation:t.flowVariation??0,add(){this.onCollideUpdate("body",(e,r)=>{let s=e,n=s.worldArea(),[i,o]=n.cut(E(-100,this.surfaceLevel),E(100,this.surfaceLevel));i&&(this.applyBuoyancy(s,i),this.applyDrag(s,i)),this.flowMagnitude&&s.addForce(C.fromAngle(this.flowAngle).scale(this.flowMagnitude))})},applyBuoyancy(e,r){let s=this.density*r.area(),n=E(0,1).scale(-s);e.addForce(n)},applyDrag(e,r){let s=e.vel,n=this.density*this.linearDrag,i=s.scale(-n);e.addForce(i)}}}a(gl,"buoyancyEffector");function cs(t){if(!t)throw new Error("Please define an anchor");return{id:"anchor",anchor:t,inspect(){return typeof this.anchor=="string"?"anchor: "+this.anchor:"anchor: "+this.anchor.toString()}}}a(cs,"anchor");function Wn(){return{id:"fixed",fixed:true}}a(Wn,"fixed");function pl(t,e){return{id:"follow",require:["pos"],follow:{obj:t,offset:e??E(0)},add(){t.exists()&&(this.pos=this.follow.obj.pos.add(this.follow.offset))},update(){t.exists()&&(this.pos=this.follow.obj.pos.add(this.follow.offset))}}}a(pl,"follow");function ml(t){var r;let e=(r=c.game.layers)==null?void 0:r.indexOf(t);return{id:"layer",get layerIndex(){return e??null},get layer(){var s;return e?((s=c.game.layers)==null?void 0:s[e])??null:null},set layer(s){var n;if(e=(n=c.game.layers)==null?void 0:n.indexOf(s),e==-1)throw Error("Invalid layer name")},inspect(){return`layer: ${this.layer}`}}}a(ml,"layer");function wl(t,e){let r=typeof t=="number"?C.fromAngle(t):t.unit();return{id:"move",require:["pos"],update(){this.move(r.scale(e))}}}a(wl,"move");function yl(t={}){let e=t.distance??Ll,r=false;return{id:"offscreen",require:["pos"],isOffScreen(){let s=this.screenPos();if(!s)return false;let n=new ie(E(0),pe(),we());return!Tr(n,s)&&n.sdistToPoint(s)>e*e},onExitScreen(s){return this.on("exitView",s)},onEnterScreen(s){return this.on("enterView",s)},update(){this.isOffScreen()?(r||(this.trigger("exitView"),r=true),t.hide&&(this.hidden=true),t.pause&&(this.paused=true),t.destroy&&this.destroy()):(r&&(this.trigger("enterView"),r=false),t.hide&&(this.hidden=false),t.pause&&(this.paused=false))}}}a(yl,"offscreen");function Pr(...t){return{id:"pos",pos:E(...t),moveBy(...e){this.pos=this.pos.add(E(...e))},move(...e){this.moveBy(E(...e).scale(ge()))},moveTo(...e){if(typeof e[0]=="number"&&typeof e[1]=="number")return this.moveTo(E(e[0],e[1]),e[2]);let r=e[0],s=e[1];if(s===void 0){this.pos=E(r);return}let n=r.sub(this.pos);if(n.len()<=s*ge()){this.pos=E(r);return}this.move(n.unit().scale(s))},worldPos(e=null){return e?(this.pos=this.pos.add(this.fromWorld(e)),null):this.parent?this.parent.transform.multVec2(this.pos):this.pos},toWorld(e){return this.parent?this.parent.transform.multVec2(this.pos.add(e)):this.pos.add(e)},fromWorld(e){return this.parent?this.parent.transform.invert().multVec2(e).sub(this.pos):e.sub(this.pos)},screenPos(e=null){if(e)return this.pos=this.pos.add(this.fromScreen(e)),null;{let r=this.worldPos();return r?ut(this)?r:us(r):null}},toScreen(e){let r=this.toWorld(e);return ut(this)?r:us(r)},fromScreen(e){return ut(this)?this.fromWorld(e):this.fromWorld(Ln(e))},toOther(e,r){return e.fromWorld(this.toWorld(r))},fromOther(e,r){return e.toOther(this,r)},inspect(){return`pos: (${Math.round(this.pos.x)}x, ${Math.round(this.pos.y)}y)`},drawInspect(){kt({color:_(255,0,0),radius:4/dn()})}}}a(Pr,"pos");function Al(t){return{id:"rotate",angle:t??0,rotateBy(e){this.angle+=e},rotateTo(e){this.angle=e},inspect(){return`angle: ${Math.round(this.angle)}`}}}a(Al,"rotate");function kr(...t){if(t.length===0)return kr(1);let e=E(...t);return{id:"scale",set scale(r){if(!(r instanceof C))throw Error("The scale property on scale is a vector. Use scaleTo or scaleBy to set the scale with a number.");e=E(r)},get scale(){return e},scaleTo(...r){e=E(...r)},scaleBy(...r){e=e.scale(E(...r))},inspect(){return e.x==e.y?`scale: ${e.x.toFixed(1)}x`:`scale: (${e.x.toFixed(1)}x, ${e.y.toFixed(1)}y)`}}}a(kr,"scale");function xl(t){return{id:"z",z:t,inspect(){return`z: ${this.z}`}}}a(xl,"z");var Du="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAACDCAYAAAB2kQxsAAAAAXNSR0IArs4c6QAABqxJREFUeJztnU1yFDkQRtMEB+A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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/4DBC0k0jFtF9wAAAAASUVORK5CYII=";var Uu="3001.0.0";var c={k:null,globalOpt:null,gfx:null,game:null,app:null,assets:null,fontCacheCanvas:null,fontCacheC2d:null,debug:null,audio:null,pixelDensity:null,canvas:null,gscale:null,kaSprite:null,boomSprite:null};var Lu=a((t={tagsAsComponents:true})=>{c.k&&(console.warn("KAPLAY already initialized, you are calling kaplay() multiple times, it may lead bugs!"),c.k.quit()),c.globalOpt=t;let e=t.root??document.body;e===document.body&&(document.body.style.width="100%",document.body.style.height="100%",document.body.style.margin="0px",document.documentElement.style.width="100%",document.documentElement.style.height="100%");let r=t.canvas??e.appendChild(document.createElement("canvas"));c.canvas=r;let s=t.scale??1;c.gscale=s;let n=t.width&&t.height&&!t.stretch&&!t.letterbox;n?(r.width=t.width*s,r.height=t.height*s):(r.width=r.parentElement.offsetWidth,r.height=r.parentElement.offsetHeight);let i=["outline: none","cursor: default"];if(n){let L=r.width,K=r.height;i.push(`width: ${L}px`),i.push(`height: ${K}px`)}else i.push("width: 100%"),i.push("height: 100%");t.crisp&&(i.push("image-rendering: pixelated"),i.push("image-rendering: crisp-edges")),r.style.cssText=i.join(";");let o=t.pixelDensity||1;c.pixelDensity=o,r.width*=o,r.height*=o,r.tabIndex=0;let d=document.createElement("canvas");d.width=256,d.height=256,c.fontCacheCanvas=d;let l=d.getContext("2d",{willReadFrequently:true});c.fontCacheC2d=l;let u=eu({canvas:r,touchToMouse:t.touchToMouse,gamepads:t.gamepads,pixelDensity:t.pixelDensity,maxFPS:t.maxFPS,buttons:t.buttons});c.app=u;let f=[],x=u.canvas.getContext("webgl",{antialias:true,depth:true,stencil:true,alpha:true,preserveDrawingBuffer:true});if(!x)throw new Error("WebGL not supported");let h=x,y=Wa(h,{texFilter:t.texFilter}),p=yu(t,y);c.gfx=p;let S=ku();c.audio=S;let g=gu(y,t.spriteAtlasPadding??0);c.assets=g;let w=Ru();c.game=w,w.root.use(ds());function R(L,K){let Q=new as(y,L,K);return{clear:a(()=>Q.clear(),"clear"),free:a(()=>Q.free(),"free"),toDataURL:a(()=>Q.toDataURL(),"toDataURL"),toImageData:a(()=>Q.toImageData(),"toImageData"),width:Q.width,height:Q.height,draw:a(re=>{Ce(),Q.bind(),re(),Ce(),Q.unbind()},"draw"),get fb(){return Q}}}a(R,"makeCanvas");function P(){h.clear(h.COLOR_BUFFER_BIT),p.frameBuffer.bind(),h.clear(h.COLOR_BUFFER_BIT),p.bgColor||$e(()=>{cr({width:pe(),height:we(),quad:new oe(0,0,pe()/64,we()/64),tex:p.bgTex,fixed:true})}),p.renderer.numDraws=0,p.fixed=false,p.transformStack.length=0,p.transform=new Qe}a(P,"frameStart");function O(L,K){p.postShader=L,p.postShaderUniform=K??null}a(O,"usePostEffect");function T(){Ce(),p.lastDrawCalls=p.renderer.numDraws,p.frameBuffer.unbind(),h.viewport(0,0,h.drawingBufferWidth,h.drawingBufferHeight);let L=p.width,K=p.height;p.width=h.drawingBufferWidth/o,p.height=h.drawingBufferHeight/o,Rr({flipY:true,tex:p.frameBuffer.tex,pos:new C(p.viewport.x,p.viewport.y),width:p.viewport.width,height:p.viewport.height,shader:p.postShader,uniform:typeof p.postShaderUniform=="function"?p.postShaderUniform():p.postShaderUniform,fixed:true}),Ce(),p.width=L,p.height=K}a(T,"frameEnd");let A=false,v={inspect:false,timeScale:1,showLog:true,fps:a(()=>u.fps(),"fps"),numFrames:a(()=>u.numFrames(),"numFrames"),stepFrame:nt,drawCalls:a(()=>p.lastDrawCalls,"drawCalls"),clearLog:a(()=>w.logs=[],"clearLog"),log:a((...L)=>{let K=t.logMax??8,Q=L.length>1?L.concat(" ").join(" "):L[0];w.logs.unshift({msg:Q,time:u.time()}),w.logs.length>K&&(w.logs=w.logs.slice(0,K))},"log"),error:a(L=>v.log(new Error(L.toString?L.toString():L)),"error"),curRecording:null,numObjects:a(()=>V("*",{recursive:true}).length,"numObjects"),get paused(){return A},set paused(L){A=L,L?S.ctx.suspend():S.ctx.resume()}};c.debug=v;function M(L,K){try{return JSON.parse(window.localStorage[L])}catch{return K?(k(L,K),K):null}}a(M,"getData");function k(L,K){window.localStorage[L]=JSON.stringify(K)}a(k,"setData");function I(L,...K){let Q=L(Ge),re;typeof Q=="function"?re=Q(...K)(Ge):re=Q;for(let ce in re)Ge[ce]=re[ce],t.global!==false&&(window[ce]=re[ce]);return Ge}a(I,"plug");function D(L){let K=u.canvas.captureStream(L),Q=S.ctx.createMediaStreamDestination();S.masterNode.connect(Q);let re=new MediaRecorder(K),ce=[];return re.ondataavailable=$=>{$.data.size>0&&ce.push($.data)},re.onerror=()=>{S.masterNode.disconnect(Q),K.getTracks().forEach($=>$.stop())},re.start(),{resume(){re.resume()},pause(){re.pause()},stop(){return re.stop(),S.masterNode.disconnect(Q),K.getTracks().forEach($=>$.stop()),new Promise($=>{re.onstop=()=>{$(new Blob(ce,{type:"video/mp4"}))}})},download($="kaboom.mp4"){this.stop().then(ye=>Ls($,ye))}}}a(D,"record");function U(){return document.activeElement===u.canvas}a(U,"isFocused");let N=w.root.add.bind(w.root),j=w.root.readd.bind(w.root),z=w.root.removeAll.bind(w.root),V=w.root.get.bind(w.root),Y=w.root.wait.bind(w.root),ee=w.root.loop.bind(w.root),J=w.root.query.bind(w.root),W=w.root.tween.bind(w.root),le=Ht(null,Ou),G=Ht(null,Du);c.kaSprite=le,c.boomSprite=G;function Xe(){w.root.fixedUpdate()}a(Xe,"fixedUpdateFrame");function nt(){w.root.update()}a(nt,"updateFrame");const vt=class vt{constructor(K,Q,re,ce,$=false){b(this,"source");b(this,"target");b(this,"normal");b(this,"distance");b(this,"resolved",false);this.source=K,this.target=Q,this.normal=re,this.distance=ce,this.resolved=$}get displacement(){return this.normal.scale(this.distance)}reverse(){return new vt(this.target,this.source,this.normal.scale(-1),this.distance,this.resolved)}hasOverlap(){return!this.displacement.isZero()}isLeft(){return this.displacement.cross(w.gravity||E(0,1))>0}isRight(){return this.displacement.cross(w.gravity||E(0,1))<0}isTop(){return this.displacement.dot(w.gravity||E(0,1))>0}isBottom(){return this.displacement.dot(w.gravity||E(0,1))<0}preventResolution(){this.resolved=true}};a(vt,"Collision");let It=vt;function pr(){if(!il())return;let L={},K=t.hashGridSize||64,Q=new Qe,re=[];function ce($){if(re.push(Q.clone()),$.pos&&Q.translate($.pos),$.scale&&Q.scale($.scale),$.angle&&Q.rotate($.angle),$.transform=Q.clone(),$.c("area")&&!$.paused){let ye=$,it=ye.worldArea().bbox(),Rs=Math.floor(it.pos.x/K),Ps=Math.floor(it.pos.y/K),Vr=Math.ceil((it.pos.x+it.width)/K),Kr=Math.ceil((it.pos.y+it.height)/K),wr=new Set;for(let De=Rs;De<=Vr;De++)for(let ze=Ps;ze<=Kr;ze++)if(!L[De])L[De]={},L[De][ze]=[ye];else if(!L[De][ze])L[De][ze]=[ye];else{let Tt=L[De][ze];e:for(let Ie of Tt){if(Ie.paused||!Ie.exists()||wr.has(Ie.id))continue;for(let We of ye.collisionIgnore)if(Ie.is(We))continue e;for(let We of Ie.collisionIgnore)if(ye.is(We))continue e;let yr=Qi(ye.worldArea(),Ie.worldArea());if(yr){let We=new It(ye,Ie,yr.normal,yr.distance);ye.trigger("collideUpdate",Ie,We);let Ar=We.reverse();Ar.resolved=We.resolved,Ie.trigger("collideUpdate",ye,Ar)}wr.add(Ie.id)}Tt.push(ye)}}$.children.forEach(ce),Q=re.pop()}a(ce,"checkObj"),ce(w.root)}a(pr,"checkFrame");function mr(L){console.error(L),S.ctx.suspend();let K=L.message??String(L)??"Unknown error, check console for more info";u.run(()=>{},()=>{P(),$e(()=>{let Q=pe(),re=we(),ce={size:36,width:Q-32*2,letterSpacing:4,lineSpacing:4,font:ts,fixed:true};Be({width:Q,height:re,color:_(0,0,255),fixed:true});let $=wt({...ce,text:"Error",pos:E(32),color:_(255,128,0),fixed:true});yt($),Vs({...ce,text:K,pos:E(32,32+$.height+16),fixed:true}),ve(),w.events.trigger("error",L)}),T()})}a(mr,"handleErr");function Gr(L){f.push(L)}a(Gr,"onCleanup");function Hr(){w.events.onOnce("frameEnd",()=>{u.quit(),h.clear(h.COLOR_BUFFER_BIT|h.DEPTH_BUFFER_BIT|h.STENCIL_BUFFER_BIT);let L=h.getParameter(h.MAX_TEXTURE_IMAGE_UNITS);for(let K=0;KK())})}a(Hr,"quit");let Ft=true;u.run(()=>{try{g.loaded&&(v.paused||Xe(),pr())}catch(L){mr(L)}},(L,K)=>{try{L(),g.loaded||pt()===1&&!Ft&&(g.loaded=true,fn().forEach(Q=>w.events.trigger("loadError",...Q)),w.events.trigger("load")),!g.loaded&&t.loadingScreen!==false||Ft?(P(),$a(),T()):(v.paused||nt(),pr(),P(),Ja(),t.debug!==false&&Za(),T()),Ft&&(Ft=false),w.events.trigger("frameEnd"),K()}catch(Q){mr(Q)}}),qn(),jn();let Ge={_k:c,VERSION:Uu,loadRoot:Pa,loadProgress:pt,loadSprite:Ht,loadSpriteAtlas:vn,loadSound:Va,loadMusic:Ka,loadBitmapFont:Ua,loadFont:Da,loadShader:Ga,loadShaderURL:Ha,loadAseprite:Ta,loadPedit:La,loadBean:Fa,loadJSON:ka,load:is,getSound:xn,getFont:wn,getBitmapFont:yn,getSprite:gn,getShader:An,getAsset:Ia,Asset:Te,SpriteData:mt,SoundData:Br,width:pe,height:we,center:Cr,dt:ge,fixedDt:ss,restDt:ns,time:u.time,screenshot:u.screenshot,record:D,isFocused:U,setCursor:u.setCursor,getCursor:u.getCursor,setCursorLocked:u.setCursorLocked,isCursorLocked:u.isCursorLocked,setFullscreen:u.setFullscreen,isFullscreen:u.isFullscreen,isTouchscreen:u.isTouchscreen,onLoad:Cs,onLoadError:Mo,onLoading:vo,onResize:bo,onGamepadConnect:u.onGamepadConnect,onGamepadDisconnect:u.onGamepadDisconnect,onError:Eo,onCleanup:Gr,flash:Un,setCamPos:kn,getCamPos:In,setCamRot:Dn,getCamRot:On,setCamScale:Fn,getCamScale:Tn,getCamTransform:So,camPos:Bo,camScale:Ro,camFlash:ko,camRot:Po,camTransform:qo,shake:Co,toScreen:us,toWorld:Ln,setGravity:Io,getGravity:Fo,setGravityDirection:To,getGravityDirection:jt,setBackground:Ea,getBackground:Ma,getGamepads:u.getGamepads,getTreeRoot:jo,add:N,make:Bs,destroy:Kn,destroyAll:z,get:V,query:J,readd:j,pos:Pr,scale:kr,rotate:Al,color:Cn,opacity:Bn,anchor:cs,area:al,sprite:hs,text:Xo,polygon:lo,rect:Pn,circle:ro,uvquad:zo,outline:ao,particles:oo,body:ol,platformEffector:fl,surfaceEffector:ul,areaEffector:hl,pointEffector:dl,buoyancyEffector:gl,constantForce:cl,doubleJump:ll,shader:uo,textInput:nl,timer:ds,fixed:Wn,stay:zn,health:el,lifespan:tl,named:rl,state:sl,z:xl,layer:ml,move:wl,offscreen:yl,follow:pl,fadeIn:no,mask:io,drawon:so,raycast:Rn,tile:Yn,animate:_o,serializeAnimation:Xn,agent:Wo,sentry:$o,patrol:Jo,pathfinder:Zo,trigger:xu,on:Me,onFixedUpdate:vu,onUpdate:bu,onDraw:Eu,onAdd:co,onDestroy:Mu,onTag:fo,onUntag:Cu,onUse:Su,onUnuse:qu,onClick:Bu,onCollide:po,onCollideUpdate:mo,onCollideEnd:wo,onHover:yo,onHoverUpdate:Ao,onHoverEnd:xo,onKeyDown:u.onKeyDown,onKeyPress:u.onKeyPress,onKeyPressRepeat:u.onKeyPressRepeat,onKeyRelease:u.onKeyRelease,onMouseDown:u.onMouseDown,onMousePress:u.onMousePress,onMouseRelease:u.onMouseRelease,onMouseMove:u.onMouseMove,onCharInput:u.onCharInput,onTouchStart:u.onTouchStart,onTouchMove:u.onTouchMove,onTouchEnd:u.onTouchEnd,onScroll:u.onScroll,onHide:u.onHide,onShow:u.onShow,onGamepadButtonDown:u.onGamepadButtonDown,onGamepadButtonPress:u.onGamepadButtonPress,onGamepadButtonRelease:u.onGamepadButtonRelease,onGamepadStick:u.onGamepadStick,onButtonPress:u.onButtonPress,onButtonDown:u.onButtonDown,onButtonRelease:u.onButtonRelease,mousePos:cn,mouseDeltaPos:u.mouseDeltaPos,isKeyDown:u.isKeyDown,isKeyPressed:u.isKeyPressed,isKeyPressedRepeat:u.isKeyPressedRepeat,isKeyReleased:u.isKeyReleased,isMouseDown:u.isMouseDown,isMousePressed:u.isMousePressed,isMouseReleased:u.isMouseReleased,isMouseMoved:u.isMouseMoved,isGamepadButtonPressed:u.isGamepadButtonPressed,isGamepadButtonDown:u.isGamepadButtonDown,isGamepadButtonReleased:u.isGamepadButtonReleased,getGamepadStick:u.getGamepadStick,isButtonPressed:u.isButtonPressed,isButtonDown:u.isButtonDown,isButtonReleased:u.isButtonReleased,setButton:u.setButton,getButton:u.getButton,pressButton:u.pressButton,releaseButton:u.releaseButton,getLastInputDeviceType:u.getLastInputDeviceType,charInputted:u.charInputted,loop:ee,wait:Y,play:Oo,setVolume:Gn,getVolume:Hn,volume:Uo,burp:Nn,audioCtx:S.ctx,Line:ke,Rect:ie,Circle:Re,Ellipse:rt,Point:Rl,Polygon:Ee,Vec2:C,Color:X,Mat4:Qe,Quad:oe,RNG:hi,rand:fe,randi:zs,randSeed:di,vec2:E,rgb:_,hsl2rgb:ql,quad:he,choose:gi,chooseMultiple:fi,shuffle:Ws,chance:ci,lerp:be,tween:W,easings:qr,map:Le,mapc:ui,wave:Xs,deg2rad:de,rad2deg:gt,clamp:Ne,evaluateQuadratic:Pi,evaluateQuadraticFirstDerivative:ki,evaluateQuadraticSecondDerivative:Ii,evaluateBezier:As,evaluateBezierFirstDerivative:Fi,evaluateBezierSecondDerivative:Ti,evaluateCatmullRom:Di,evaluateCatmullRomFirstDerivative:Oi,curveLengthApproximation:nn,normalizedCurve:Ui,hermite:gr,cardinal:an,catmullRom:Mr,bezier:Li,kochanekBartels:Ni,easingSteps:Yi,easingLinear:Vi,easingCubicBezier:Ki,testLineLine:fs,testRectRect:Zs,testRectLine:gs,testRectPoint:Tr,testCirclePolygon:Or,testLinePoint:ps,testLineCircle:fr,isConvex:Ji,triangulate:ln,NavMesh:cu,drawSprite:eo,drawText:Vs,formatText:wt,drawRect:Be,drawLine:Nt,drawLines:qs,drawTriangle:Mn,drawCircle:kt,drawEllipse:bn,drawUVQuad:cr,drawPolygon:et,drawCurve:En,drawBezier:za,drawFormattedText:yt,drawMasked:_a,drawSubtracted:to,pushTransform:qe,popTransform:ve,pushTranslate:ae,pushScale:dr,pushRotate:Ct,pushMatrix:Sa,usePostEffect:O,makeCanvas:R,debug:v,scene:Vo,getSceneName:Qo,go:Ko,onSceneLeave:Yo,layers:Ho,getLayers:No,setLayers:Vn,getDefaultLayer:Go,addLevel:ho,getData:M,setData:k,download:vs,downloadJSON:ia,downloadText:hn,downloadBlob:Ls,plug:I,ASCII_CHARS:$i,canvas:u.canvas,addKaboom:Lo,LEFT:C.LEFT,RIGHT:C.RIGHT,UP:C.UP,DOWN:C.DOWN,RED:X.RED,GREEN:X.GREEN,BLUE:X.BLUE,YELLOW:X.YELLOW,MAGENTA:X.MAGENTA,CYAN:X.CYAN,WHITE:X.WHITE,BLACK:X.BLACK,quit:Hr,KEvent:xe,KEventHandler:Sr,KEventController:Bt,cancel:a(()=>ea,"cancel")};c.k=Ge;let jr=t.plugins;if(jr&&jr.forEach(I),t.global!==false)for(let L in Ge)window[L]=Ge[L];return t.focus!==false&&u.canvas.focus(),Ge},"kaplay");var Nu=Lu;Nu();var Ir=(t=>{t["Game"]="Game";t["Preload"]="Preload";return t})(Ir||{});var ot=(t=>{t["Bean"]="Bean";t["Bubbie"]="Bubbie";t["Ghosty"]="Ghosty";t["Pokey"]="Pokey";return t})(ot||{});var Fr=(t=>{t["Bullet"]="Bullet";t["Enemy"]="Enemy";t["Player"]="Player";return t})(Fr||{});const Gu=200;const Hu=20;function ju(t){const e=add([pos(t.pos),move(Vu(t),Gu),circle(30),area(),offscreen({destroy:true}),anchor("center"),color(0,0,255),Fr.Bullet]);e.onCollide(Fr.Enemy,r=>{e.destroy();const s=r;s.hurt(Hu)});return e}function Vu(t){const e=mousePos();const r=t.screenPos();const s=Math.atan2(e.y-r.y,e.x-r.x);const n=s*180/Math.PI;return n}function Ku(t,e,r){const s=rand(100,300);const n=[ot.Bubbie,ot.Pokey];const i=add([sprite(n[randi(n.length)]),pos(t,e),anchor("center"),health(100),opacity(1),area(),Fr.Enemy,{speed:s}]);i.onUpdate(()=>{const o=r.pos.sub(i.pos).unit();i.move(o.scale(i.speed))});i.onHurt(()=>{i.opacity=i.hp()/100});i.onDeath(()=>{i.destroy();addKaboom(i.pos)});return i}function Yu(t){const e=new Qu(t);onClick(()=>{if(e.canAttack()){e.update();ju(t)}})}class Qu{constructor(e){this.attackDelay=1;this.lastAttacked=0;this.player=e}update(){this.lastAttacked=time()}canAttack(){return!this.lastAttacked?true:this.lastAttacked+this.attackDelay{switch(e){case"left":case"a":t.move(-zr,0);Wr(t);break;case"right":case"d":t.move(zr,0);Wr(t);break;case"up":case"w":t.move(0,-zr);Wr(t);break;case"down":case"s":t.move(0,zr);Wr(t);break}})}function Wr(t){setCamPos(t.worldPos())}function zu(t=center().x,e=center().y){const r=add([sprite(ot.Bean),pos(t,e),rotate(0),anchor("center"),area(),Fr.Player]);Xu(r);Yu(r);return r}function Wu(){return Boolean(randi(2))}function Zu(t,e){const r=width()/2;const s=height()/2;const n=Wu()?1:-1;return{x:t+r*n,y:e+s*n}}scene(Ir.Game,()=>{const t=zu();add([text("Press arrow keys",{width:width()/2}),pos(12,12)]);loop(5,()=>{const{x:e,y:r}=Zu(t.pos.x,t.pos.y);Ku(e,r,t)})});scene(Ir.Preload,()=>{[[ot.Bean,"sprites/bean.png"],[ot.Bubbie,"sprites/bubbie.png"],[ot.Ghosty,"sprites/ghosty.png"],[ot.Pokey,"sprites/pokey.png"]].forEach(([t,e])=>{loadSprite(t,e)});go(Ir.Game)});function Ju(){go(Ir.Preload)}Ju(); diff --git a/index.html b/index.html new file mode 100644 index 0000000..c767858 --- /dev/null +++ b/index.html @@ -0,0 +1,7 @@ +Kiki and Boba | remarkablegames \ No newline at end of file diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..ef31299 Binary files /dev/null and b/logo.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..24a695d --- /dev/null +++ b/manifest.json @@ -0,0 +1,15 @@ +{ + "short_name": "Kiki and Boba", + "name": "Kiki and Boba", + "icons": [ + { + "src": "logo.png", + "type": "image/png", + "sizes": "72x72" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/sounds/score.mp3 b/sounds/score.mp3 new file mode 100644 index 0000000..e068db0 Binary files /dev/null and b/sounds/score.mp3 differ diff --git a/sprites/apple.png b/sprites/apple.png new file mode 100644 index 0000000..a7d81ff Binary files /dev/null and b/sprites/apple.png differ diff --git a/sprites/bag.png b/sprites/bag.png new file mode 100644 index 0000000..3b0ba4d Binary files /dev/null and b/sprites/bag.png differ diff --git a/sprites/bean.png b/sprites/bean.png new file mode 100644 index 0000000..66637b6 Binary files /dev/null and b/sprites/bean.png differ diff --git a/sprites/bobo.png b/sprites/bobo.png new file mode 100644 index 0000000..a946bf8 Binary files /dev/null and b/sprites/bobo.png differ diff --git a/sprites/boom.png b/sprites/boom.png new file mode 100644 index 0000000..6289876 Binary files /dev/null and b/sprites/boom.png differ diff --git a/sprites/btfly.png b/sprites/btfly.png new file mode 100644 index 0000000..d71338b Binary files /dev/null and b/sprites/btfly.png differ diff --git a/sprites/bubbie.png b/sprites/bubbie.png new file mode 100644 index 0000000..913458a Binary files /dev/null and b/sprites/bubbie.png differ diff --git a/sprites/cloud.png b/sprites/cloud.png new file mode 100644 index 0000000..05f93c9 Binary files /dev/null and b/sprites/cloud.png differ diff --git a/sprites/coin.png b/sprites/coin.png new file mode 100644 index 0000000..146a3d7 Binary files /dev/null and b/sprites/coin.png differ diff --git a/sprites/cursor_default.png b/sprites/cursor_default.png new file mode 100644 index 0000000..1a741a4 Binary files /dev/null and b/sprites/cursor_default.png differ diff --git a/sprites/cursor_pointer.png b/sprites/cursor_pointer.png new file mode 100644 index 0000000..4412581 Binary files /dev/null and b/sprites/cursor_pointer.png differ diff --git a/sprites/dino.png b/sprites/dino.png new file mode 100644 index 0000000..edee654 Binary files /dev/null and b/sprites/dino.png differ diff --git a/sprites/door.png b/sprites/door.png new file mode 100644 index 0000000..87d020c Binary files /dev/null and b/sprites/door.png differ diff --git a/sprites/egg.png b/sprites/egg.png new file mode 100644 index 0000000..f37a364 Binary files /dev/null and b/sprites/egg.png differ diff --git a/sprites/egg_crack.png b/sprites/egg_crack.png new file mode 100644 index 0000000..7192a74 Binary files /dev/null and b/sprites/egg_crack.png differ diff --git a/sprites/ghosty.png b/sprites/ghosty.png new file mode 100644 index 0000000..4f2f3be Binary files /dev/null and b/sprites/ghosty.png differ diff --git a/sprites/gigagantrum.png b/sprites/gigagantrum.png new file mode 100644 index 0000000..039dc9f Binary files /dev/null and b/sprites/gigagantrum.png differ diff --git a/sprites/grape.png b/sprites/grape.png new file mode 100644 index 0000000..1427dd4 Binary files /dev/null and b/sprites/grape.png differ diff --git a/sprites/grass.png b/sprites/grass.png new file mode 100644 index 0000000..342993e Binary files /dev/null and b/sprites/grass.png differ diff --git a/sprites/gun.png b/sprites/gun.png new file mode 100644 index 0000000..f5d32bc Binary files /dev/null and b/sprites/gun.png differ diff --git a/sprites/heart.png b/sprites/heart.png new file mode 100644 index 0000000..a787a7f Binary files /dev/null and b/sprites/heart.png differ diff --git a/sprites/jumpy.png b/sprites/jumpy.png new file mode 100644 index 0000000..78ae7bb Binary files /dev/null and b/sprites/jumpy.png differ diff --git a/sprites/k.png b/sprites/k.png new file mode 100644 index 0000000..20d23b2 Binary files /dev/null and b/sprites/k.png differ diff --git a/sprites/ka.png b/sprites/ka.png new file mode 100644 index 0000000..1bf2dd7 Binary files /dev/null and b/sprites/ka.png differ diff --git a/sprites/key.png b/sprites/key.png new file mode 100644 index 0000000..7552dfb Binary files /dev/null and b/sprites/key.png differ diff --git a/sprites/lightening.png b/sprites/lightening.png new file mode 100644 index 0000000..8645c7b Binary files /dev/null and b/sprites/lightening.png differ diff --git a/sprites/mark.png b/sprites/mark.png new file mode 100644 index 0000000..7c57042 Binary files /dev/null and b/sprites/mark.png differ diff --git a/sprites/meat.png b/sprites/meat.png new file mode 100644 index 0000000..292568d Binary files /dev/null and b/sprites/meat.png differ diff --git a/sprites/moon.png b/sprites/moon.png new file mode 100644 index 0000000..cd36c16 Binary files /dev/null and b/sprites/moon.png differ diff --git a/sprites/mushroom.png b/sprites/mushroom.png new file mode 100644 index 0000000..3ed177d Binary files /dev/null and b/sprites/mushroom.png differ diff --git a/sprites/note.png b/sprites/note.png new file mode 100644 index 0000000..2bd770f Binary files /dev/null and b/sprites/note.png differ diff --git a/sprites/pineapple.png b/sprites/pineapple.png new file mode 100644 index 0000000..894063b Binary files /dev/null and b/sprites/pineapple.png differ diff --git a/sprites/pokey.png b/sprites/pokey.png new file mode 100644 index 0000000..aedab37 Binary files /dev/null and b/sprites/pokey.png differ diff --git a/sprites/portal.png b/sprites/portal.png new file mode 100644 index 0000000..49b52eb Binary files /dev/null and b/sprites/portal.png differ diff --git a/sprites/spike.png b/sprites/spike.png new file mode 100644 index 0000000..94d814e Binary files /dev/null and b/sprites/spike.png differ diff --git a/sprites/steel.png b/sprites/steel.png new file mode 100644 index 0000000..ee896f1 Binary files /dev/null and b/sprites/steel.png differ diff --git a/sprites/sun.png b/sprites/sun.png new file mode 100644 index 0000000..3628ee7 Binary files /dev/null and b/sprites/sun.png differ diff --git a/sprites/sword.png b/sprites/sword.png new file mode 100644 index 0000000..99cf100 Binary files /dev/null and b/sprites/sword.png differ diff --git a/sprites/watermelon.png b/sprites/watermelon.png new file mode 100644 index 0000000..129ab67 Binary files /dev/null and b/sprites/watermelon.png differ