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