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-BvzMacPY.js b/assets/index-BvzMacPY.js new file mode 100644 index 0000000..d33aa24 --- /dev/null +++ b/assets/index-BvzMacPY.js @@ -0,0 +1,56 @@ +var Il=Object.defineProperty;var Tl=(t,e,r)=>e in t?Il(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var b=(t,e,r)=>Tl(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 Fl=Object.defineProperty;var a=(t,e)=>Fl(t,"name",{value:e,configurable:true});var Dl=(()=>{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=je(e,0,255),this.g=je(r,0,255),this.b=je(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,c)=>(c<0&&(c+=1),c>1&&(c-=1),c<1/6?f+(x-f)*6*c:c<1/2?x:c<2/3?f+(x-f)*(2/3-c)*6:f),"hue2rgb"),i=s<.5?s*(1+r):s+r-s*r,o=2*s-i,h=n(o,i,e+1/3),l=n(o,i,e),u=n(o,i,e-1/3);return new Z(Math.round(h*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(Se(this.r,e.r,r),Se(this.g,e.g,r),Se(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,h=o,l=o;if(n==i)o=h=0;else{let u=n-i;switch(h=l>.5?u/(2-n-i):u/(n+i),n){case e:o=(r-s)/u+(rX.fromHSL(t,e,r),"hsl2rgb");function ce(t){return t*Math.PI/180}a(ce,"deg2rad");function yt(t){return t*180/Math.PI}a(yt,"rad2deg");function je(t,e,r){return e>r?je(t,r,e):Math.min(Math.max(t,e),r)}a(je,"clamp");function Se(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(Se,"lerp");function Ge(t,e,r,s,n){return s+(t-e)/(r-e)*(n-s)}a(Ge,"map");function wi(t,e,r,s,n){return je(Ge(t,e,r,s,n),s,n)}a(wi,"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=ce(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 yt(Math.atan2(this.y-r.y,this.x-r.x))}angleBetween(...e){let r=E(...e);return yt(Math.atan2(this.cross(r),this.dot(r)))}lerp(e,r){return new te(Se(this.x,e.x,r),Se(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 pt;var oe=(pt=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 pt(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 pt(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(pt,"Quad"),pt);function he(t,e,r,s){return new oe(t,e,r,s)}a(he,"quad");var Ne;var ss=(Ne=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 Ne(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 Ne(this.d/e,-this.b/e,-this.c/e,this.a/e)}get transpose(){return new Ne(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 yt(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],h=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],c=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],g=this.m[4]*this.m[13]-this.m[12]*this.m[5],M=this.m[6]*this.m[11]-this.m[10]*this.m[7],p=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]*h,e[12]=-(this.m[4]*n-this.m[5]*o+this.m[6]*h),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]*h),e[13]=this.m[0]*n-this.m[1]*o+this.m[2]*h,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]*c),e[10]=this.m[0]*y-this.m[1]*x+this.m[3]*g,e[14]=-(this.m[0]*f-this.m[1]*c+this.m[2]*g),e[3]=-(this.m[1]*M-this.m[2]*p+this.m[3]*w),e[7]=this.m[0]*M-this.m[2]*R+this.m[3]*P,e[11]=-(this.m[0]*p-this.m[1]*R+this.m[3]*O),e[15]=this.m[0]*w-this.m[1]*P+this.m[2]*O;let F=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/F;return new ve(e)}clone(){return new ve([...this.m])}toString(){return this.m.toString()}},a(ve,"Mat4"),ve);function $s(t,e,r,s=n=>-Math.cos(n)){return t+(s(r)+1)/2*(e-t)}a($s,"wave");var Ll=1103515245;var Ul=12345;var ui=2147483648;var Wt;var yi=(Wt=class{constructor(e){b(this,"seed");this.seed=e}gen(){return this.seed=(Ll*this.seed+Ul)%ui,this.seed/ui}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(Wt,"RNG"),Wt);var Us=new yi(Date.now());function Ai(t){return t!=null&&(Us.seed=t),Us.seed}a(Ai,"randSeed");function pe(...t){return Us.genAny(...t)}a(pe,"rand");function _s(...t){return Math.floor(pe(...t.length>0?t:[2]))}a(_s,"randi");function xi(t){return pe()<=t}a(xi,"chance");function en(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(en,"shuffle");function vi(t,e){return t.length<=e?t.slice():en(t.slice()).slice(0,e)}a(vi,"chooseMultiple");function bi(t){return t[_s(t.length)]}a(bi,"choose");function tn(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(Ei,"testLineLineT");function ms(t,e){let r=Ei(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(ms,"testLineLine");function ws(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(ws,"testRectLine");function Ur(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(ys,"testLinePoint");function Ar(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,h=i*i-4*s*o;if(s<=Number.EPSILON||h<0)return false;if(h==0){let l=-i/(2*s);if(l>=0&&l<=1)return true}else{let l=(-i+Math.sqrt(h))/(2*s),u=(-i-Math.sqrt(h))/(2*s);if(l>=0&&l<=1||u>=0&&u<=1)return true}return Nr(e,t.p1)}a(Ar,"testLineCircle");function As(t,e){if(at(e,t.p1)||at(e,t.p2))return true;for(let r=0;rat(e,r))||e.pts.some(r=>at(t,r)))}a(nn,"testPolygonPolygon");function at(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(at,"testPolygonPoint");function xs(t,e){e=e.sub(t.center);let r=ce(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(xs,"testEllipsePoint");function Rr(t,e){let r=e.center.sub(t.center),s=ce(t.angle),n=Math.cos(s),i=Math.sin(s),o=r.x*n+r.y*i,h=-r.x*i+r.y*n;return xs(new ot(E(),t.radiusX+e.radius,t.radiusY+e.radius,0),E(o,h))}a(Rr,"testEllipseCircle");function an(t,e){let r=t.toMat2().inverse;return e=new Fe(r.transform(e.p1.sub(t.center)),r.transform(e.p2.sub(t.center))),Ar(e,new Ie(E(),1))}a(an,"testEllipseLine");function Mi(t,e){if(t.radiusX===t.radiusY)return Rr(e,new Ie(t.center,t.radiusX));if(e.radiusX===e.radiusY)return Rr(t,new Ie(e.center,e.radiusX));let r=new qr(1/t.radiusX**2,0,0,0,1/t.radiusY**2,0,0,0,-1),s=new qr(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,h=e.center.y,l=ce(t.angle),u=ce(e.angle),f=new qr(Math.cos(l),-Math.sin(l),n,Math.sin(l),Math.cos(l),i,0,0,1),x=new qr(Math.cos(u),-Math.sin(u),o,Math.sin(u),Math.cos(u),h,0,0,1),c=f.inverse,y=x.inverse,g=c.transpose.mul(r).mul(c),M=y.transpose.mul(s).mul(y),p=g.m11,w=g.m12,R=g.m13,P=g.m21,O=g.m22,F=g.m23,A=g.m31,v=g.m32,S=g.m33,k=M.m11,I=M.m12,D=M.m13,L=M.m21,N=M.m22,j=M.m23,z=M.m31,V=M.m32,Y=M.m33,ee=p*O*S-p*F*v-w*P*S+w*F*A+R*P*v-R*O*A,J=(p*O*Y-p*F*V-p*v*j+p*S*N-w*P*Y+w*F*z+w*A*j-w*S*L+R*P*V-R*O*z-R*A*N+R*v*L+P*v*D-P*S*I-O*A*D+O*S*k+F*A*I-F*v*k)/ee,W=(p*N*Y-p*j*V-w*L*Y+w*j*z+R*L*V-R*N*z-P*I*Y+P*D*V+O*k*Y-O*D*z-F*k*V+F*I*z+A*I*j-A*D*N-v*k*j+v*D*L+S*k*N-S*I*L)/ee,le=(k*N*Y-k*j*V-I*L*Y+I*j*z+D*L*V-D*N*z)/ee;if(J>=0){let H=-3*W+J**2,$e=3*J*le+W*J**2-4*W**2,ut=-27*le**2+18*le*J*W+J**2*W**2-4*J**3*le-4*W**3;return!(H>0&&$e<0&&ut>0)}else{let H=-3*W+J**2,$e=-27*le**2+18*le*J*W+J**2*W**2-4*J**3*le-4*W**3;return!(H>0&&$e>0)}}a(Mi,"testEllipseEllipse");function on(t,e){return vs(t,new Me(e.points()))}a(on,"testEllipseRect");function vs(t,e){let r=t.toMat2().inverse;return e=new Me(e.pts.map(s=>r.transform(s.sub(t.center)))),Hr(new Ie(E(),1),e)}a(vs,"testEllipsePolygon");function qi(t,e){return t.x===e.x&&t.y===e.y}a(qi,"testPointPoint");function Ci(t,e){return e instanceof C?qi(e,t.pt):e instanceof Ie?Nr(e,t.pt):e instanceof Fe?ys(e,t.pt):e instanceof ie?Ur(e,t.pt):e instanceof Me?at(e,t.pt):e instanceof ot?xs(e,t.pt):false}a(Ci,"testPointShape");function Bi(t,e){return e instanceof C?ys(t,e):e instanceof Ie?Ar(t,e):e instanceof Fe?ms(t,e)!=null:e instanceof ie?ws(e,t):e instanceof Me?As(t,e):e instanceof ot?an(e,t):false}a(Bi,"testLineShape");function Ri(t,e){return e instanceof C?Nr(t,e):e instanceof Ie?Si(t,e):e instanceof Fe?Ar(e,t):e instanceof ie?rn(e,t):e instanceof Me?Hr(t,e):e instanceof ot?Rr(e,t):false}a(Ri,"testCircleShape");function Pi(t,e){return e instanceof C?Ur(t,e):e instanceof Ie?rn(t,e):e instanceof Fe?ws(t,e):e instanceof ie?tn(t,e):e instanceof Me?sn(t,e):e instanceof ot?on(e,t):false}a(Pi,"testRectShape");function ki(t,e){return e instanceof C?at(t,e):e instanceof Ie?Hr(e,t):e instanceof Fe?As(e,t):e instanceof ie?sn(e,t):e instanceof Me?nn(e,t):e instanceof ot?vs(e,t):false}a(ki,"testPolygonShape");function Ii(t,e){return e instanceof C?xs(t,e):e instanceof Ie?Rr(t,e):e instanceof Fe?an(t,e):e instanceof ie?on(t,e):e instanceof Me?vs(t,e):e instanceof ot?Mi(e,t):false}a(Ii,"testEllipseShape");function ln(t,e,r){let s=t,n=r.p1,i=r.p2,o=e,h=i.sub(n),l=o.cross(h);if(Math.abs(l)=1)return null;let x=u.cross(o)/l;if(x<=0||x>=1)return null;let c=h.normal().unit();return e.dot(c)>0&&(c.x*=-1,c.y*=-1),{point:s.add(o.scale(f)),normal:c,fraction:f}}a(ln,"raycastLine");function Ti(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,h=(r.pos.x+r.width-t.x)/e.x;i=E(-Math.sign(e.x),0),s=Math.max(s,Math.min(o,h)),n=Math.min(n,Math.max(o,h))}if(t.y!=0){let o=(r.pos.y-t.y)/e.y,h=(r.pos.y+r.height-t.y)/e.y;Math.min(o,h)>s&&(i=E(0,-Math.sign(e.y))),s=Math.max(s,Math.min(o,h)),n=Math.min(n,Math.max(o,h))}return n>=s&&s>=0&&s<=1?{point:t.add(e.scale(s)),normal:i,fraction:s}:null}a(Ti,"raycastRect");function un(t,e,r){let s=t,n=r.center,i=e,o=i.dot(i),h=s.sub(n),l=2*i.dot(h),u=h.dot(h)-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 c=s.add(i.scale(x));return{point:c,normal:c.sub(n),fraction:x}}}else{let x=(-l+Math.sqrt(f))/(2*o),c=(-l-Math.sqrt(f))/(2*o),y=null;if(x>=0&&x<=1&&(y=x),c>=0&&c<=1&&(y=Math.min(c,y??c)),y!=null){let g=s.add(i.scale(y));return{point:g,normal:g.sub(n).unit(),fraction:y}}}return null}a(un,"raycastCircle");function Fi(t,e,r){let s=r.pts,n=null,i=s[s.length-1];for(let o=0;ol.fraction)&&(n=l),i=h}return n}a(Fi,"raycastPolygon");function Di(t,e,r){let s=r.toMat2(),n=s.inverse,i=n.transform(t.sub(r.center)),o=n.transform(e),h=un(i,o,new Ie(E(),1));if(h){let l=ss.rotation(ce(-r.angle)),u=ss.scale(r.radiusX,r.radiusY).transform(h.point),f=s.transform(h.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 h}a(Di,"raycastEllipse");function Oi(t,e,r,s=64){let n=t,i=e.len(),o=e.scale(1/i),h=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),c=E(f.x<1/0?f.x*x.x:1/0,f.y<1/0?f.y*x.y:1/0),y=-1;for(;h<=s;){let g=r(l);if(g===true)return{point:n.add(o.scale(h)),normal:E(y===0?-u.x:0,y===1?-u.y:0),fraction:h/i,gridPos:l};if(g)return g;c.xe.multVec2(r)))}bbox(){return this.clone()}area(){return this.width*this.height}clone(){return new wt(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 Pi(this,e)}contains(e){return this.collides(e)}raycast(e,r){return Ti(e,r,this)}random(){return this.pos.add(pe(this.width),pe(this.height))}},a(wt,"Rect"),wt);var Bt;var Ie=(Bt=class{constructor(e,r){b(this,"center");b(this,"radius");this.center=e.clone(),this.radius=r}transform(e){return new ot(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 Bt(this.center,this.radius)}collides(e){return Ri(this,e)}contains(e){return this.collides(e)}raycast(e,r){return un(e,r,this)}random(){return this.center.add(C.fromAngle(pe(360)).scale(pe(this.radius)))}},a(Bt,"Circle"),Bt);var He;var ot=(He=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,h]=s.eigenvectors(n,i),[l,u]=[1/Math.sqrt(n),1/Math.sqrt(i)];return l>u?new He(E(),l,u,yt(Math.atan2(-o[1],o[0]))):new He(E(),u,l,yt(Math.atan2(-h[1],h[0])))}toMat2(){let e=ce(this.angle),r=Math.cos(e),s=Math.sin(e);return new ss(r*this.radiusX,-s*this.radiusY,s*this.radiusX,r*this.radiusY)}transform(e){if(this.angle==0&&e.getRotation()==0)return new He(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=qr.fromMat2(r).scale(n.x,n.y).rotate(s).toMat2();let i=He.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=ce(this.angle),r=Math.cos(e),s=Math.sin(e),n=this.radiusX*r,i=this.radiusX*s,o=this.radiusY*s,h=this.radiusY*r,l=Math.sqrt(n*n+o*o),u=Math.sqrt(i*i+h*h);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 He(this.center,this.radiusX,this.radiusY,this.angle)}collides(e){return Ii(this,e)}contains(e){e=e.sub(this.center);let r=ce(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 Di(e,r,this)}random(){return this.center}},a(He,"Ellipse"),He);function Li(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(Li,"segmentLineIntersection");var ze;var Me=(ze=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 ze(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 ki(this,e)}contains(e){return this.collides(e)}raycast(e,r){return Fi(e,r,this)}random(){return E()}cut(e,r){new Fe(e,r);let s=[],n=[],i=r.sub(e),o=this.pts[this.pts.length-1],h=o.sub(e),l=i.cross(h)>0;return this.pts.forEach(u=>{h=u.sub(e);let f=i.cross(h)>0;if(l!=f){let x=Li(o,u,e,r);s.push(x),n.push(x),l=f}(f?s:n).push(u),o=u}),[s.length?new ze(s):null,n.length?new ze(n):null]}},a(ze,"Polygon"),ze);function Ui(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(Ui,"evaluateQuadratic");function Ni(t,e,r,s){let n=1-s;return e.sub(t).scale(2*n).add(r.sub(e).scale(2*s))}a(Ni,"evaluateQuadraticFirstDerivative");function Hi(t,e,r,s){return r.sub(e.scale(2)).add(t).scale(2)}a(Hi,"evaluateQuadraticSecondDerivative");function bs(t,e,r,s,n){let i=n*n,o=i*n,h=1-n,l=h*h,u=l*h;return t.scale(u).add(e.scale(3*l*n)).add(r.scale(3*h*i)).add(s.scale(o))}a(bs,"evaluateBezier");function Gi(t,e,r,s,n){let i=n*n,o=1-n,h=o*o;return e.sub(t).scale(3*h).add(r.sub(e).scale(6*o*n)).add(s.sub(r).scale(3*i))}a(Gi,"evaluateBezierFirstDerivative");function ji(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(ji,"evaluateBezierSecondDerivative");function Vi(t,e,r,s,n){let i=.5*(((-n+2)*n-1)*n),o=.5*((3*n-5)*n*n+2),h=.5*(((-3*n+4)*n+1)*n),l=.5*((n-1)*n*n);return t.scale(i).add(e.scale(o)).add(r.scale(h)).add(s.scale(l))}a(Vi,"evaluateCatmullRom");function Ki(t,e,r,s,n){let i=.5*((-3*n+4)*n-1),o=.5*((9*n-10)*n),h=.5*((-9*n+8)*n+1),l=.5*((3*n-2)*n);return t.scale(i).add(e.scale(o)).add(r.scale(h)).add(s.scale(l))}a(Ki,"evaluateCatmullRomFirstDerivative");function Yi(t){let e=hn(t),r=e(1);return s=>{let n=s*r,i=e(n,true);return t(i)}}a(Yi,"normalizedCurve");function hn(t,e=10,r=10){let s=[0],n=[0],i=1/(e-1)/r,o=0,h=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 c=0;for(;s[c+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+h}}a(xr,"hermite");function cn(t,e,r,s,n,i=xr){let o=i(e.x,(1-n)*(r.x-t.x),(1-n)*(s.x-e.x),r.x),h=i(e.y,(1-n)*(r.y-t.y),(1-n)*(s.y-e.y),r.y);return l=>new C(o(l),h(l))}a(cn,"cardinal");function Pr(t,e,r,s,n=xr){return cn(t,e,r,s,.5,n)}a(Pr,"catmullRom");function Qi(t,e,r,s,n=xr){return Pr(s.add(t.sub(e).scale(6)),t,s,t.add(s.sub(r).scale(6)),n)}a(Qi,"bezier");function Xi(t,e,r,s,n,i,o,h=xr){let l=h(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=h(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(Xi,"kochanekBartels");function zi(t,e,r,s){let n=2*t+e-2*s+r,i=-3*t+3*s-2*e+r,o=e;return h=>{let l=h*h;return 3*n*l+2*i*h+o}}a(zi,"hermiteFirstDerivative");function Gt(t){return 0<=t&&t<=1}a(Gt,"inZeroOneDomain");function _r(t,e){return Math.abs(t-e)<=Number.EPSILON}a(_r,"approximately");function jt(t){return t<0?-Math.pow(-t,1/3):Math.pow(t,1/3)}a(jt,"cubeRoot");function Wi(t,e,r,s){let n=3*t-6*e+3*r,i=-3*t+3*e,o=t,h=-t+3*e-3*r+s;if(_r(h,0)){if(_r(n,0))return _r(i,0)?[]:[-o/i].filter(Gt);let p=Math.sqrt(i*i-4*n*o),w=2*n;return[(p-i)/w,(-i-p)/w].filter(Gt)}n/=h,i/=h,o/=h;let l=(3*i-n*n)/3,u=l/3,f=(2*n*n*n-9*n*i+27*o)/27,x=f/2,c=x*x+u*u*u;if(c<0){let p=-l/3,w=p*p*p,R=Math.sqrt(w),P=-f/(2*R),O=P<-1?-1:P>1?1:P,F=Math.acos(O),A=2*jt(R),v=A*Math.cos(F/3)-n/3,S=A*Math.cos((F+2*Math.PI)/3)-n/3,k=A*Math.cos((F+4*Math.PI)/3)-n/3;return[v,S,k].filter(Gt)}if(c===0){let p=x<0?jt(-x):-jt(x),w=2*p-n/3,R=-p-n/3;return[w,R].filter(Gt)}let y=Math.sqrt(c),g=jt(y-x),M=jt(y+x);return[g-M-n/3].filter(Gt)}a(Wi,"getCubicRoots");function Zi(t,e,r,s,n){let i=Wi(t.x-n,e.x-n,r.x-n,s.x-n);return i.length>0?bs(t,e,r,s,i[0]).y:NaN}a(Zi,"cubicBezierYforX");function Ji(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 Ge(r,t[s-1].x,t[s].x,t[s-1].y,t[s].y);return t[t.length-1].y}}a(Ji,"easingLinear");function $i(t,e){return r=>Zi(E(0,0),t,e,E(1,1),r)}a($i,"easingCubicBezier");function _i(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 h=>{let l=Math.floor(h/r);return o+l*i}}a(_i,"easingSteps");function ea(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(dn,"isOrientedCcw");function ta(t){let e=0,r=t[t.length-1];for(let s=0;s=0}a(es,"onSameSide");function ra(t,e,r,s){return es(t,e,r,s)&&es(t,r,e,s)&&es(t,s,e,r)}a(ra,"pointInTriangle");function sa(t,e,r,s){for(let n of t)if(n!==e&&n!==r&&n!==s&&ra(n,e,r,s))return true;return false}a(sa,"someInTriangle");function na(t,e,r,s){return dn(t,e,r)&&!sa(s,t,e,r)}a(na,"isEar");function fn(t){if(t.length<3)return[];if(t.length==3)return[t];let e=[],r=[],s=0;for(let x=0;x3;){u=e[h],f=r[h];let x=t[f],c=t[h],y=t[u];if(na(x,c,y,n))i.push([x,c,y]),e[f]=u,r[u]=f,n.splice(n.indexOf(c),1),--o,l=0;else if(++l>o)return[];h=u}return u=e[h],f=r[h],i.push([t[f],t[h],t[u]]),i}a(fn,"triangulate");function ia(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 Es="topleft";var Hl="monospace";var ns="monospace";var Ns="linear";var pn=[{name:"a_pos",size:2},{name:"a_uv",size:2},{name:"a_color",size:4}];var Gl=pn.reduce((t,e)=>t+e.size,0);var oa=2048;var jl=oa*4*Gl;var Vl=oa*6;var Kl=` +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 Yl=` +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 Hs=` +vec4 vert(vec2 pos, vec2 uv, vec4 color) { + return def_vert(); +} +`;var Gs=` +vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) { + return def_frag(); +} +`;var Ql=new Set(["id","require"]);var Xl=new Set(["add","fixedUpdate","update","draw","destroy","inspect","drawInspect"]);var zl=200;var Wl=640;var Zl=65536;var la=Symbol.for("kaplay.cancel");var Zt;var ua=(Zt=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(Zt,"Registry"),Zt);var Rt;var Tt=(Rt=class{constructor(e){b(this,"paused",false);b(this,"cancel");this.cancel=e}static join(e){let r=new Rt(()=>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(Rt,"KEventController"),Rt);var Jt;var be=(Jt=class{constructor(){b(this,"cancellers",new WeakMap);b(this,"handlers",new ua)}add(e){function r(...i){if(!n.paused)return e(...i)}a(r,"handler");let s=this.handlers.pushd(r),n=new Tt(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===la&&(n=this.cancellers.get(r))&&n()})}numListeners(){return this.handlers.size}clear(){this.handlers.clear()}},a(Jt,"KEvent"),Jt);var $t;var kr=($t=class{constructor(){b(this,"handlers",{});b(this,"registers",{})}on(e,r){return this.handlers[e]||(this.handlers[e]=new be),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($t,"KEventHandler"),$t);var Jl=a(t=>t[0]instanceof X,"arrayIsColor");var $l=a(t=>t[0]instanceof C,"arrayIsVec2");var _l=a(t=>typeof t[0]=="number","arrayIsNumber");var _t;var ha=(_t=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 eu=a(t=>t.split(".").slice(0,-1).join("."),"getFileName");function Ms(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 h=t[o],l=e[o];if(!Ms(h,l))return false}return true}return false}a(Ms,"deepEq");var hi=new Set;var tu=a(t=>t instanceof Error?t.message:String(t),"getErrorMessage");function ga(t){hi.has(t)||(hi.add(t),console.warn(t))}a(ga,"warn");function Ft(t,e){ga(`${t} is deprecated. Use ${e} instead.`)}a(Ft,"deprecateMsg");function is(t,e){return Number(t.toFixed(e))}a(is,"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 ru=Object.freeze([776,2359,2367,2984,3007,3021,3633,3635,3648,3657,4352,4449,4520]);function ma(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(Mt,"betweenInclusive");var Oe=a((t,e)=>Array.isArray(t)?t==null?void 0:t.includes(e):t===e,"isEqOrIncludes");var Ye=a((t,e)=>Array.isArray(e)?e.some(r=>t.has(r)):t.has(e),"setHasOrIncludes");var Zr=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 su=(()=>{let t=0;return()=>t++})();var nu={"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 iu=a(()=>Ct.lastInputDevice,"getLastInputDeviceType");var au=a(()=>{let t=Ct.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=>{Zr(Ct.buttonsByKey,o,e)}),s&&s.forEach(o=>{Zr(Ct.buttonsByKeyCode,o,e)}),n&&n.forEach(o=>{Zr(Ct.buttonsByGamepad,o,e)}),i&&i.forEach(o=>{Zr(Ct.buttonsByMouse,o,e)})}},"parseButtonBindings");var er;var Cr=(er=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(er,"ButtonState"),er);var tr;var ou=(tr=class{constructor(){b(this,"buttonState",new Cr);b(this,"stickState",new Map)}},a(tr,"GamepadState"),tr);var rr;var lu=(rr=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(rr,"FPSCounter"),rr);var Ct;var ci=nu;var uu=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 lu,timeScale:1,skipTime:false,isHidden:false,numFrames:0,mousePos:new C(0),mouseDeltaPos:new C(0),keyState:new Cr,mouseState:new Cr,mergedGamepadState:new ou,gamepadStates:new Map,lastInputDevice:null,buttonState:new Cr,gamepads:[],charInputted:[],isMouseMoved:false,lastWidth:t.canvas.offsetWidth,lastHeight:t.canvas.offsetHeight,events:new kr}},"initAppState");var hu=a(t=>{if(!t.canvas)throw new Error("Please provide a canvas");let e=uu(t);Ct=e,au();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 h(){return e.fpsCounter.fps}a(h,"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 c(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(c,"setCursorLocked");function y(){return!!document.pointerLockElement}a(y,"isCursorLocked");function g(m){m.requestFullscreen?m.requestFullscreen():m.webkitRequestFullscreen&&m.webkitRequestFullscreen()}a(g,"enterFullscreen");function M(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullScreen&&document.webkitExitFullScreen()}a(M,"exitFullscreen");function p(m=true){m?g(e.canvas):M()}a(p,"setFullscreen");function w(){return document.fullscreenElement===e.canvas||document.webkitFullscreenElement===e.canvas}a(w,"isFullscreen");function R(){e.stopped=true;let m=Object.entries(Ce),q=Object.entries(Ds),B=Object.entries(Wr);for(let[T,G]of m)e.canvas.removeEventListener(T,G);for(let[T,G]of q)document.removeEventListener(T,G);for(let[T,G]of B)window.removeEventListener(T,G);li.disconnect()}a(R,"quit");function P(m,q){e.loopID!==null&&cancelAnimationFrame(e.loopID);let B=0,T=0,G=a(se=>{if(e.stopped)return;if(document.visibilityState!=="visible"){e.loopID=requestAnimationFrame(G);return}let ye=se/1e3,ue=Math.min(ye-e.realTime,.25),tt=t.maxFPS?1/t.maxFPS:0;if(e.realTime=ye,T+=ue,T>tt){if(!e.skipTime){for(B+=T,e.dt=e.fixedDt,e.restDt=0;B>e.fixedDt;)B-=e.fixedDt,B0}a(O,"isTouchscreen");function F(){return e.mousePos.clone()}a(F,"mousePos");function A(){return e.mouseDeltaPos.clone()}a(A,"mouseDeltaPos");function v(m="left"){return e.mouseState.pressed.has(m)}a(v,"isMousePressed");function S(m="left"){return e.mouseState.down.has(m)}a(S,"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:Ye(e.keyState.pressed,m)}a(D,"isKeyPressed");function L(m){return m===void 0?e.keyState.pressedRepeat.size>0:Ye(e.keyState.pressedRepeat,m)}a(L,"isKeyPressedRepeat");function N(m){return m===void 0?e.keyState.down.size>0:Ye(e.keyState.down,m)}a(N,"isKeyDown");function j(m){return m===void 0?e.keyState.released.size>0:Ye(e.keyState.released,m)}a(j,"isKeyReleased");function z(m){return m===void 0?e.mergedGamepadState.buttonState.pressed.size>0:Ye(e.mergedGamepadState.buttonState.pressed,m)}a(z,"isGamepadButtonPressed");function V(m){return m===void 0?e.mergedGamepadState.buttonState.down.size>0:Ye(e.mergedGamepadState.buttonState.down,m)}a(V,"isGamepadButtonDown");function Y(m){return m===void 0?e.mergedGamepadState.buttonState.released.size>0:Ye(e.mergedGamepadState.buttonState.released,m)}a(Y,"isGamepadButtonReleased");function ee(m){return m===void 0?e.buttonState.pressed.size>0:Ye(e.buttonState.pressed,m)}a(ee,"isButtonPressed");function J(m){return m===void 0?e.buttonState.down.size>0:Ye(e.buttonState.down,m)}a(J,"isButtonDown");function W(m){return m===void 0?e.buttonState.released.size>0:Ye(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 H(m,q){e.buttons[m]={...e.buttons[m],...q}}a(H,"setButton");function $e(m){e.buttonState.press(m),e.events.trigger("buttonPress",m)}a($e,"pressButton");function ut(m){e.buttonState.release(m),e.events.trigger("buttonRelease",m)}a(ut,"releaseButton");function Lt(m){return e.events.on("resize",m)}a(Lt,"onResize");let vr=ne(m=>e.events.on("keyDown",m),(m,q)=>e.events.on("keyDown",B=>Oe(m,B)&&q(B))),br=ne(m=>e.events.on("keyPress",q=>m(q)),(m,q)=>e.events.on("keyPress",B=>Oe(m,B)&&q(B))),Kr=ne(m=>e.events.on("keyPressRepeat",m),(m,q)=>e.events.on("keyPressRepeat",B=>Oe(m,B)&&q(B))),Yr=ne(m=>e.events.on("keyRelease",m),(m,q)=>e.events.on("keyRelease",B=>Oe(m,B)&&q(B))),Ut=ne(m=>e.events.on("mouseDown",q=>m(q)),(m,q)=>e.events.on("mouseDown",B=>Oe(m,B)&&q(B))),Ve=ne(m=>e.events.on("mousePress",q=>m(q)),(m,q)=>e.events.on("mousePress",B=>Oe(m,B)&&q(B))),Qr=ne(m=>e.events.on("mouseRelease",q=>m(q)),(m,q)=>e.events.on("mouseRelease",B=>B===m&&q(B)));function qt(m){return e.events.on("mouseMove",()=>m(F(),A()))}a(qt,"onMouseMove");function U(m){return e.events.on("charInput",m)}a(U,"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 de(m){return e.events.on("scroll",m)}a(de,"onScroll");function $(m){return e.events.on("hide",m)}a($,"onHide");function xe(m){return e.events.on("show",m)}a(xe,"onShow");let ht=ne(m=>e.events.on("gamepadButtonPress",(q,B)=>m(q,B)),(m,q)=>e.events.on("gamepadButtonPress",(B,T)=>Oe(m,B)&&q(B,T))),Is=ne(m=>e.events.on("gamepadButtonDown",(q,B)=>m(q,B)),(m,q)=>e.events.on("gamepadButtonDown",(B,T)=>Oe(m,B)&&q(B,T))),Ts=ne(m=>e.events.on("gamepadButtonRelease",(q,B)=>m(q,B)),(m,q)=>e.events.on("gamepadButtonRelease",(B,T)=>Oe(m,B)&&q(B,T)));function Xr(m,q){return e.events.on("gamepadStick",(B,T,G)=>B===m&&q(T,G))}a(Xr,"onGamepadStick");function zr(m){e.events.on("gamepadConnect",m)}a(zr,"onGamepadConnect");function Er(m){e.events.on("gamepadDisconnect",m)}a(Er,"onGamepadDisconnect");function Ue(m){return e.mergedGamepadState.stickState.get(m)||new C(0)}a(Ue,"getGamepadStick");function _e(){return[...e.charInputted]}a(_e,"charInputted");function Nt(){return[...e.gamepads]}a(Nt,"getGamepads");let De=ne(m=>e.events.on("buttonPress",q=>m(q)),(m,q)=>e.events.on("buttonPress",B=>Oe(m,B)&&q(B))),Sr=ne(m=>e.events.on("buttonDown",q=>m(q)),(m,q)=>e.events.on("buttonDown",B=>Oe(m,B)&&q(B))),et=ne(m=>e.events.on("buttonRelease",q=>m(q)),(m,q)=>e.events.on("buttonRelease",B=>Oe(m,B)&&q(B)));function Mr(){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)}),ni()}a(Mr,"processInput");function ri(){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(ri,"resetInput");function Fs(m){let q={index:m.index,isPressed:a(B=>{var T;return((T=e.gamepadStates.get(m.index))==null?void 0:T.buttonState.pressed.has(B))||false},"isPressed"),isDown:a(B=>{var T;return((T=e.gamepadStates.get(m.index))==null?void 0:T.buttonState.down.has(B))||false},"isDown"),isReleased:a(B=>{var T;return((T=e.gamepadStates.get(m.index))==null?void 0:T.buttonState.released.has(B))||false},"isReleased"),getStick:a(B=>{var T;return((T=e.gamepadStates.get(m.index))==null?void 0:T.stickState.get(B))||E()},"getStick")};return e.gamepads.push(q),e.gamepadStates.set(m.index,{buttonState:new Cr,stickState:new Map([["left",new C(0)],["right",new C(0)]])}),q}a(Fs,"registerGamepad");function si(m){e.gamepads=e.gamepads.filter(q=>q.index!==m.index),e.gamepadStates.delete(m.index)}a(si,"removeGamepad");function ni(){var m,q;for(let B of navigator.getGamepads())B&&!e.gamepadStates.has(B.index)&&Fs(B);for(let B of e.gamepads){let T=navigator.getGamepads()[B.index];if(!T)continue;let G=(t.gamepads??{})[T.id]||ci[T.id]||ci.default,se=e.gamepadStates.get(B.index);if(se){for(let ye=0;ye{e.buttonState.press(rt),e.events.trigger("buttonPress",rt)})),e.mergedGamepadState.buttonState.press(ue),se.buttonState.press(ue),e.events.trigger("gamepadButtonPress",ue,B)}else se.buttonState.down.has(ue)&&(Ke&&((q=e.buttonsByGamepad.get(ue))==null?void 0:q.forEach(rt=>{e.buttonState.release(rt),e.events.trigger("buttonRelease",rt)})),e.mergedGamepadState.buttonState.release(ue),se.buttonState.release(ue),e.events.trigger("gamepadButtonRelease",ue,B))}for(let ye in G.sticks){let ue=G.sticks[ye];if(!ue)continue;let tt=new C(T.axes[ue.x],T.axes[ue.y]);se.stickState.set(ye,tt),e.mergedGamepadState.stickState.set(ye,tt),e.events.trigger("gamepadStick",ye,tt,B)}}}}a(ni,"processGamepad");let Ce={},Ds={},Wr={},ii=t.pixelDensity||1;Ce.mousemove=m=>{let q=new C(m.offsetX,m.offsetY),B=new C(m.movementX,m.movementY);if(w()){let T=e.canvas.width/ii,G=e.canvas.height/ii,se=window.innerWidth,ye=window.innerHeight,ue=se/ye,tt=T/G;if(ue>tt){let Ke=ye/G,rt=(se-T*Ke)/2;q.x=Ge(m.offsetX-rt,0,T*Ke,0,T),q.y=Ge(m.offsetY,0,G*Ke,0,G)}else{let Ke=se/T,rt=(ye-G*Ke)/2;q.x=Ge(m.offsetX,0,T*Ke,0,T),q.y=Ge(m.offsetY-rt,0,G*Ke,0,G)}}e.events.onOnce("input",()=>{e.isMouseMoved=true,e.mousePos=q,e.mouseDeltaPos=B,e.events.trigger("mouseMove")})};let ai=["left","middle","right","back","forward"];Ce.mousedown=m=>{e.events.onOnce("input",()=>{var B;let q=ai[m.button];q&&(e.lastInputDevice="mouse",e.buttonsByMouse.has(q)&&((B=e.buttonsByMouse.get(q))==null?void 0:B.forEach(T=>{e.buttonState.press(T),e.events.trigger("buttonPress",T)})),e.mouseState.press(q),e.events.trigger("mousePress",q))})},Ce.mouseup=m=>{e.events.onOnce("input",()=>{var B;let q=ai[m.button];q&&(e.buttonsByMouse.has(q)&&((B=e.buttonsByMouse.get(q))==null?void 0:B.forEach(T=>{e.buttonState.release(T),e.events.trigger("buttonRelease",T)})),e.mouseState.release(q),e.events.trigger("mouseRelease",q))})};let kl=new Set([" ","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Tab"]),oi={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down"," ":"space"};Ce.keydown=m=>{kl.has(m.key)&&m.preventDefault(),e.events.onOnce("input",()=>{var T,G;let q=oi[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)&&((T=e.buttonsByKey.get(q))==null?void 0:T.forEach(se=>{e.buttonState.press(se),e.events.trigger("buttonPress",se)})),e.buttonsByKeyCode.has(B)&&((G=e.buttonsByKeyCode.get(B))==null?void 0:G.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))})},Ce.keyup=m=>{e.events.onOnce("input",()=>{var T,G;let q=oi[m.key]||m.key.toLowerCase(),B=m.code;e.buttonsByKey.has(q)&&((T=e.buttonsByKey.get(q))==null?void 0:T.forEach(se=>{e.buttonState.release(se),e.events.trigger("buttonRelease",se)})),e.buttonsByKeyCode.has(B)&&((G=e.buttonsByKeyCode.get(B))==null?void 0:G.forEach(se=>{e.buttonState.release(se),e.events.trigger("buttonRelease",se)})),e.keyState.release(q),e.events.trigger("keyRelease",q)})},Ce.touchstart=m=>{m.preventDefault(),e.events.onOnce("input",()=>{var T;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")&&((T=e.buttonsByMouse.get("left"))==null?void 0:T.forEach(G=>{e.buttonState.press(G),e.events.trigger("buttonPress",G)})),e.mouseState.press("left"),e.events.trigger("mousePress","left")),q.forEach(G=>{e.events.trigger("touchStart",new C(G.clientX-B.x,G.clientY-B.y),G)})})},Ce.touchmove=m=>{m.preventDefault(),e.events.onOnce("input",()=>{let q=[...m.changedTouches],B=e.canvas.getBoundingClientRect();if(t.touchToMouse!==false){let T=e.mousePos;e.mousePos=new C(q[0].clientX-B.x,q[0].clientY-B.y),e.mouseDeltaPos=e.mousePos.sub(T),e.events.trigger("mouseMove")}q.forEach(T=>{e.events.trigger("touchMove",new C(T.clientX-B.x,T.clientY-B.y),T)})})},Ce.touchend=m=>{e.events.onOnce("input",()=>{var T;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")&&((T=e.buttonsByMouse.get("left"))==null?void 0:T.forEach(G=>{e.buttonState.release(G),e.events.trigger("buttonRelease",G)})),e.mouseState.release("left"),e.events.trigger("mouseRelease","left")),q.forEach(G=>{e.events.trigger("touchEnd",new C(G.clientX-B.x,G.clientY-B.y),G)})})},Ce.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(T=>{e.events.trigger("touchEnd",new C(T.clientX-B.x,T.clientY-B.y),T)})})},Ce.wheel=m=>{m.preventDefault(),e.events.onOnce("input",()=>{e.events.trigger("scroll",new C(m.deltaX,m.deltaY))})},Ce.contextmenu=m=>m.preventDefault(),Ds.visibilitychange=()=>{document.visibilityState==="visible"?(e.skipTime=true,e.isHidden=false,e.events.trigger("show")):(e.isHidden=true,e.events.trigger("hide"))},Wr.gamepadconnected=m=>{let q=Fs(m.gamepad);e.events.onOnce("input",()=>{e.events.trigger("gamepadConnect",q)})},Wr.gamepaddisconnected=m=>{let q=Nt().filter(B=>B.index===m.gamepad.index)[0];si(m.gamepad),e.events.onOnce("input",()=>{e.events.trigger("gamepadDisconnect",q)})};for(let[m,q]of Object.entries(Ce))e.canvas.addEventListener(m,q);for(let[m,q]of Object.entries(Ds))document.addEventListener(m,q);for(let[m,q]of Object.entries(Wr))window.addEventListener(m,q);let li=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 li.observe(e.canvas),{state:e,dt:r,fixedDt:s,restDt:n,time:o,run:P,canvas:e.canvas,fps:h,numFrames:l,quit:R,isHidden:i,setFullscreen:p,isFullscreen:w,setCursor:f,screenshot:u,getGamepads:Nt,getCursor:x,setCursorLocked:c,isCursorLocked:y,isTouchscreen:O,mousePos:F,mouseDeltaPos:A,isKeyDown:N,isKeyPressed:D,isKeyPressedRepeat:L,isKeyReleased:j,isMouseDown:S,isMousePressed:v,isMouseReleased:k,isMouseMoved:I,isGamepadButtonPressed:z,isGamepadButtonDown:V,isGamepadButtonReleased:Y,getGamepadStick:Ue,isButtonPressed:ee,isButtonDown:J,isButtonReleased:W,setButton:H,getButton:le,pressButton:$e,releaseButton:ut,charInputted:_e,onResize:Lt,onKeyDown:vr,onKeyPress:br,onKeyPressRepeat:Kr,onKeyRelease:Yr,onMouseDown:Ut,onMousePress:Ve,onMouseRelease:Qr,onMouseMove:qt,onCharInput:U,onTouchStart:K,onTouchMove:Q,onTouchEnd:re,onScroll:de,onHide:$,onShow:xe,onGamepadButtonDown:Is,onGamepadButtonPress:ht,onGamepadButtonRelease:Ts,onGamepadStick:Xr,onGamepadConnect:zr,onGamepadDisconnect:Er,onButtonPress:De,onButtonDown:Sr,onButtonRelease:et,getLastInputDeviceType:iu,events:e.events}},"initApp");function ge(){return d.app.dt()}a(ge,"dt");function as(){return d.app.fixedDt()}a(as,"fixedDt");function os(){return d.app.restDt()}a(os,"restDt");var cu=new C(-1,-1);var du=new C(0,-1);var fu=new C(1,-1);var pu=new C(-1,0);var gu=new C(0,0);var mu=new C(1,0);var wu=new C(-1,1);var yu=new C(0,1);var Au=new C(1,1);function Dt(t){switch(t){case"topleft":return cu;case"top":return du;case"topright":return fu;case"left":return pu;case"center":return gu;case"right":return mu;case"botleft":return wu;case"bot":return yu;case"botright":return Au;default:return t}}a(Dt,"anchorPt");function qa(t){switch(t){case"left":return 0;case"center":return .5;case"right":return 1;default:return 0}}a(qa,"alignPt");function Ca(t){return t.createBuffer(1,1,44100)}a(Ca,"createEmptyAudioBuffer");var Jr=2.5949095;var di=1.70158+1;var fi=2*Math.PI/3;var pi=2*Math.PI/4.5;var ts={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=>di*t*t*t-1.70158*t*t,"easeInBack"),easeOutBack:a(t=>1+di*Math.pow(t-1,3)+1.70158*Math.pow(t-1,2),"easeOutBack"),easeInOutBack:a(t=>t<.5?Math.pow(2*t,2)*((Jr+1)*2*t-Jr)/2:(Math.pow(2*t-2,2)*((Jr+1)*(t*2-2)+Jr)+2)/2,"easeInOutBack"),easeInElastic:a(t=>t===0?0:t===1?1:-Math.pow(2,10*t-10)*Math.sin((t*10-10.75)*fi),"easeInElastic"),easeOutElastic:a(t=>t===0?0:t===1?1:Math.pow(2,-10*t)*Math.sin((t*10-.75)*fi)+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)*pi))/2:Math.pow(2,-20*t+10)*Math.sin((20*t-11.125)*pi)/2+1,"easeInOutElastic"),easeInBounce:a(t=>1-ts.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-ts.easeOutBounce(1-2*t))/2:(1+ts.easeOutBounce(2*t-1))/2,"easeInOutBounce")};var Ir=ts;function Ba(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(Ba,"buildPath");function Ra(t,e,r){var o;let s=new ha((h,l)=>h.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(nr,"NavPolygon"),nr);var ir;var bu=(ir=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 vu(this._polygons.length),s=e.map((n,i)=>new xu(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]:Ra(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 h=this.getPath(i.id,o.id);if(!h)return[];if(n==="edges"){let l=[];for(let u=1;uthis._polygons[l].centroid),r]}},a(ir,"NavMesh"),ir);function Yt(t){let e=new Ze;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(Yt,"calcTransform");function Pa(t){return new C(t.x/we()*2-1,-t.y/Ae()*2+1)}a(Pa,"screen2ndc");function Vt(t,e,r,s,n,i=1){s=ce(s%360),n=ce(n%360),n<=s&&(n+=Math.PI*2);let o=[],h=Math.ceil((n-s)/ce(8)*i),l=(n-s)/h,u=E(Math.cos(s),Math.sin(s)),f=E(Math.cos(l),Math.sin(l));for(let x=0;x<=h;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(Vt,"getArcPts");function ka(...t){let e=_(...t),r=t[3]??1;d.gfx.bgColor=e,d.gfx.bgAlpha=r,d.gfx.ggl.gl.clearColor(e.r/255,e.g/255,e.b/255,r)}a(ka,"setBackground");function Ia(){var t,e;return((e=(t=d.gfx.bgColor)==null?void 0:t.clone)==null?void 0:e.call(t))??null}a(Ia,"getBackground");function ae(...t){if(t[0]===void 0)return;let e=E(...t);e.x===0&&e.y===0||d.gfx.transform.translate(e)}a(ae,"pushTranslate");function Be(){d.gfx.transformStack.push(d.gfx.transform.clone())}a(Be,"pushTransform");function Ta(t){d.gfx.transform=t.clone()}a(Ta,"pushMatrix");function wr(...t){if(t[0]===void 0)return;let e=E(...t);e.x===1&&e.y===1||d.gfx.transform.scale(e)}a(wr,"pushScale");function It(t){t&&d.gfx.transform.rotate(t)}a(It,"pushRotate");function Ee(){d.gfx.transformStack.length>0&&(d.gfx.transform=d.gfx.transformStack.pop())}a(Ee,"popTransform");function Re(){d.gfx.renderer.flush()}a(Re,"flush");function we(){return d.gfx.width}a(we,"width");function Ae(){return d.gfx.height}a(Ae,"height");function mn(){return(d.gfx.viewport.width+d.gfx.viewport.height)/(d.gfx.width+d.gfx.height)}a(mn,"getViewportScale");function Fa(t){return new C(t.x*d.gfx.viewport.width/d.gfx.width,t.y*d.gfx.viewport.height/d.gfx.height)}a(Fa,"contentToView");function Da(t){return new C((t.x-d.gfx.viewport.x)*we()/d.gfx.viewport.width,(t.y-d.gfx.viewport.y)*Ae()/d.gfx.viewport.height)}a(Da,"windowToContent");function wn(){return Da(d.app.mousePos())}a(wn,"mousePos");function Tr(){return E(we()/2,Ae()/2)}a(Tr,"center");var ar;var Eu=(ar=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=[dt.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=dt.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(dt.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(ar,"TexPacker"),ar);function Te(t){return typeof t!="string"||pa(t)?t:d.assets.urlPrefix+t}a(Te,"fixURL");var Pt;var Le=(Pt=class{constructor(e){b(this,"loaded",false);b(this,"data",null);b(this,"error",null);b(this,"onLoadEvents",new be);b(this,"onErrorEvents",new be);b(this,"onFinishEvents",new be);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 Pt(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(Pt,"Asset"),Pt);var or;var Ht=(or=class{constructor(){b(this,"assets",new Map);b(this,"lastUID",0)}add(e,r){let s=e??this.lastUID+++"",n=new Le(r);return this.assets.set(s,n),n}addLoaded(e,r){let s=e??this.lastUID+++"",n=Le.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(or,"AssetBucket"),or);function Cs(t){return fetch(t).then(e=>{if(!e.ok)throw new Error(`Failed to fetch "${t}"`);return e})}a(Cs,"fetchURL");function Gr(t){return Cs(t).then(e=>e.json())}a(Gr,"fetchJSON");function Oa(t){return Cs(t).then(e=>e.text())}a(Oa,"fetchText");function La(t){return Cs(t).then(e=>e.arrayBuffer())}a(La,"fetchArrayBuffer");function Ua(t){return t!==void 0&&(d.assets.urlPrefix=t),d.assets.urlPrefix}a(Ua,"loadRoot");function Na(t,e){return d.assets.custom.add(t,Gr(Te(e)))}a(Na,"loadJSON");function jr(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(jr,"loadImg");function At(){let t=[d.assets.sprites,d.assets.sounds,d.assets.shaders,d.assets.fonts,d.assets.bitmapFonts,d.assets.custom];return t.reduce((e,r)=>e+r.progress(),0)/t.length}a(At,"loadProgress");function yn(){return[d.assets.sprites,d.assets.sounds,d.assets.shaders,d.assets.fonts,d.assets.bitmapFonts,d.assets.custom].reduce((t,e)=>t.concat(e.getFailedAssets()),[])}a(yn,"getFailedAssets");function Ha(t){return d.assets.custom.get(t)??null}a(Ha,"getAsset");function ls(t){return d.assets.custom.add(null,t)}a(ls,"load");var Su=a((t,e)=>({urlPrefix:"",sprites:new Ht,fonts:new Ht,bitmapFonts:new Ht,sounds:new Ht,shaders:new Ht,custom:new Ht,music:{},packer:new Eu(t,2048,2048,e),loaded:false}),"initAssets");var Mu="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 We;var xt=(We=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"?We.fromURL(e,r):Promise.resolve(We.fromImage(e,r))}static fromImage(e,r={}){let[s,n]=d.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)):xn(r.sliceX||1,r.sliceY||1,n.x,n.y,n.w,n.h);return new We(s,i,r.anims,r.slice9)}static fromURL(e,r={}){return jr(e).then(s=>We.fromImage(s,r))}},a(We,"SpriteData"),We);function Br(t){if(typeof t=="string"){let e=An(t);if(e)return e;if(At()<1)return null;throw new Error(`Sprite not found: ${t}`)}else{if(t instanceof xt)return Le.loaded(t);if(t instanceof Le)return t;throw new Error(`Invalid sprite: ${t}`)}}a(Br,"resolveSprite");function An(t){return d.assets.sprites.get(t)??null}a(An,"getSprite");function Qt(t,e,r={sliceX:1,sliceY:1,anims:{}}){return e=Te(e),Array.isArray(e)?e.some(s=>typeof s=="string")?d.assets.sprites.add(t,Promise.all(e.map(s=>typeof s=="string"?jr(s):Promise.resolve(s))).then(s=>Ks(s,r))):d.assets.sprites.addLoaded(t,Ks(e,r)):typeof e=="string"?d.assets.sprites.add(t,xt.from(e,r)):d.assets.sprites.addLoaded(t,xt.fromImage(e,r))}a(Qt,"loadSprite");function xn(t=1,e=1,r=0,s=0,n=1,i=1){let o=[],h=n/t,l=i/e;for(let u=0;u{h instanceof ImageData?i.putImageData(h,l*s,0):i.drawImage(h,l*s,0)});let o=i.getImageData(0,0,t.length*s,n);return xt.fromImage(o,{...e,sliceX:t.length,sliceY:1})}a(Ks,"createSpriteSheet");function Ga(t="bean"){return Qt(t,Mu)}a(Ga,"loadBean");function ja(t,e,r){e=Te(e),r=Te(r),typeof e=="string"&&!r&&(r=eu(e)+".json");let s=typeof r=="string"?Gr(r):Promise.resolve(r);return d.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)),h={};for(let l of n.meta.frameTags)l.from===l.to?h[l.name]=l.from:h[l.name]={from:l.from,to:l.to,speed:10,loop:true,pingpong:l.direction==="pingpong"};return xt.from(e,{frames:o,anims:h})}))}a(ja,"loadAseprite");var lr;var rs=(lr=class{constructor(e,r={}){b(this,"fontface");b(this,"filter",Ns);b(this,"outline",null);b(this,"size",64);if(this.fontface=e,this.filter=r.filter??Ns,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(lr,"FontData"),lr);function vn(t){if(!t)return vn(d.globalOpt.font??Hl);if(typeof t=="string"){let e=En(t),r=bn(t);if(e)return e.data??e;if(r)return r.data??r;if(document.fonts.check(`${64}px ${t}`))return t;if(At()<1)return null;throw new Error(`Font not found: ${t}`)}else if(t instanceof Le)return t.data?t.data:t;return t}a(vn,"resolveFont");function bn(t){return d.assets.fonts.get(t)??null}a(bn,"getFont");function Va(t,e,r={}){let s=Te(e),n=new FontFace(t,typeof e=="string"?`url(${s})`:s);return document.fonts.add(n),d.assets.fonts.add(t,n.load().catch(i=>{throw new Error(`Failed to load font from "${s}": ${i}`)}).then(i=>new rs(i,r)))}a(Va,"loadFont");function Ka(t,e,r,s){let n=t.width/e,i={},o=s.split("").entries();for(let[h,l]of o)i[l]=new oe(h%n*e,Math.floor(h/n)*r,e,r);return{tex:t,map:i,size:r}}a(Ka,"makeFont");function En(t){return d.assets.bitmapFonts.get(t)??null}a(En,"getBitmapFont");function Ya(t,e,r,s,n={}){let i=Te(e);return d.assets.bitmapFonts.add(t,jr(i).then(o=>Ka(dt.fromImage(d.gfx.ggl,o,n),r,s,n.chars??aa)))}a(Ya,"loadBitmapFont");function Qa(t,e){return e=Te(e),d.assets.sprites.add(t,new Promise(async r=>{let s=typeof e=="string"?await Gr(e):e,n=await Promise.all(s.frames.map(jr)),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 h=await Qt(null,i,{sliceY:s.frames.length,anims:s.anims});r(h)}))}a(Qa,"loadPedit");var ur;var qu=(ur=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),h=i.createShader(i.FRAGMENT_SHADER);if(!o||!h)throw new Error("Failed to create shader");i.shaderSource(o,r),i.shaderSource(h,s),i.compileShader(o),i.compileShader(h);let l=i.createProgram();if(this.glProgram=l,i.attachShader(l,o),i.attachShader(l,h),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(h);if(f)throw new Error("FRAGMENT SHADER "+f)}i.deleteShader(o),i.deleteShader(h)}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 Ze)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];_l(n)?r.uniform1fv(i,n):$l(n)?r.uniform2fv(i,n.map(o=>[o.x,o.y]).flat()):Jl(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(ur,"Shader"),ur);function Bs(t,e=Hs,r=Gs){let s=Kl.replace("{{user}}",e??Hs),n=Yl.replace("{{user}}",r??Gs);try{return new qu(t,s,n,pn.map(i=>i.name))}catch(i){let o=/(?^\w+) SHADER ERROR: 0:(?\d+): (?.+)/,h=tu(i).match(o);if(!(h==null?void 0:h.groups))throw i;let l=Number(h.groups.line)-14,u=h.groups.msg.trim(),f=h.groups.type.toLowerCase();throw new Error(`${f} shader line ${l}: ${u}`)}}a(Bs,"makeShader");function Xa(t){if(!t)return d.gfx.defShader;if(typeof t=="string"){let e=Sn(t);if(e)return e.data??e;if(At()<1)return null;throw new Error(`Shader not found: ${t}`)}else if(t instanceof Le)return t.data?t.data:t;return t}a(Xa,"resolveShader");function Sn(t){return d.assets.shaders.get(t)??null}a(Sn,"getShader");function za(t,e,r){return d.assets.shaders.addLoaded(t,Bs(d.gfx.ggl,e,r))}a(za,"loadShader");function Wa(t,e,r){e=Te(e),r=Te(r);let s=a(i=>i?Oa(i):Promise.resolve(null),"resolveUrl"),n=Promise.all([s(e),s(r)]).then(([i,o])=>Bs(d.gfx.ggl,i,o));return d.assets.shaders.add(t,n)}a(Wa,"loadShaderURL");var nt;var Fr=(nt=class{constructor(e){b(this,"buf");this.buf=e}static fromArrayBuffer(e){return new Promise((r,s)=>d.audio.ctx.decodeAudioData(e,r,s)).then(r=>new nt(r))}static fromURL(e){return pa(e)?nt.fromArrayBuffer(da(e)):La(e).then(r=>nt.fromArrayBuffer(r))}},a(nt,"SoundData"),nt);function Za(t){if(typeof t=="string"){let e=Mn(t);if(e)return e;if(At()<1)return null;throw new Error(`Sound not found: ${t}`)}else{if(t instanceof Fr)return Le.loaded(t);if(t instanceof Le)return t;throw new Error(`Invalid sound: ${t}`)}}a(Za,"resolveSound");function Mn(t){return d.assets.sounds.get(t)??null}a(Mn,"getSound");function Ja(t,e){return e=Te(e),d.assets.sounds.add(t,typeof e=="string"?Fr.fromURL(e):Fr.fromArrayBuffer(e))}a(Ja,"loadSound");function $a(t,e){let r=Te(e),s=new Audio(r);return s.preload="auto",d.assets.music[t]=r}a($a,"loadMusic");function qn(t,e){return t=Te(t),typeof e=="string"?ls(new Promise((r,s)=>{Gr(e).then(n=>{qn(t,n).then(r).catch(s)})})):ls(xt.from(t).then(r=>{let s={};for(let n in e){let i=e[n],o=r.frames[0],h=2048*o.w,l=2048*o.h,u=i.frames?i.frames.map(x=>new oe(o.x+(i.x+x.x)/h*o.w,o.y+(i.y+x.y)/l*o.h,x.w/h*o.w,x.h/l*o.h)):xn(i.sliceX||1,i.sliceY||1,o.x+i.x/h*o.w,o.y+i.y/l*o.h,i.width/h*o.w,i.height/l*o.h),f=new xt(r.tex,u,i.anims);d.assets.sprites.addLoaded(n,f),s[n]=f}return s}))}a(qn,"loadSpriteAtlas");function lt(t,e,r=false,s,n,i={}){let o=s??d.gfx.defTex,h=n??d.gfx.defShader,l=Xa(h);if(!l||l instanceof Le)return;let u=d.gfx.fixed||r?d.gfx.transform:d.game.cam.transform.mult(d.gfx.transform),f=[];for(let x of t){let c=Pa(u.multVec2(x.pos));f.push(c.x,c.y,x.uv.x,x.uv.y,x.color.r/255,x.color.g/255,x.color.b/255,x.opacity)}d.gfx.renderer.push(d.gfx.ggl.gl.TRIANGLES,f,e,l,o,i)}a(lt,"drawRaw");function it(t){if(!t.pts)throw new Error('drawPolygon() requires property "pts".');let e=t.pts.length;if(!(e<3)){if(Be(),ae(t.pos),wr(t.scale),It(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=fn(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(),lt(s,t.indices??n,t.fixed,t.uv?t.tex:d.gfx.defTex,t.shader,t.uniform??void 0)}t.outline&&Rs({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}),Ee()}}a(it,"drawPolygon");function Cn(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=Dt(t.anchor??"center").scale(new C(-t.radiusX,-t.radiusY)),n=Vt(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&&it(Object.assign({},i,{outline:null})),it(Object.assign({},i,{pts:n.slice(1),fill:false}));return}it(i)}a(Cn,"drawEllipse");function Ot(t){if(typeof t.radius!="number")throw new Error('drawCircle() requires property "radius".');t.radius!==0&&Cn(Object.assign({},t,{radiusX:t.radius,radiusY:t.radius,angle:0}))}a(Ot,"drawCircle");function Kt(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}));lt(i,[0,1,3,1,2,3],t.fixed,d.gfx.defTex,t.shader,t.uniform??void 0)}a(Kt,"drawLine");function _a(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 h=o.len(),l=o.normal().scale(-s/h),u,f=e[0];if(!n)switch(t.cap){case"square":{let g=o.scale(-s/h);r.push(f.add(g).add(l)),r.push(f.add(g).sub(l));break}case"round":{let g=Math.max(s,10),M=Math.PI/g,p=l.scale(-1),w=Math.cos(M),R=Math.sin(M);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=M,h=p,l=w}if(!n)switch(r.push(f.add(l)),r.push(f.sub(l)),t.cap){case"square":{let g=o.scale(s/h);r.push(f.add(g).add(l)),r.push(f.add(g).sub(l));break}case"round":{let g=Math.max(s,10),M=Math.PI/g,p=l.scale(1),w=Math.cos(M),R=Math.sin(M);for(let P=0;P({pos:i.add(g),uv:E(),color:t.color||X.WHITE,opacity:t.opacity??1})),c=[],y=0;for(let g=0;g0){let F=u.add(O),A=Math.max(s,10),v=ce(l.angleBetween(w)/A),S=l,k=Math.cos(v),I=Math.sin(v);for(let D=0;D({pos:i.add(g),uv:E(),color:t.color||X.WHITE,opacity:t.opacity??1})),c=[],y=0;for(let g=0;g({pos:i.add(g),uv:E(),color:t.color||X.WHITE,opacity:t.opacity??1})),c=[],y=0;for(let g=0;g2)switch(t.join){case"bevel":return _a(t);case"round":return eo(t);case"miter":return to(t)}if(t.radius&&e.length>=3){Kt(Object.assign({},t,{p1:e[0],p2:e[1]}));for(let s=1;sbs(t.pt1,t.pt2,t.pt3,t.pt4,e),t)}a(ro,"drawBezier");var kt;var dt=(kt=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 h={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,h),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,h),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 kt(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(kt,"Texture"),kt);var hr;var us=(hr=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 dt(e,r,s,n);let o=i.createFramebuffer(),h=i.createRenderbuffer();if(!o||!h)throw new Error("Failed to create framebuffer");this.glFramebuffer=o,this.glRenderbuffer=h,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,h=(this.height-i-1)*s;n.set(r.subarray(o,o+s)),r.copyWithin(o,h,h+s),r.set(n,h)}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(hr,"FrameBuffer"),hr);var cr;var Cu=(cr=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((h,l)=>h+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||!Ms(this.curUniform,o)||this.vqueue.length+r.length*this.stride>this.maxVertices||this.iqueue.length+s.length>this.maxIndices)&&this.flush();let h=this.vqueue.length/this.stride;for(let l of r)this.vqueue.push(l);for(let l of s)this.iqueue.push(l+h);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(cr,"BatchRenderer"),cr);function ct(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(ct,"genStack");function so(t,e={}){let r=[];function s(F){r.push(F)}a(s,"onDestroy");function n(){r.forEach(A=>A());let F=t.getExtension("WEBGL_lose_context");F&&F.loseContext()}a(n,"destroy");let i=null;function o(F){if(Ms(F,i))return;i=F;let A=F.reduce((v,S)=>v+S.size,0);F.reduce((v,S,k)=>(t.vertexAttribPointer(k,S.size,t.FLOAT,false,A*4,v),t.enableVertexAttribArray(k),v+S.size*4),0)}a(o,"setVertexFormat");let[h,l]=ct(F=>t.bindTexture(t.TEXTURE_2D,F)),[u,f]=ct(F=>t.bindBuffer(t.ARRAY_BUFFER,F)),[x,c]=ct(F=>t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,F)),[y,g]=ct(F=>t.bindFramebuffer(t.FRAMEBUFFER,F)),[M,p]=ct(F=>t.bindRenderbuffer(t.RENDERBUFFER,F)),[w,R]=ct(F=>{if(!F)return;let{x:A,y:v,w:S,h:k}=F;t.viewport(A,v,S,k)}),[P,O]=ct(F=>t.useProgram(F));return w({x:0,y:0,w:t.drawingBufferWidth,h:t.drawingBufferHeight}),{gl:t,opts:e,onDestroy:s,destroy:n,pushTexture2D:h,popTexture2D:l,pushArrayBuffer:u,popArrayBuffer:f,pushElementArrayBuffer:x,popElementArrayBuffer:c,pushFramebuffer:y,popFramebuffer:g,pushRenderbuffer:M,popRenderbuffer:p,pushViewport:w,popViewport:R,pushProgram:P,popProgram:O,setVertexFormat:o}}a(so,"initGfx");var Os={};function Ys(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(Ys,"applyCharTransform");function hs(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[h,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(h.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(hs,"compileStyledText");function vt(t){var P,O,F;if(t.text===void 0)throw new Error('formatText() requires property "text".');let e=vn(t.font);if(!t.text||t.text===""||e instanceof Le||!e)return{width:0,height:0,chars:[],opt:t,renderedText:""};let{charStyleMap:r,text:s}=hs(t.text+""),n=ma(s);if(e instanceof rs||typeof e=="string"){let A=e instanceof rs?e.fontface.family:e,v=e instanceof rs?{outline:e.outline,filter:e.filter}:{outline:null,filter:Ns},S=Os[A]??{font:{tex:new dt(d.gfx.ggl,2048,2048,{filter:v.filter}),map:{},size:64},cursor:new C(0),maxHeight:0,outline:v.outline};Os[A]||(Os[A]=S),e=S.font;for(let k of n)if(!S.font.map[k]){let I=d.fontCacheC2d;if(!I)throw new Error("fontCacheC2d is not defined.");if(!d.fontCacheCanvas)throw new Error("fontCacheCanvas is not defined.");I.clearRect(0,0,d.fontCacheCanvas.width,d.fontCacheCanvas.height),I.font=`${e.size}px ${A}`,I.textBaseline="top",I.textAlign="left",I.fillStyle="#ffffff";let D=I.measureText(k),L=Math.ceil(D.width);if(!L)continue;let N=Math.ceil(Math.abs(D.actualBoundingBoxAscent))+Math.ceil(Math.abs(D.actualBoundingBoxDescent));S.outline&&S.outline.width&&S.outline.color&&(I.lineJoin="round",I.lineWidth=S.outline.width*2,I.strokeStyle=S.outline.color.toHex(),I.strokeText(k,S.outline.width,S.outline.width),L+=S.outline.width*2,N+=S.outline.width*3),I.fillText(k,((P=S.outline)==null?void 0:P.width)??0,((O=S.outline)==null?void 0:O.width)??0);let j=I.getImageData(0,0,L,N);if(S.cursor.x+L>2048&&(S.cursor.x=0,S.cursor.y+=S.maxHeight,S.maxHeight=0,S.cursor.y>2048))throw new Error("Font atlas exceeds character limit");e.tex.update(j,S.cursor.x,S.cursor.y),e.map[k]=new oe(S.cursor.x,S.cursor.y,L,N),S.cursor.x+=L+1,S.maxHeight=Math.max(S.maxHeight,N)}}let i=t.size||e.size,o=E(t.scale??1).scale(i/e.size),h=t.lineSpacing??0,l=t.letterSpacing??0,u=0,f=0,x=0,c=[],y=[],g=0,M=null,p=0,w;for(;gt.width&&(x+=i+h,M!=null&&(g-=y.length-M,A=n[g],v=e.map[A],S=v.w*o.x,y=y.slice(0,M-1),u=p),M=null,p=0,c.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===" "&&(M=y.length,p=u),t.indentAll&&w===void 0&&/\S/.test(A)&&(w=u),u+=S,f=Math.max(f,u),u+=l}}g++}c.push({width:u-l,chars:y}),x+=i,t.width&&(f=t.width);let R=[];for(let A=0;A{yr({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})}),Ee()}a(bt,"drawFormattedText");function Pe(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=Dt(t.anchor||Es).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(h=>Math.min(i,h)):new Array(4).fill(Math.min(i,t.radius));n=[new C(o[0],0),...o[1]?Vt(new C(e-o[1],o[1]),o[1],o[1],270,360):[E(e,0)],...o[2]?Vt(new C(e-o[2],r-o[2]),o[2],o[2],0,90):[E(e,r)],...o[3]?Vt(new C(o[3],r-o[3]),o[3],o[3],90,180):[E(0,r)],...o[0]?Vt(new C(o[0],o[0]),o[0],o[0],180,270):[]]}it(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(Pe,"drawRect");function st(t){Re();let e=d.gfx.width,r=d.gfx.height;d.gfx.width=d.gfx.viewport.width,d.gfx.height=d.gfx.viewport.height,t(),Re(),d.gfx.width=e,d.gfx.height=r}a(st,"drawUnscaled");function Qs(t,e){st(()=>{let r=E(8);Be(),ae(t);let s=vt({text:e,font:ns,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>=we()&&ae(E(-n,0)),t.y+i>=Ae()&&ae(E(0,-i)),Pe({width:n,height:i,color:_(0,0,0),radius:4,opacity:.8,fixed:true}),bt(s),Ee()})}a(Qs,"drawInspectText");function Rn(t){if(!t.p1||!t.p2||!t.p3)throw new Error('drawTriangle() requires properties "p1", "p2" and "p3".');return it(Object.assign({},t,{pts:[t.p1,t.p2,t.p3]}))}a(Rn,"drawTriangle");function no(){if(d.debug.inspect){let t=null;for(let e of d.game.root.get("*",{recursive:true}))if(e.c("area")&&e.isHovering()){t=e;break}if(d.game.root.drawInspect(),t){let e=[],r=t.inspect();for(let s in r)r[s]?e.push(`${r[s]}`):e.push(`${s}`);Qs(Fa(wn()),e.join(` +`))}Qs(E(8),`FPS: ${d.debug.fps()}`)}d.debug.paused&&st(()=>{Be(),ae(we(),0),ae(-8,8);let t=32;Pe({width:t,height:t,anchor:"topright",color:_(0,0,0),opacity:.8,radius:4,fixed:true});for(let e=1;e<=2;e++)Pe({width:4,height:t*.6,anchor:"center",pos:E(-t/3*e,t*.5),color:_(255,255,255),radius:2,fixed:true});Ee()}),d.debug.timeScale!==1&&st(()=>{Be(),ae(we(),Ae()),ae(-8,-8);let t=8,e=vt({text:d.debug.timeScale.toFixed(1),font:ns,size:16,color:_(255,255,255),pos:E(-t),anchor:"botright",fixed:true});Pe({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=d.debug.timeScale<1;Rn({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})}bt(e),Ee()}),d.debug.curRecording&&st(()=>{Be(),ae(0,Ae()),ae(24,-24),Ot({radius:12,color:_(255,0,0),opacity:$s(0,1,d.app.time()*4),fixed:true}),Ee()}),d.debug.showLog&&d.game.logs.length>0&&st(()=>{Be(),ae(0,Ae()),ae(8,-8);let t=8,e=[];for(let s of d.game.logs){let n="",i=s.msg instanceof Error?"error":"info";n+=`[time]${s.time.toFixed(2)}[/time]`,n+=" ",n+=`[${i}]${cs(s.msg)}[/${i}]`,e.push(n)}d.game.logs=d.game.logs.filter(s=>d.app.time()-s.time<(d.globalOpt.logTime||4));let r=vt({text:e.join(` +`),font:ns,pos:E(t,-t),anchor:"botleft",size:16,width:we()*.6,lineSpacing:t/2,fixed:true,styles:{time:{color:_(127,127,127)},info:{color:_(255,255,255)},error:{color:_(255,0,127)}}});Pe({width:r.width+t*2,height:r.height+t*2,anchor:"botleft",color:_(0,0,0),radius:4,opacity:.8,fixed:true}),bt(r),Ee()})}a(no,"drawDebug");function cs(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=>cs(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)}: ${cs(t[i],true,r.union(new Set([t])))}`).join(", "))?` ${n} `:"","}"].join(""),t=s),String(t).replaceAll(new RegExp("(?0?d.game.events.trigger("loading",t):st(()=>{let e=we()/2,r=24,s=E(we()/2,Ae()/2).sub(E(e/2,r/2));Pe({pos:E(0),width:we(),height:Ae(),color:_(0,0,0)}),Pe({pos:s,width:e,height:r,fill:false,outline:{width:4}}),Pe({pos:s,width:e*t,height:r})})}a(ao,"drawLoadScreen");function Pn(t,e,r){let s=d.gfx.ggl.gl;Re(),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(),Re(),s.stencilFunc(r,1,255),s.stencilOp(s.KEEP,s.KEEP,s.KEEP),t(),Re(),s.disable(s.STENCIL_TEST)}a(Pn,"drawStenciled");function oo(t,e){let r=d.gfx.ggl.gl;Pn(t,e,r.EQUAL)}a(oo,"drawMasked");function Dr(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 h=Dt(t.anchor||Es);(((i=t.pos)==null?void 0:i.x)||0)-(h.x+1)*.5*(t.width||r);(((o=t.pos)==null?void 0:o.y)||0)-(h.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),c=l-f,y=u-x,g=(f+c?1:0)*(x+y?1:0),M=new Array(g*6),p=new Array(g*4),w=0,R=a((P,O,F,A,v)=>{M[w*6+0]=w*4+0,M[w*6+1]=w*4+1,M[w*6+2]=w*4+3,M[w*6+3]=w*4+1,M[w*6+4]=w*4+2,M[w*6+5]=w*4+3,p[w*4+0]={pos:new C(P-h.x,O-h.y),uv:new C(v.x,v.y),color:t.color||X.WHITE,opacity:t.opacity||1},p[w*4+1]={pos:new C(P+F-h.x,O-h.y),uv:new C(v.x+v.w,v.y),color:t.color||X.WHITE,opacity:t.opacity||1},p[w*4+2]={pos:new C(P+F-h.x,O+A-h.y),uv:new C(v.x+v.w,v.y+v.h),color:t.color||X.WHITE,opacity:t.opacity||1},p[w*4+3]={pos:new C(P-h.x,O+A-h.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=Bs(e,Hs,Gs),s=t.pixelDensity??1,n=t.scale??1,{gl:i}=e,o=dt.fromImage(e,new ImageData(new Uint8ClampedArray([255,255,255,255]),1,1)),h=t.width&&t.height?new us(e,t.width*s*n,t.height*s*n):new us(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 Cu(e,pn,jl,Vl),x=dt.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:h,postShader:null,postShaderUniform:null,renderer:f,transform:new Ze,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 kn(){let t=d.pixelDensity,e=d.gfx.ggl.gl.drawingBufferWidth/t,r=d.gfx.ggl.gl.drawingBufferHeight/t;if(d.globalOpt.letterbox){if(!d.globalOpt.width||!d.globalOpt.height)throw new Error("Letterboxing requires width and height defined.");let s=e/r,n=d.globalOpt.width/d.globalOpt.height;if(s>n){let i=r*n,o=(e-i)/2;d.gfx.viewport={x:o,y:0,width:i,height:r}}else{let i=e/n,o=(r-i)/2;d.gfx.viewport={x:0,y:o,width:e,height:i}}return}if(d.globalOpt.stretch&&(!d.globalOpt.width||!d.globalOpt.height))throw new Error("Stretching requires width and height defined.");d.gfx.viewport={x:0,y:0,width:e,height:r}}a(kn,"updateViewport");function ft(t){return t.fixed?true:t.parent?ft(t.parent):false}a(ft,"isFixed");function Et(t){return{color:t.color,opacity:t.opacity,anchor:t.anchor,outline:t.outline,shader:t.shader,uniform:t.uniform}}a(Et,"getRenderProps");function ho(t,e={}){return{id:"circle",radius:t,draw(){Ot(Object.assign(Et(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(ho,"circle");function In(...t){return{id:"color",color:_(...t),inspect(){return`color: ${this.color.toString()}`}}}a(In,"color");function co(t){return{add(){this.canvas=t}}}a(co,"drawon");function fo(t=1){let e,r=0,s=false;return{require:["opacity"],add(){e=this.opacity,this.opacity=0},update(){s||(r+=ge(),this.opacity=Ge(r,0,t,0,e),r>=t&&(this.opacity=e,s=true))}}}a(fo,"fadeIn");function po(t="intersect"){return{id:"mask",mask:t}}a(po,"mask");function Tn(t){return{id:"opacity",opacity:t??1,fadeIn(e=1,r=d.k.easings.linear){return d.game.root.tween(0,this.opacity,e,s=>this.opacity=s,r)},fadeOut(e=1,r=d.k.easings.linear){return d.game.root.tween(this.opacity,0,e,s=>this.opacity=s,r)},inspect(){return`opacity: ${is(this.opacity,1)}`}}}a(Tn,"opacity");function mo(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(mo,"outline");var dr;var Ru=(dr=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(dr,"Particle"),dr);function wo(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)],h=t.scales||[1],l=t.lifeTime,u=e.direction,f=e.spread,x=t.speed||[0,0],c=t.angle||[0,0],y=t.angularVelocity||[0,0],g=t.acceleration||[E(0),E(0)],M=t.damping||[0,0],p=[],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(yo,"polygon");function Fn(t,e,r){let s;return d.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)c(A)},"createSpatialMap"),c=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 S=i[v].indexOf(A);S>=0&&i[v].splice(S,1)}},"removeFromSpatialMap"),g=a(()=>{let A=false;for(let v of r.children){let S=r.pos2Tile(v.pos);(v.tilePos.x!=S.x||v.tilePos.y!=S.y)&&(A=true,y(v),v.tilePos.x=S.x,v.tilePos.y=S.y,c(v))}A&&r.trigger("spatialMapChanged")},"updateSpatialMap"),M=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 S=0;S{let A=r.getSpatialMap(),v=r.numRows()*r.numColumns();h?h.length=v:h=new Array(v),h.fill(15,0,v);for(let S=0;S{let A=r.numRows()*r.numColumns(),v=a((k,I)=>{let D=[];for(D.push(k);D.length>0;){let L=D.pop();O(L).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 S=0;for(let k=0;k=0){S++;continue}v(k,S),S++}},"createConnectivityMap"),R=a((A,v)=>o[v],"getCost"),P=a((A,v)=>{let S=f(A),k=f(v);return S.dist(k)},"getHeuristic"),O=a((A,v)=>{let S=[],k=Math.floor(A%n),I=k>0&&h[A]&1&&o[A-1]!==1/0,D=A>=n&&h[A]&2&&o[A-n]!==1/0,L=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](S)}else if(e.wildcardTile)return e.wildcardTile(A,S)}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(Or(this.tile2Pos(S))),D||k.push(Zn());let L=r.add(k);return I&&(L.tilePosOffset=L.pos.clone()),L.tilePos=S,L.transform=Yt(L),i&&(c(L),this.trigger("spatialMapChanged"),this.trigger("navigationMapInvalid")),L},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:c,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 S=this.toWorld(A),k=this.toWorld(A.add(v)).sub(S),I=1/this.tileWidth(),D=A.scale(I),L=Oi(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(S,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 ha((ee,J)=>ee.costL.scale(k,I).add(k/2,I/2)),v]:null}};return r.use(F),r.onNavigationMapInvalid(()=>{r.invalidateNavigationMap(),r.trigger("navigationMapChanged")}),t.forEach((A,v)=>{let S=A.split("");n=Math.max(S.length,n),S.forEach((k,I)=>{r.spawn(k,E(I,v))})}),r}a(xo,"addLevel");function qe(t,e,r){return d.game.objEvents.registers[t]||(d.game.objEvents.registers[t]=new ua),d.game.objEvents.on(t,(s,...n)=>{s.is(e)&&r(s,...n)})}a(qe,"on");var Pu=a((t,e,...r)=>{for(let s of d.game.root.children)s.is(e)&&s.trigger(t)},"trigger");var ku=ne(t=>{let e=d.game.root.add([{fixedUpdate:t}]);return{get paused(){return e.paused},set paused(r){e.paused=r},cancel:a(()=>e.destroy(),"cancel")}},(t,e)=>qe("fixedUpdate",t,e));var Iu=ne(t=>{let e=d.game.root.add([{update:t}]);return{get paused(){return e.paused},set paused(r){e.paused=r},cancel:a(()=>e.destroy(),"cancel")}},(t,e)=>qe("update",t,e));var Tu=ne(t=>{let e=d.game.root.add([{draw:t}]);return{get paused(){return e.hidden},set paused(r){e.hidden=r},cancel:a(()=>e.destroy(),"cancel")}},(t,e)=>qe("draw",t,e));var vo=ne(t=>d.game.events.on("add",t),(t,e)=>qe("add",t,e));var Fu=ne(t=>d.game.events.on("destroy",t),(t,e)=>qe("destroy",t,e));var Du=ne(t=>d.game.events.on("use",t),(t,e)=>qe("use",t,e));var Ou=ne(t=>d.game.events.on("unuse",t),(t,e)=>qe("unuse",t,e));var bo=ne(t=>d.game.events.on("tag",t),(t,e)=>qe("tag",t,e));var Lu=ne(t=>d.game.events.on("untag",t),(t,e)=>qe("untag",t,e));function Eo(t,e,r){return qe("collide",t,(s,n,i)=>n.is(e)&&r(s,n,i))}a(Eo,"onCollide");function So(t,e,r){return qe("collideUpdate",t,(s,n,i)=>n.is(e)&&r(s,n,i))}a(So,"onCollideUpdate");function Mo(t,e,r){return qe("collideEnd",t,(s,n,i)=>n.is(e)&&r(s,n,i))}a(Mo,"onCollideEnd");function Vr(t,e){d.game.root.get(t,{recursive:true}).forEach(e),vo(t,e),bo((r,s)=>{s===t&&e(r)})}a(Vr,"forAllCurrentAndFuture");var Uu=ne(t=>d.app.onMousePress(t),(t,e)=>{let r=[];return Vr(t,s=>{if(!s.area)throw new Error("onClick() requires the object to have area() component");r.push(s.onClick(()=>e(s)))}),Tt.join(r)});function qo(t,e){let r=[];return Vr(t,s=>{if(!s.area)throw new Error("onHover() requires the object to have area() component");r.push(s.onHover(()=>e(s)))}),Tt.join(r)}a(qo,"onHover");function Co(t,e){let r=[];return Vr(t,s=>{if(!s.area)throw new Error("onHoverUpdate() requires the object to have area() component");r.push(s.onHoverUpdate(()=>e(s)))}),Tt.join(r)}a(Co,"onHoverUpdate");function Bo(t,e){let r=[];return Vr(t,s=>{if(!s.area)throw new Error("onHoverEnd() requires the object to have area() component");r.push(s.onHoverEnd(()=>e(s)))}),Tt.join(r)}a(Bo,"onHoverEnd");function Ro(t){d.game.events.on("loading",t)}a(Ro,"onLoading");function Po(t){d.app.onResize(t)}a(Po,"onResize");function ko(t){d.game.events.on("error",t)}a(ko,"onError");function Ps(t){d.assets.loaded?t():d.game.events.on("load",t)}a(Ps,"onLoad");function Io(t){if(d.assets.loaded)yn().forEach(e=>t(...e));else return d.game.events.on("loadError",t)}a(Io,"onLoadError");function On(...t){d.game.cam.pos=E(...t)}a(On,"setCamPos");function Ln(){return d.game.cam.pos?d.game.cam.pos.clone():Tr()}a(Ln,"getCamPos");function Un(...t){d.game.cam.scale=E(...t)}a(Un,"setCamScale");function Nn(){return d.game.cam.scale.clone()}a(Nn,"getCamScale");function Hn(t){d.game.cam.angle=t}a(Hn,"setCamRot");function Gn(){return d.game.cam.angle}a(Gn,"getCamRot");function To(){return d.game.cam.transform.clone()}a(To,"getCamTransform");function jn(t=_(255,255,255),e=1){let r=d.game.root.add([Dn(we(),Ae()),In(t),Tn(1),ei()]),s=r.fadeOut(e);return s.onEnd(()=>Wn(r)),s}a(jn,"flash");function Fo(){return d.game.cam.transform.clone()}a(Fo,"camTransform");function Do(t=12){d.game.cam.shake+=t}a(Do,"shake");function ds(t){return d.game.cam.transform.multVec2(t)}a(ds,"toScreen");function Vn(t){return d.game.cam.transform.invert().multVec2(t)}a(Vn,"toWorld");function Oo(...t){return Ft("camPos","setCamPos / getCamPos"),t.length>0&&On(...t),Ln()}a(Oo,"camPos");function Lo(...t){return Ft("camScale","setCamScale / getCamScale"),t.length>0&&Un(...t),Nn()}a(Lo,"camScale");function Uo(t){return Ft("camRot","setCamRot / getCamRot"),t!==void 0&&Hn(t),Gn()}a(Uo,"camRot");function No(t=_(255,255,255),e=1){return Ft("camFlash","flash"),jn(t,e)}a(No,"camFlash");function ks(t=[]){let e=new Map,r=[],s={},n=new kr,i=[],o=new Set("*"),h=d.globalOpt.tagsAsComponents,l=null,u=false,f={id:su(),hidden:false,transform:new Ze,children:[],parent:null,set paused(c){if(c!==u){u=c;for(let y of i)y.paused=c}},get paused(){return u},get tags(){return Array.from(o)},add(c){let y=Array.isArray(c)?ks(c):c;if(y.parent)throw new Error("Cannot add a game obj that already has a parent.");return y.parent=this,y.transform=Yt(y),this.children.push(y),y.trigger("add",y),d.game.events.trigger("add",y),y},readd(c){let y=this.children.indexOf(c);return y!==-1&&(this.children.splice(y,1),this.children.push(c)),c},remove(c){let y=this.children.indexOf(c);if(y!==-1){c.parent=null,this.children.splice(y,1);let g=a(M=>{M.trigger("destroy"),d.game.events.trigger("destroy",M),M.children.forEach(p=>g(p))},"trigger");g(c)}},removeAll(c){if(c)this.get(c).forEach(y=>this.remove(y));else for(let y of[...this.children])this.remove(y)},fixedUpdate(){this.paused||(this.children.forEach(c=>c.fixedUpdate()),this.trigger("fixedUpdate"))},update(){this.paused||(this.children.forEach(c=>c.update()),this.trigger("update"))},draw(){if(this.hidden)return;this.canvas&&(Re(),this.canvas.bind());let c=d.gfx.fixed;this.fixed&&(d.gfx.fixed=true),Be(),ae(this.pos),wr(this.scale),It(this.angle);let y=this.children.sort((g,M)=>{let p=g.layerIndex??d.game.defaultLayerIndex,w=M.layerIndex??d.game.defaultLayerIndex;return p-w||(g.z??0)-(M.z??0)});if(this.mask){let g={intersect:d.k.drawMasked,subtract:d.k.drawSubtracted}[this.mask];if(!g)throw new Error(`Invalid mask func: "${this.mask}"`);g(()=>{y.forEach(M=>M.draw())},()=>{this.trigger("draw")})}else this.trigger("draw"),y.forEach(g=>g.draw());Ee(),d.gfx.fixed=c,this.canvas&&(Re(),this.canvas.unbind())},drawInspect(){this.hidden||(Be(),ae(this.pos),wr(this.scale),It(this.angle),this.children.forEach(c=>c.drawInspect()),this.trigger("drawInspect"),Ee())},use(c){var M;if(typeof c=="string")return o.add(c);if(!c||typeof c!="object")throw new Error(`You can only pass a component or a string to .use(), you passed a "${typeof c}"`);let y=[];c.id?(this.unuse(c.id),s[c.id]=[],y=s[c.id],e.set(c.id,c),h&&o.add(c.id)):r.push(c);for(let p in c){if(Ql.has(p))continue;let w=Object.getOwnPropertyDescriptor(c,p);if(w)if(typeof w.value=="function"&&(c[p]=c[p].bind(this)),w.set&&Object.defineProperty(c,p,{set:w.set.bind(this)}),w.get&&Object.defineProperty(c,p,{get:w.get.bind(this)}),Xl.has(p)){let R=p==="add"?()=>{var P;l=a(O=>y.push(O),"onCurCompCleanup"),(P=c[p])==null?void 0:P.call(c),l=null}:c[p];y.push(this.on(p,R).cancel)}else if(this[p]===void 0)Object.defineProperty(this,p,{get:a(()=>c[p],"get"),set:a(R=>c[p]=R,"set"),configurable:true,enumerable:true}),y.push(()=>delete this[p]);else{let R=(M=e.values().find(P=>P[p]!==void 0))==null?void 0:M.id;throw new Error(`Duplicate component property: "${p}" while adding component "${c.id}"`+(R?` (originally added by "${R}")`:""))}}let g=a(()=>{if(c.require){for(let p of c.require)if(!this.c(p))throw new Error(`Component "${c.id}" requires component "${p}"`)}},"checkDeps");c.destroy&&y.push(c.destroy.bind(this)),this.exists()?(g(),c.add&&(l=a(p=>y.push(p),"onCurCompCleanup"),c.add.call(this),l=null),c.id&&(this.trigger("use",c.id),d.game.events.trigger("use",this,c.id))):c.require&&y.push(this.on("add",g).cancel)},unuse(c){if(e.has(c)){for(let y of e.values())if(y.require&&y.require.includes(c))throw new Error(`Can't unuse. Component "${y.id}" requires component "${c}"`);e.delete(c),this.trigger("unuse",c),d.game.events.trigger("unuse",this,c)}else h&&o.has(c)&&o.delete(c);s[c]&&(s[c].forEach(y=>y()),delete s[c])},c(c){return e.get(c)??null},get(c,y={}){let g=a((p,w)=>y.only==="comps"?p.has(w):y.only==="tags"?p.is(w):p.is(w)||p.has(w),"checkTagsOrComps"),M=y.recursive?this.children.flatMap(a(function p(w){return[w,...w.children.flatMap(p)]},"recurse")):this.children;if(M=M.filter(p=>c?g(p,c):true),y.liveUpdate){let p=a(R=>y.recursive?this.isAncestorOf(R):R.parent===this,"isChild"),w=[];w.push(d.k.onAdd(R=>{p(R)&&g(R,c)&&M.push(R)})),w.push(d.k.onDestroy(R=>{if(p(R)&&g(R,c)){let P=M.findIndex(O=>O.id===R.id);P!==-1&&M.splice(P,1)}})),this.onDestroy(()=>{for(let R of w)R.cancel()})}return M},query(c){let y=c.hierarchy||"children",g=c.include,M=c.exclude,p=[];switch(y){case"children":p=this.children;break;case"siblings":p=this.parent?this.parent.children.filter(R=>R!==this):[];break;case"ancestors":let w=this.parent;for(;w;)p.push(w),w=w.parent;break;case"descendants":p=this.children.flatMap(a(function R(P){return[P,...P.children.flatMap(R)]},"recurse"));break}if(g&&((c.includeOp||"and")==="and"||!Array.isArray(c.include)?p=p.filter(w=>w.is(g)):p=p.filter(w=>c.include.some(R=>w.is(R)))),M&&((c.includeOp||"and")==="and"||!Array.isArray(c.include)?p=p.filter(w=>!w.is(M)):p=p.filter(w=>!c.exclude.some(R=>w.is(R)))),c.visible===true&&(p=p.filter(w=>w.visible)),c.distance){if(!this.pos)throw Error("Can't do a distance query from an object without pos");let w=c.distanceOp||"near",R=c.distance*c.distance;w==="near"?p=p.filter(P=>P.pos&&this.pos.sdist(P.pos)<=R):p=p.filter(P=>P.pos&&this.pos.sdist(P.pos)>R)}return c.name&&(p=p.filter(w=>w.name===c.name)),p},isAncestorOf(c){return c.parent?c.parent===this||this.isAncestorOf(c.parent):false},exists(){return d.game.root.isAncestorOf(this)},is(c,y="and"){return Array.isArray(c)?y==="and"?c.every(g=>o.has(g)):c.some(g=>o.has(g)):o.has(c)},tag(c){if(Array.isArray(c))for(let y of c)o.add(y),this.trigger("tag",y),d.game.events.trigger("tag",this,y);else o.add(c),this.trigger("tag",c),d.game.events.trigger("tag",this,c)},untag(c){if(Array.isArray(c))for(let y of c)o.delete(y),this.trigger("untag",y),d.game.events.trigger("untag",this,y);else o.delete(c),this.trigger("untag",c),d.game.events.trigger("untag",this,c)},has(c,y="and"){return Array.isArray(c)?y==="and"?c.every(g=>e.has(g)):c.some(g=>e.has(g)):e.has(c)},on(c,y){let g=n.on(c,y.bind(this));return l&&l(()=>g.cancel()),g},trigger(c,...y){n.trigger(c,...y),d.game.objEvents.trigger(c,this,...y)},destroy(){this.parent&&this.parent.remove(this)},inspect(){var y;let c={};for(let[g,M]of e)c[g]=((y=M.inspect)==null?void 0:y.call(M))??null;for(let[g,M]of r.entries()){if(M.inspect){c[g]=M.inspect();continue}for(let[p,w]of Object.entries(M))typeof w!="function"&&(c[p]=`${p}: ${w}`)}return c},onAdd(c){return this.on("add",c)},onFixedUpdate(c){return this.on("fixedUpdate",c)},onUpdate(c){return this.on("update",c)},onDraw(c){return this.on("draw",c)},onDestroy(c){return this.on("destroy",c)},onUse(c){return this.on("use",c)},onUnuse(c){return this.on("unuse",c)},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 c of x)f[c]=(...y)=>{var M,p;let g=(p=(M=d.app)[c])==null?void 0:p.call(M,...y);return i.push(g),f.onDestroy(()=>g.cancel()),f.on("sceneEnter",()=>{var R,P;i.splice(i.indexOf(g),1);let w=(P=(R=d.app)[c])==null?void 0:P.call(R,...y);Tt.replace(g,w),i.push(g)}),g};for(let c of t)f.use(c);return f}a(ks,"make");var Nu=a(()=>({events:new kr,objEvents:new kr,root:ks([]),gravity:null,scenes:{},currentScene:null,layers:null,defaultLayerIndex:0,logs:[],cam:{pos:null,scale:new C(1),angle:0,shake:0,transform:new Ze}}),"initGame");function Ho(t){d.game.gravity=t?(d.game.gravity||E(0,1)).unit().scale(t):null}a(Ho,"setGravity");function Go(){return d.game.gravity?d.game.gravity.len():0}a(Go,"getGravity");function jo(t){d.game.gravity=t.unit().scale(d.game.gravity?d.game.gravity.len():1)}a(jo,"setGravityDirection");function Xt(){return d.game.gravity?d.game.gravity.unit():E(0,1)}a(Xt,"getGravityDirection");var Hu=Dl("//uUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAATAAAeAAANDQ0NDRoaGhoaKCgoKCg1NTU1NTVDQ0NDQ1BQUFBQXl5eXl5ra2tra2t5eXl5eYaGhoaGlJSUlJShoaGhoaGvr6+vr7y8vLy8ysrKysrX19fX19fl5eXl5fLy8vLy//////8AAAA5TEFNRTMuMTAwAaoAAAAAAAAAABSAJAOPhgAAgAAAHgBaqIlmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//uUBAAP8h1kPIABR4BEDGeQAEbkSb2RAACBFMEyMiAAASJw4xjgwAGyRvfIoZT2QKGV5YNw/tKID9+X93qXtBQUFBQ/e+EFKTQUT/dy3f5dK/3d04rkXHpufCClDAaH7jDMgFAQEGfPt+jI352U9vU4GLRpzkUDeeeTQggQe2ggF3d7/3j697DnhCH5iGf38//iNj9oy2Jk71oj+CBAABGNB4RJNMwgCABCB//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cKB+HpYd/3//i3rZFOT0N05+QpgWZYZ3pi5biJNCj4fRQQwYK8p48BQUTWPDTbNjkPn8+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 Gu=a(()=>(()=>{let t=new(window.AudioContext||window.webkitAudioContext),e=t.createGain();e.connect(t.destination);let r=new Fr(Ca(t));return t.decodeAudioData(Hu.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 Vo(t,e={}){let r=new be,s=new Audio(t);s.crossOrigin="anonymous",s.loop=!!e.loop,d.audio.ctx.createMediaElementSource(s).connect(d.audio.masterNode);function n(){d.debug.paused||d.app.isHidden()&&!d.globalOpt.backgroundAudio||d.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=je(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(Vo,"playMusic");function Ko(t,e={}){if(typeof t=="string"&&d.assets.music[t])return Vo(d.assets.music[t],e);let r=d.audio.ctx,s=e.paused??false,n=r.createBufferSource(),i=new be,o=r.createGain(),h=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(h),n.onended=()=>{var p;g()>=(((p=n.buffer)==null?void 0:p.duration)??Number.POSITIVE_INFINITY)&&i.trigger()},h.pan.value=e.pan??0,h.connect(o),o.connect(d.audio.masterNode),o.gain.value=e.volume??1;let c=a(p=>{n.buffer=p.buf,s||(u=r.currentTime,n.start(0,l),x=true)},"start"),y=Za(t);y instanceof Le&&y.onLoad(c);let g=a(()=>{if(!n.buffer)return 0;let p=s?f-u:r.currentTime-u,w=n.buffer.duration;return n.loop?p%w:Math.min(p,w)},"getTime"),M=a(p=>{let w=r.createBufferSource();return w.buffer=p.buffer,w.loop=p.loop,w.playbackRate.value=p.playbackRate.value,w.detune.value=p.detune.value,w.onended=p.onended,w.connect(h),w},"cloneNode");return{stop(){this.paused=true,this.seek(0)},set paused(p){if(s!==p)if(s=p,p)x&&(n.stop(),x=false),f=r.currentTime;else{n=M(n);let w=f-u;n.start(0,w),x=true,u=r.currentTime-w,f=0}},get paused(){return s},play(p=0){this.seek(p),this.paused=false},seek(p){var w;((w=n.buffer)==null?void 0:w.duration)&&(p>n.buffer.duration||(s?(n=M(n),u=f-p):(n.stop(),n=M(n),u=r.currentTime-p,n.start(0,p),x=true,f=0)))},set speed(p){n.playbackRate.value=p},get speed(){return n.playbackRate.value},set detune(p){n.detune.value=p},get detune(){return n.detune.value},set volume(p){o.gain.value=Math.max(p,0)},get volume(){return o.gain.value},set pan(p){h.pan.value=p},get pan(){return h.pan.value},set loop(p){n.loop=p},get loop(){return n.loop},duration(){var p;return((p=n.buffer)==null?void 0:p.duration)??0},time(){return g()%this.duration()},onEnd(p){return i.add(p)},then(p){return this.onEnd(p)}}}a(Ko,"play");function Kn(t){return d.k.play(d.audio.burpSnd,t)}a(Kn,"burp");function Yn(t){d.audio.masterNode.gain.value=t}a(Yn,"setVolume");function Qn(){return d.audio.masterNode.gain.value}a(Qn,"getVolume");function Yo(t){return Ft("volume","setVolume / getVolume"),t!==void 0&&Yn(t),Qn()}a(Yo,"volume");function Xn(){d.app.onHide(()=>{d.globalOpt.backgroundAudio||d.audio.ctx.suspend()}),d.app.onShow(()=>{!d.globalOpt.backgroundAudio&&!d.debug.paused&&d.audio.ctx.resume()}),d.app.onResize(()=>{if(d.app.isFullscreen())return;let t=d.globalOpt.width&&d.globalOpt.height;t&&!d.globalOpt.stretch&&!d.globalOpt.letterbox||(d.canvas.width=d.canvas.offsetWidth*d.pixelDensity,d.canvas.height=d.canvas.offsetHeight*d.pixelDensity,kn(),t||(d.gfx.frameBuffer.free(),d.gfx.frameBuffer=new us(d.gfx.ggl,d.gfx.ggl.gl.drawingBufferWidth,d.gfx.ggl.gl.drawingBufferHeight),d.gfx.width=d.gfx.ggl.gl.drawingBufferWidth/d.pixelDensity/d.gscale,d.gfx.height=d.gfx.ggl.gl.drawingBufferHeight/d.pixelDensity/d.gscale))}),d.globalOpt.debug!==false&&(d.app.onKeyPress(d.globalOpt.debugKey??"f1",()=>d.debug.inspect=!d.debug.inspect),d.app.onKeyPress("f2",()=>d.debug.clearLog()),d.app.onKeyPress("f8",()=>d.debug.paused=!d.debug.paused),d.app.onKeyPress("f7",()=>{d.debug.timeScale=is(je(d.debug.timeScale-.2,0,2),1)}),d.app.onKeyPress("f9",()=>{d.debug.timeScale=is(je(d.debug.timeScale+.2,0,2),1)}),d.app.onKeyPress("f10",()=>d.debug.stepFrame())),d.globalOpt.burp&&d.app.onKeyPress("b",()=>Kn())}a(Xn,"initEvents");function Qo(t,e={}){let r=d.game.root.add([Or(t),_n()]),s=(e.speed||1)*5,n=e.scale||1;r.add([fs(d.boomSprite),Lr(0),gs("center"),Ws(s,n),...e.comps??[]]);let i=r.add([fs(d.kaSprite),Lr(0),gs("center"),ps(),...e.comps??[]]);return i.wait(.4/s,()=>i.use(Ws(s,n))),i.onDestroy(()=>r.destroy()),r}a(Qo,"addKaboom");function zn(t,e){if(d.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.");d.game.layers=t,d.game.defaultLayerIndex=r}a(zn,"setLayers");function Xo(){return d.game.layers}a(Xo,"getLayers");function zo(){var t;return((t=d.game.layers)==null?void 0:t[d.game.defaultLayerIndex])??null}a(zo,"getDefaultLayer");function Wo(t,e){Ft("layers","setLayers"),zn(t,e)}a(Wo,"layers");function Wn(t){t.destroy()}a(Wn,"destroy");function Zo(){return d.game.root}a(Zo,"getTreeRoot");function Jo(t,e){d.game.scenes[t]=e}a(Jo,"scene");function $o(t,...e){if(!d.game.scenes[t])throw new Error(`Scene not found: ${t}`);d.game.events.onOnce("frameEnd",()=>{d.game.events.trigger("sceneLeave",t),d.app.events.clear(),d.game.events.clear(),d.game.objEvents.clear(),[...d.game.root.children].forEach(r=>{!r.stay||r.scenesToStay&&!r.scenesToStay.includes(t)?d.game.root.remove(r):r.trigger("sceneEnter",t)}),d.game.root.clearEvents(),Xn(),d.game.cam={pos:null,scale:E(1),angle:0,shake:0,transform:new Ze},d.game.scenes[t](...e)}),d.game.currentScene=t}a($o,"go");function _o(t){return d.game.events.on("sceneLeave",t)}a(_o,"onSceneLeave");function el(){return d.game.currentScene}a(el,"getSceneName");function fs(t,e={}){let r=null,s=null,n=null,i=new be;if(!t)throw new Error("Please pass the resource name or data to sprite()");let o=a((l,u,f,x)=>{let c=E(1,1);return f&&x?(c.x=f/(l.width*u.w),c.y=x/(l.height*u.h)):f?(c.x=f/(l.width*u.w),c.y=c.x):x&&(c.y=x/(l.height*u.h),c.x=c.y),c},"calcTexScale"),h=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=>h(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:c}=r.slice9,y=r.tex.width*l.w,g=r.tex.height*l.h,M=this.width-u-f,p=this.height-x-c,w=u/y,R=f/y,P=1-w-R,O=x/g,F=c/g,A=1-O-F,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,F),he(w,O+A,P,F),he(w+P,O+A,R,F),he(0,0,u,x),he(u,0,M,x),he(u+M,0,f,x),he(0,x,u,p),he(u,x,M,p),he(u+M,x,f,p),he(0,x+p,u,c),he(u,x+p,M,c),he(u+M,x+p,f,c)];for(let S=0;S<9;S++){let k=v[S],I=v[S+9];Dr(Object.assign(Et(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 Dr(Object.assign(Et(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=>h(this,u)):Ps(()=>h(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(){bt(r(this))},renderArea(){return new ie(E(0),this.width,this.height)}};return r(s),s}a(tl,"text");function rl(t,e){return{id:"rect",width:t,height:e,draw(){yr(Object.assign(Et(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(rl,"uvquad");function sl(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(sl,"agent");function nl(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(nl,"pathfinder");function il(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(il,"patrol");function al(t,e={}){let r=typeof t=="function"?t:()=>d.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,h,l){let u=(typeof h=="number"?C.fromAngle(h):h)||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 h=Fn(this.pos,o.pos.sub(this.pos),e.raycastExclude);return h!=null&&h.object===o},update(){if(i+=ge(),i>s){i-=s;let o=r();if(o.length&&n&&this.fieldOfView&&this.fieldOfView<360){let h=this.fieldOfView/2;o=o.filter(l=>l.pos&&n.angleBetween(l.pos.sub(this.pos))<=h)}o.length&&e.lineOfSight&&(o=o.filter(h=>h.pos&&this.hasLineOfSight(h))),o.length>0&&(this.spotted=o,this.trigger("objectSpotted",o))}},onObjectsSpotted(o){return this.on("objectSpotted",o)}}}a(al,"sentry");function Zn(t={}){let e=E(0),r=t.isObstacle??false,s=t.cost??0,n=t.edges??[],i=a(()=>{let h={left:1,top:2,right:4,bottom:8};return n.map(l=>h[l]||0).reduce((l,u)=>l|u,0)},"getEdgeMask"),o=i();return{id:"tile",tilePosOffset:t.offset??E(0),set tilePos(h){let l=this.getLevel();e=h.clone(),this.pos=E(this.tilePos.x*l.tileWidth(),this.tilePos.y*l.tileHeight()).add(this.tilePosOffset)},get tilePos(){return e},set isObstacle(h){r!==h&&(r=h,this.getLevel().invalidateNavigationMap())},get isObstacle(){return r},set cost(h){s!==h&&(s=h,this.getLevel().invalidateNavigationMap())},get cost(){return s},set edges(h){n=h,o=i(),this.getLevel().invalidateNavigationMap()},get edges(){return n},get edgeMask(){return o},getLevel(){return this.parent},tileMove(h){let l=this.getLevel();l.removeFromSpatialMap(this),this.tilePos=this.tilePos.add(h),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(Zn,"tile");var fr;var Jn=(fr=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||Ir.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 h=0;for(;s[h+1]!==void 0&&s[h+1]=n?[n,0,true]:[h,(i-s[h])/(s[h+1]-s[h]),false]}else{let h=Math.floor((r-1)*i);return[h,(i-h/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!=Ir.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(fr,"AnimateChannel"),fr);function zs(t,e){return e.add(e.sub(t))}a(zs,"reflect");var pr;var ju=(pr=class extends Jn{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 h=this.easings?this.easings[n]:this.easing;this.setValue(r,this.name,Se(this.keys[n],this.keys[n+1],h(i)))}return o}serialize(){return Object.assign(super.serialize(),{keys:this.keys})}},a(pr,"AnimateChannelNumber"),pr);var gr;var Vu=(gr=class extends Jn{constructor(r,s,n,i,o){var h;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]:zs(x,u),y=f[r.x,r.y])})}},a(gr,"AnimateChannelVec2"),gr);var mr;var Ku=(mr=class extends Jn{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 h=this.easings?this.easings[n]:this.easing;this.setValue(r,this.name,this.keys[n].lerp(this.keys[n+1],h(i)))}return o}serialize(){return Object.assign(super.serialize(),{keys:this.keys})}},a(mr,"AnimateChannelColor"),mr);function ol(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=je(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 ju(n,i,o,t.relative||false)):i[0]instanceof C?e.push(new Vu(n,i,o,t.relative||false,n==="pos"&&(t.followMotion||false))):i[0]instanceof X&&e.push(new Ku(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(ol,"animate");function $n(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=>$n(s,s.name))),r}a($n,"serializeAnimation");function Ws(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(Ws,"boom");function ll(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(ll,"health");function ul(t,e={}){if(t==null)throw new Error("lifespan() requires time");let r=e.fade??0;return{id:"lifespan",require:["opacity"],add(){d.game.root.wait(t,()=>{this.opacity=this.opacity??1,r>0?d.game.root.tween(this.opacity,0,r,s=>this.opacity=s,Ir.linear).onEnd(()=>{this.destroy()}):this.destroy()})}}}a(ul,"lifespan");function hl(t){return{id:"named",name:t}}a(hl,"named");function cl(t,e,r){if(!t)throw new Error("state() requires an initial state");let s={};function n(l){s[l]||(s[l]={enter:new be,end:new be,update:new be,draw:new be})}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 h=false;return{id:"state",state:t,enterState(l,...u){if(h=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(c=>`"${c}"`).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(){h||(o("enter",t),h=true),o("update",this.state)},draw(){o("draw",this.state)},inspect(){return`state: ${this.state}`}}}a(cl,"state");function _n(t){return{id:"stay",stay:true,scenesToStay:t}}a(_n,"stay");function dl(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=d.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(dl,"textInput");function ps(t=1e3){return{id:"timer",maxLoopsPerFrame:t,loop(e,r,s=-1,n=false){let i=n?0:e,o=new be,h=this.onUpdate(()=>{i+=d.app.state.dt;for(let l=0;i>=e&&l{}),1,true)},tween(e,r,s,n,i=Ir.linear){let o=0,h=[],l=this.onUpdate(()=>{o+=d.app.state.dt;let u=Math.min(o/s,1);n(Se(e,r,i(u))),u===1&&(l.cancel(),n(r),h.forEach(f=>f()))});return{get paused(){return l.paused},set paused(u){l.paused=u},onEnd(u){h.push(u)},then(u){return this.onEnd(u),this},cancel(){l.cancel()},finish(){l.cancel(),n(r),h.forEach(u=>u())}}}}}a(ps,"timer");var Zs=0;function fl(){return Zs>0}a(fl,"usesArea");function pl(t={}){let e={},r=new Set,s=[];return{id:"area",collisionIgnore:t.collisionIgnore??[],add(){Zs++,this.area.cursor&&s.push(this.onHover(()=>d.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(){Zs--;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();Be(),ae(this.area.offset);let i={outline:{width:4/mn(),color:_(0,0,255)},anchor:this.anchor,fill:false,fixed:ft(this)};n instanceof ie?Pe({...i,pos:n.pos,width:n.width*this.area.scale.x,height:n.height*this.area.scale.y}):n instanceof Me?it({...i,pts:n.pts,scale:this.area.scale}):n instanceof Ie&&Ot({...i,pos:n.center,radius:n.radius}),Ee()},area:{shape:t.shape??null,scale:t.scale?E(t.scale):E(1),offset:t.offset??E(0),cursor:t.cursor??null},isClicked(){return d.app.isMousePressed()&&this.isHovering()},isHovering(){let n=ft(this)?d.k.mousePos():d.k.toWorld(d.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=d.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,h)=>{o.is(n)&&(i==null?void 0:i(o,h))});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,h)=>o.is(n)&&(i==null?void 0:i(o,h)));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 at(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 Me||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=Dt(this.anchor||Es).add(1,1).scale(-.5).scale(n.width,n.height);i.translate(o)}return n.transform(i)},screenArea(){let n=this.worldArea();return ft(this)?n:n.transform(d.game.cam.transform)},inspect(){var n,i,o,h,l,u,f;return((n=this.area.scale)==null?void 0:n.x)==((i=this.area.scale)==null?void 0:i.y)?`area: ${(h=(o=this.area.scale)==null?void 0:o.x)==null?void 0:h.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(pl,"area");function gl(t={}){let e=null,r=null,s=false,n=E(0),i=null,o=null,h;return{id:"body",require:["pos"],vel:E(0),drag:t.drag??0,jumpForce:t.jumpForce??Wl,gravityScale:t.gravityScale??1,isStatic:t.isStatic??false,mass:t.mass??1,add(){if(i=this.pos.clone(),o=this.pos.clone(),h=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=Yt(this),l.transform=Yt(l)}else{let x=!this.isStatic&&l.isStatic?u:u.reverse();x.source.pos=x.source.pos.add(x.displacement),x.source.transform=Yt(x.source)}u.resolved=true,this.trigger("physicsResolve",u),l.trigger("physicsResolve",u.reverse())}}),this.onPhysicsResolve(l=>{if(d.game.gravity)if(l.isBottom()&&this.isFalling()){this.vel=this.vel.reject(d.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(d.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=os();l&&(this.pos.x==h.x&&(this.pos.x=Se(i.x,o.x,l/as()),h.x=this.pos.x),this.pos.y==h.y&&(this.pos.y=Se(i.y,o.y,l/as()),h.y=this.pos.y))},fixedUpdate(){if(i&&(this.pos.x==h.x&&(this.pos.x=i.x),this.pos.y==h.y&&(this.pos.y=i.y),i=null),d.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(d.game.gravity.scale(this.gravityScale*ge()));let u=t.maxVelocity??Zl;this.vel.slen()>u*u&&(this.vel=this.vel.unit().scale(u)),l.dot(d.game.gravity)<0&&this.vel.dot(d.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),os()){i=this.pos.clone();let l=this.vel.add(n.scale(ge()));o=this.pos.add(l.scale(ge())),h=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(Xt())>0},isJumping(){return this.vel.dot(Xt())<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=Xt().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(gl,"body");function ml(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(wl,"surfaceEffector");function yl(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(yl,"areaEffector");function Al(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,h=s.scale(this.forceMagnitude*o/n);e.addForce(h),this.linearDrag&&e.addForce(e.vel.scale(-this.linearDrag))})}}}a(Al,"pointEffector");function xl(t){return{id:"constantForce",require:["body"],force:t.force,update(){this.force&&this.addForce(this.force)}}}a(xl,"constantForce");function vl(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=Xt().scale(-1).angleBetween(r);Math.abs(s)>this.surfaceArc/2&&e.preventResolution()})}}}a(vl,"platformEffector");function bl(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(bl,"buoyancyEffector");function gs(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(gs,"anchor");function ei(){return{id:"fixed",fixed:true}}a(ei,"fixed");function El(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(El,"follow");function Sl(t){var r;let e=(r=d.game.layers)==null?void 0:r.indexOf(t);return{id:"layer",get layerIndex(){return e??null},get layer(){var s;return e?((s=d.game.layers)==null?void 0:s[e])??null:null},set layer(s){var n;if(e=(n=d.game.layers)==null?void 0:n.indexOf(s),e==-1)throw Error("Invalid layer name")},inspect(){return`layer: ${this.layer}`}}}a(Sl,"layer");function Ml(t,e){let r=typeof t=="number"?C.fromAngle(t):t.unit();return{id:"move",require:["pos"],update(){this.move(r.scale(e))}}}a(Ml,"move");function ql(t={}){let e=t.distance??zl,r=false;return{id:"offscreen",require:["pos"],isOffScreen(){let s=this.screenPos();if(!s)return false;let n=new ie(E(0),we(),Ae());return!Ur(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(ql,"offscreen");function Or(...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?ft(this)?r:ds(r):null}},toScreen(e){let r=this.toWorld(e);return ft(this)?r:ds(r)},fromScreen(e){return ft(this)?this.fromWorld(e):this.fromWorld(Vn(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(){Ot({color:_(255,0,0),radius:4/mn()})}}}a(Or,"pos");function Cl(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(Cl,"rotate");function Lr(...t){if(t.length===0)return Lr(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(Lr,"scale");function Bl(t){return{id:"z",z:t,inspect(){return`z: ${this.z}`}}}a(Bl,"z");var Yu="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAACDCAYAAAB2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ChshKNM3qd4135BCaqK9VAKy+lAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/4DBC0k0jFtF9wAAAAASUVORK5CYII=";var Xu="3001.0.0";var d={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 zu=a((t={tagsAsComponents:true})=>{d.k&&(console.warn("KAPLAY already initialized, you are calling kaplay() multiple times, it may lead bugs!"),d.k.quit()),d.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"));d.canvas=r;let s=t.scale??1;d.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 U=r.width,K=r.height;i.push(`width: ${U}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;d.pixelDensity=o,r.width*=o,r.height*=o,r.tabIndex=0;let h=document.createElement("canvas");h.width=256,h.height=256,d.fontCacheCanvas=h;let l=h.getContext("2d",{willReadFrequently:true});d.fontCacheC2d=l;let u=hu({canvas:r,touchToMouse:t.touchToMouse,gamepads:t.gamepads,pixelDensity:t.pixelDensity,maxFPS:t.maxFPS,buttons:t.buttons});d.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 c=x,y=so(c,{texFilter:t.texFilter}),g=Bu(t,y);d.gfx=g;let M=Gu();d.audio=M;let p=Su(y,t.spriteAtlasPadding??0);d.assets=p;let w=Nu();d.game=w,w.root.use(ps());function R(U,K){let Q=new us(y,U,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=>{Re(),Q.bind(),re(),Re(),Q.unbind()},"draw"),get fb(){return Q}}}a(R,"makeCanvas");function P(){c.clear(c.COLOR_BUFFER_BIT),g.frameBuffer.bind(),c.clear(c.COLOR_BUFFER_BIT),g.bgColor||st(()=>{yr({width:we(),height:Ae(),quad:new oe(0,0,we()/64,Ae()/64),tex:g.bgTex,fixed:true})}),g.renderer.numDraws=0,g.fixed=false,g.transformStack.length=0,g.transform=new Ze}a(P,"frameStart");function O(U,K){g.postShader=U,g.postShaderUniform=K??null}a(O,"usePostEffect");function F(){Re(),g.lastDrawCalls=g.renderer.numDraws,g.frameBuffer.unbind(),c.viewport(0,0,c.drawingBufferWidth,c.drawingBufferHeight);let U=g.width,K=g.height;g.width=c.drawingBufferWidth/o,g.height=c.drawingBufferHeight/o,Dr({flipY:true,tex:g.frameBuffer.tex,pos:new C(g.viewport.x,g.viewport.y),width:g.viewport.width,height:g.viewport.height,shader:g.postShader,uniform:typeof g.postShaderUniform=="function"?g.postShaderUniform():g.postShaderUniform,fixed:true}),Re(),g.width=U,g.height=K}a(F,"frameEnd");let A=false,v={inspect:false,timeScale:1,showLog:true,fps:a(()=>u.fps(),"fps"),numFrames:a(()=>u.numFrames(),"numFrames"),stepFrame:ut,drawCalls:a(()=>g.lastDrawCalls,"drawCalls"),clearLog:a(()=>w.logs=[],"clearLog"),log:a((...U)=>{let K=t.logMax??8,Q=U.length>1?U.concat(" ").join(" "):U[0];w.logs.unshift({msg:Q,time:u.time()}),w.logs.length>K&&(w.logs=w.logs.slice(0,K))},"log"),error:a(U=>v.log(new Error(U.toString?U.toString():U)),"error"),curRecording:null,numObjects:a(()=>V("*",{recursive:true}).length,"numObjects"),get paused(){return A},set paused(U){A=U,U?M.ctx.suspend():M.ctx.resume()}};d.debug=v;function S(U,K){try{return JSON.parse(window.localStorage[U])}catch{return K?(k(U,K),K):null}}a(S,"getData");function k(U,K){window.localStorage[U]=JSON.stringify(K)}a(k,"setData");function I(U,...K){let Q=U(Ve),re;typeof Q=="function"?re=Q(...K)(Ve):re=Q;for(let de in re)Ve[de]=re[de],t.global!==false&&(window[de]=re[de]);return Ve}a(I,"plug");function D(U){let K=u.canvas.captureStream(U),Q=M.ctx.createMediaStreamDestination();M.masterNode.connect(Q);let re=new MediaRecorder(K),de=[];return re.ondataavailable=$=>{$.data.size>0&&de.push($.data)},re.onerror=()=>{M.masterNode.disconnect(Q),K.getTracks().forEach($=>$.stop())},re.start(),{resume(){re.resume()},pause(){re.pause()},stop(){return re.stop(),M.masterNode.disconnect(Q),K.getTracks().forEach($=>$.stop()),new Promise($=>{re.onstop=()=>{$(new Blob(de,{type:"video/mp4"}))}})},download($="kaboom.mp4"){this.stop().then(xe=>js($,xe))}}}a(D,"record");function L(){return document.activeElement===u.canvas}a(L,"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=Qt(null,Qu),H=Qt(null,Yu);d.kaSprite=le,d.boomSprite=H;function $e(){w.root.fixedUpdate()}a($e,"fixedUpdateFrame");function ut(){w.root.update()}a(ut,"updateFrame");const qt=class qt{constructor(K,Q,re,de,$=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=de,this.resolved=$}get displacement(){return this.normal.scale(this.distance)}reverse(){return new qt(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(qt,"Collision");let Lt=qt;function vr(){if(!fl())return;let U={},K=t.hashGridSize||64,Q=new Ze,re=[];function de($){if(re.push(Q.clone()),$.pos&&Q.translate($.pos),$.scale&&Q.scale($.scale),$.angle&&Q.rotate($.angle),$.transform=Q.clone(),$.c("area")&&!$.paused){let xe=$,ht=xe.worldArea().bbox(),Is=Math.floor(ht.pos.x/K),Ts=Math.floor(ht.pos.y/K),Xr=Math.ceil((ht.pos.x+ht.width)/K),zr=Math.ceil((ht.pos.y+ht.height)/K),Er=new Set;for(let Ue=Is;Ue<=Xr;Ue++)for(let _e=Ts;_e<=zr;_e++)if(!U[Ue])U[Ue]={},U[Ue][_e]=[xe];else if(!U[Ue][_e])U[Ue][_e]=[xe];else{let Nt=U[Ue][_e];e:for(let De of Nt){if(De.paused||!De.exists()||Er.has(De.id))continue;for(let et of xe.collisionIgnore)if(De.is(et))continue e;for(let et of De.collisionIgnore)if(xe.is(et))continue e;let Sr=ea(xe.worldArea(),De.worldArea());if(Sr){let et=new Lt(xe,De,Sr.normal,Sr.distance);xe.trigger("collideUpdate",De,et);let Mr=et.reverse();Mr.resolved=et.resolved,De.trigger("collideUpdate",xe,Mr)}Er.add(De.id)}Nt.push(xe)}}$.children.forEach(de),Q=re.pop()}a(de,"checkObj"),de(w.root)}a(vr,"checkFrame");function br(U){console.error(U),M.ctx.suspend();let K=U.message??String(U)??"Unknown error, check console for more info";u.run(()=>{},()=>{P(),st(()=>{let Q=we(),re=Ae(),de={size:36,width:Q-32*2,letterSpacing:4,lineSpacing:4,font:ns,fixed:true};Pe({width:Q,height:re,color:_(0,0,255),fixed:true});let $=vt({...de,text:"Error",pos:E(32),color:_(255,128,0),fixed:true});bt($),Xs({...de,text:K,pos:E(32,32+$.height+16),fixed:true}),Ee(),w.events.trigger("error",U)}),F()})}a(br,"handleErr");function Kr(U){f.push(U)}a(Kr,"onCleanup");function Yr(){w.events.onOnce("frameEnd",()=>{u.quit(),c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT|c.STENCIL_BUFFER_BIT);let U=c.getParameter(c.MAX_TEXTURE_IMAGE_UNITS);for(let K=0;KK())})}a(Yr,"quit");let Ut=true;u.run(()=>{try{p.loaded&&(v.paused||$e(),vr())}catch(U){br(U)}},(U,K)=>{try{U(),p.loaded||At()===1&&!Ut&&(p.loaded=true,yn().forEach(Q=>w.events.trigger("loadError",...Q)),w.events.trigger("load")),!p.loaded&&t.loadingScreen!==false||Ut?(P(),ao(),F()):(v.paused||ut(),vr(),P(),io(),t.debug!==false&&no(),F()),Ut&&(Ut=false),w.events.trigger("frameEnd"),K()}catch(Q){br(Q)}}),kn(),Xn();let Ve={_k:d,VERSION:Xu,loadRoot:Ua,loadProgress:At,loadSprite:Qt,loadSpriteAtlas:qn,loadSound:Ja,loadMusic:$a,loadBitmapFont:Ya,loadFont:Va,loadShader:za,loadShaderURL:Wa,loadAseprite:ja,loadPedit:Qa,loadBean:Ga,loadJSON:Na,load:ls,getSound:Mn,getFont:bn,getBitmapFont:En,getSprite:An,getShader:Sn,getAsset:Ha,Asset:Le,SpriteData:xt,SoundData:Fr,width:we,height:Ae,center:Tr,dt:ge,fixedDt:as,restDt:os,time:u.time,screenshot:u.screenshot,record:D,isFocused:L,setCursor:u.setCursor,getCursor:u.getCursor,setCursorLocked:u.setCursorLocked,isCursorLocked:u.isCursorLocked,setFullscreen:u.setFullscreen,isFullscreen:u.isFullscreen,isTouchscreen:u.isTouchscreen,onLoad:Ps,onLoadError:Io,onLoading:Ro,onResize:Po,onGamepadConnect:u.onGamepadConnect,onGamepadDisconnect:u.onGamepadDisconnect,onError:ko,onCleanup:Kr,flash:jn,setCamPos:On,getCamPos:Ln,setCamRot:Hn,getCamRot:Gn,setCamScale:Un,getCamScale:Nn,getCamTransform:To,camPos:Oo,camScale:Lo,camFlash:No,camRot:Uo,camTransform:Fo,shake:Do,toScreen:ds,toWorld:Vn,setGravity:Ho,getGravity:Go,setGravityDirection:jo,getGravityDirection:Xt,setBackground:ka,getBackground:Ia,getGamepads:u.getGamepads,getTreeRoot:Zo,add:N,make:ks,destroy:Wn,destroyAll:z,get:V,query:J,readd:j,pos:Or,scale:Lr,rotate:Cl,color:In,opacity:Tn,anchor:gs,area:pl,sprite:fs,text:tl,polygon:yo,rect:Dn,circle:ho,uvquad:rl,outline:mo,particles:wo,body:gl,platformEffector:vl,surfaceEffector:wl,areaEffector:yl,pointEffector:Al,buoyancyEffector:bl,constantForce:xl,doubleJump:ml,shader:Ao,textInput:dl,timer:ps,fixed:ei,stay:_n,health:ll,lifespan:ul,named:hl,state:cl,z:Bl,layer:Sl,move:Ml,offscreen:ql,follow:El,fadeIn:fo,mask:po,drawon:co,raycast:Fn,tile:Zn,animate:ol,serializeAnimation:$n,agent:sl,sentry:al,patrol:il,pathfinder:nl,trigger:Pu,on:qe,onFixedUpdate:ku,onUpdate:Iu,onDraw:Tu,onAdd:vo,onDestroy:Fu,onTag:bo,onUntag:Lu,onUse:Du,onUnuse:Ou,onClick:Uu,onCollide:Eo,onCollideUpdate:So,onCollideEnd:Mo,onHover:qo,onHoverUpdate:Co,onHoverEnd:Bo,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:wn,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:Ko,setVolume:Yn,getVolume:Qn,volume:Yo,burp:Kn,audioCtx:M.ctx,Line:Fe,Rect:ie,Circle:Ie,Ellipse:ot,Point:Nl,Polygon:Me,Vec2:C,Color:X,Mat4:Ze,Quad:oe,RNG:yi,rand:pe,randi:_s,randSeed:Ai,vec2:E,rgb:_,hsl2rgb:Ol,quad:he,choose:bi,chooseMultiple:vi,shuffle:en,chance:xi,lerp:Se,tween:W,easings:Ir,map:Ge,mapc:wi,wave:$s,deg2rad:ce,rad2deg:yt,clamp:je,evaluateQuadratic:Ui,evaluateQuadraticFirstDerivative:Ni,evaluateQuadraticSecondDerivative:Hi,evaluateBezier:bs,evaluateBezierFirstDerivative:Gi,evaluateBezierSecondDerivative:ji,evaluateCatmullRom:Vi,evaluateCatmullRomFirstDerivative:Ki,curveLengthApproximation:hn,normalizedCurve:Yi,hermite:xr,cardinal:cn,catmullRom:Pr,bezier:Qi,kochanekBartels:Xi,easingSteps:_i,easingLinear:Ji,easingCubicBezier:$i,testLineLine:ms,testRectRect:tn,testRectLine:ws,testRectPoint:Ur,testCirclePolygon:Hr,testLinePoint:ys,testLineCircle:Ar,isConvex:ia,triangulate:fn,NavMesh:bu,drawSprite:lo,drawText:Xs,formatText:vt,drawRect:Pe,drawLine:Kt,drawLines:Rs,drawTriangle:Rn,drawCircle:Ot,drawEllipse:Cn,drawUVQuad:yr,drawPolygon:it,drawCurve:Bn,drawBezier:ro,drawFormattedText:bt,drawMasked:oo,drawSubtracted:uo,pushTransform:Be,popTransform:Ee,pushTranslate:ae,pushScale:wr,pushRotate:It,pushMatrix:Ta,usePostEffect:O,makeCanvas:R,debug:v,scene:Jo,getSceneName:el,go:$o,onSceneLeave:_o,layers:Wo,getLayers:Xo,setLayers:zn,getDefaultLayer:zo,addLevel:xo,getData:S,setData:k,download:Ss,downloadJSON:fa,downloadText:gn,downloadBlob:js,plug:I,ASCII_CHARS:aa,canvas:u.canvas,addKaboom:Qo,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:Yr,KEvent:be,KEventHandler:kr,KEventController:Tt,cancel:a(()=>la,"cancel")};d.k=Ve;let Qr=t.plugins;if(Qr&&Qr.forEach(I),t.global!==false)for(let U in Ve)window[U]=Ve[U];return t.focus!==false&&u.canvas.focus(),Ve},"kaplay");var Wu=zu;Wu();var Qe=(t=>{t["Attack"]="Attack";t["Cooldown"]="Cooldown";t["Idle"]="Idle";t["Stunned"]="Stunned";return t})(Qe||{});var ti=(t=>{t["Background"]="Background";return t})(ti||{});var Je=(t=>{t["Game"]="Game";t["Lose"]="Lose";t["Preload"]="Preload";t["Title"]="Title";return t})(Je||{});var ke=(t=>{t["Explode"]="Explode";t["Hit"]="Hit";t["Shoot"]="Shoot";t["Whoosh"]="Whoosh";return t})(ke||{});var me=(t=>{t["Bean"]="Bean";t["Bubbie"]="Bubbie";t["Gooba"]="Gooba";t["Pokey"]="Pokey";t["Projectile"]="Projectile";t["Shellie"]="Shellie";t["Spiny"]="Spiny";return t})(me||{});var St=(t=>{t["Bullet"]="Bullet";t["Enemy"]="Enemy";t["Player"]="Player";t["Projectile"]="Projectile";return t})(St||{});function Zu(){return Boolean(randi(2))}function Ju(t,e){const r=width()/2;const s=height()/2;const n=Zu()?1:-1;return{x:t+r*n,y:e+s*n}}function Rl(t,e){return e.sub(t).unit()}const $u=200;const _u=20;function eh(t){const e=add([pos(t.pos),move(Rl(t.screenPos(),mousePos()),$u),circle(30),area(),offscreen({destroy:true}),anchor("center"),color(0,0,255),St.Bullet]);e.onCollide(St.Enemy,r=>{play(ke.Hit);e.destroy();const s=r;s.hurt(_u)});return e}const th=500;const rh=5;function sh(t,e){const r=add([sprite(me.Projectile),pos(t.pos),move(Rl(t.screenPos(),e.screenPos()),th),area(),offscreen({destroy:true}),anchor("center"),scale(.2),St.Projectile]);r.onCollide(St.Player,s=>{play(ke.Hit);r.destroy();const n=s;n.hurt(rh)});return r}let Js;function nh(){const t=add([rect(70,70),pos(50,50),anchor("center"),color(255,255,255),layer("ui"),fixed()]);const e=t.add([text("0",{size:48}),anchor("center"),color(0,0,0)]);ih(e);return e}function ih(t){Js=t}function ah(t=1){Js.text=String(parseInt(Js.text,10)+t)}const fe=Qe;function oh(t,e,r){const s=[me.Bubbie,me.Gooba,me.Pokey,me.Shellie,me.Spiny];const n=rand(100,300);const i=rand(1,10);const o=randi(20,100);const h=add([sprite(s[randi(s.length)]),pos(t,e),anchor("center"),health(o,o),opacity(1),area(),body(),scale(.75),state(fe.Attack,Object.values(fe)),St.Enemy,{damage:i,speed:n}]);h.onStateEnter(fe.Idle,async()=>{try{h.play(fe.Idle)}catch(l){}await wait(rand(0,1));h.enterState(fe.Attack)});h.onStateEnter(fe.Stunned,async()=>{try{h.play(fe.Stunned)}catch(l){}await wait(rand(0,1));h.enterState(fe.Attack)});h.onStateEnter(fe.Cooldown,async()=>{try{h.play(fe.Cooldown)}catch(l){}await wait(rand(1,3));h.enterState(fe.Attack)});h.onStateEnter(fe.Attack,async()=>{try{h.play(fe.Attack)}catch(l){}if(h.sprite===me.Pokey){sh(h,r)}});h.onStateUpdate(fe.Attack,async()=>{if(!r.exists()){return}if(h.sprite===me.Pokey&&Number(rand())<.005){return h.enterState(fe.Idle)}const l=r.pos.sub(h.pos).unit();h.move(l.scale(h.speed))});h.onCollide(St.Player,async()=>{h.enterState(fe.Cooldown);r.hurt(h.damage)});h.onHurt(()=>{h.enterState(fe.Stunned);try{h.play(fe.Stunned)}catch(l){}h.opacity=h.hp()/h.maxHP()});h.onDeath(()=>{h.enterState(fe.Stunned);ah();play(ke.Explode,{volume:.2});h.destroy();addKaboom(h.pos)});return h}const Ls=300;const gi=30;function lh(t){const e=add([rect(Ls,gi),pos(30,height()-60),color(0,0,0),fixed()]);const r=e.add([rect(Ls,gi),pos(0,0),color(255,0,0)]);function s(){r.width=t.hp()/t.maxHP()*Ls}t.onHurt(s);t.onHeal(s);return r}let zt;function Pl(){if(zt){return zt.play()}const t=play(ti.Background,{loop:true,paused:true});t.volume=.5;uh(t);Pl()}function uh(t){zt=t}function hh(){zt==null?void 0:zt.stop()}function ch(t){const e=new dh(t);onClick(()=>{if(e.canAttack()){e.update();play(ke.Shoot,{detune:rand(-100,100)});eh(t)}})}class dh{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(-$r,0);break;case"right":case"d":t.move($r,0);break;case"up":case"w":t.move(0,-$r);break;case"down":case"s":t.move(0,$r);break}})}const mi=100;function ph(t=center().x,e=center().y){const r=add([sprite(me.Bean),pos(t,e),rotate(0),anchor("center"),area(),body(),health(mi,mi),St.Player]);fh(r);ch(r);r.onUpdate(()=>{setCamPos(r.worldPos())});r.onHurt(()=>{play(ke.Hit);if(r.hp()<=0){hh();play(ke.Whoosh);go(Je.Lose)}});return r}scene(Je.Game,()=>{const t=add([rect(600,100),pos(center().x,80),anchor("center"),color(255,255,255)]);t.add([text("WASD or arrow keys to move\nLeft click to shoot"),anchor("center"),color(0,0,0)]);nh();Pl();const e=ph();lh(e);loop(5,()=>{const{x:r,y:s}=Ju(e.pos.x,e.pos.y);oh(r,s,e)})});scene(Je.Lose,()=>{const{x:t,y:e}=center();const r=100;const s=add([rect(400,100),pos(t,e-r),anchor("center"),color(255,255,255)]);s.add([text("Game Over",{size:48}),anchor("center"),color(0,0,0)]);const n=add([rect(220,80,{radius:8}),pos(t,e+r),area(),scale(1),anchor("center"),outline(4),color(255,255,255)]);n.add([text("Restart"),anchor("center"),color(0,0,0)]);n.onHover(()=>{n.scaleTo(1.1)});n.onHoverEnd(()=>{n.scaleTo(1)});n.onClick(()=>{play(ke.Hit);go(Je.Game)})});scene(Je.Preload,()=>{loadSprite(me.Shellie,"sprites/shellie.png",{sliceX:4,anims:{[Qe.Attack]:1,[Qe.Cooldown]:2,[Qe.Idle]:0,[Qe.Stunned]:3}});loadSprite(me.Pokey,"sprites/pokey.png",{sliceX:5,anims:{[Qe.Attack]:{from:0,to:1,loop:true,speed:1},[Qe.Cooldown]:2,[Qe.Idle]:3,[Qe.Stunned]:4}});const t=[[me.Bean,"sprites/bean.png"],[me.Bubbie,"sprites/bubbie.png"],[me.Gooba,"sprites/gooba.png"],[me.Projectile,"sprites/projectile.png"],[me.Spiny,"sprites/spiny.png"]];t.forEach(([s,n])=>{loadSprite(s,n)});const e=[[ke.Explode,"sounds/explode.mp3"],[ke.Hit,"sounds/hit.mp3"],[ke.Shoot,"sounds/shoot.mp3"],[ke.Whoosh,"sounds/whoosh.mp3"]];e.forEach(([s,n])=>{loadSound(s,n)});const r=[[ti.Background,"music/background.mp3"]];r.forEach(([s,n])=>{loadMusic(s,n)});go(Je.Title)});scene(Je.Title,()=>{const{x:t,y:e}=center();const r=100;const s=add([rect(400,100),pos(t,e-r),anchor("center"),color(255,255,255)]);s.add([text("Kiki & Boba",{size:48}),anchor("center"),color(0,0,0)]);const n=add([rect(220,80,{radius:8}),pos(t,e+r),area(),scale(1),anchor("center"),outline(4),color(255,255,255)]);n.add([text("Play"),anchor("center"),color(0,0,0)]);n.onHover(()=>{n.scaleTo(1.1)});n.onHoverEnd(()=>{n.scaleTo(1)});n.onClick(()=>{play(ke.Hit);go(Je.Game)})});function gh(){go(Je.Preload)}gh(); diff --git a/index.html b/index.html new file mode 100644 index 0000000..2d75b05 --- /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/music/background.mp3 b/music/background.mp3 new file mode 100644 index 0000000..eabf89d Binary files /dev/null and b/music/background.mp3 differ diff --git a/sounds/explode.mp3 b/sounds/explode.mp3 new file mode 100644 index 0000000..e0d8d6a Binary files /dev/null and b/sounds/explode.mp3 differ diff --git a/sounds/hit.mp3 b/sounds/hit.mp3 new file mode 100644 index 0000000..dc40cf2 Binary files /dev/null and b/sounds/hit.mp3 differ diff --git a/sounds/shoot.mp3 b/sounds/shoot.mp3 new file mode 100644 index 0000000..e068db0 Binary files /dev/null and b/sounds/shoot.mp3 differ diff --git a/sounds/whoosh.mp3 b/sounds/whoosh.mp3 new file mode 100644 index 0000000..e3b4c1e Binary files /dev/null and b/sounds/whoosh.mp3 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/bubbie.png b/sprites/bubbie.png new file mode 100644 index 0000000..69c0823 Binary files /dev/null and b/sprites/bubbie.png differ diff --git a/sprites/gooba.png b/sprites/gooba.png new file mode 100644 index 0000000..46d5d37 Binary files /dev/null and b/sprites/gooba.png differ diff --git a/sprites/pokey.png b/sprites/pokey.png new file mode 100644 index 0000000..5ccb8b2 Binary files /dev/null and b/sprites/pokey.png differ diff --git a/sprites/projectile.png b/sprites/projectile.png new file mode 100644 index 0000000..5835475 Binary files /dev/null and b/sprites/projectile.png differ diff --git a/sprites/shellie.png b/sprites/shellie.png new file mode 100644 index 0000000..78736e3 Binary files /dev/null and b/sprites/shellie.png differ diff --git a/sprites/spiny.png b/sprites/spiny.png new file mode 100644 index 0000000..9ff6e7a Binary files /dev/null and b/sprites/spiny.png differ