-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
p5play.min.js
7 lines (7 loc) · 111 KB
/
p5play.min.js
1
2
3
4
5
6
7
/**
* p5play
* @version 3.24
* @author quinton-ashley
* @license AGPL-3.0
*/
if("object"!=typeof planck){if("object"!=typeof process)throw"planck.js must be loaded before p5play";global.planck=require("./planck.min.js")}p5.prototype.registerMethod("init",(function(){const t=this,e=planck;if("object"!=typeof process&&0!=window._p5play_gtagged){let t=document.createElement("script");t.src="https://www.googletagmanager.com/gtag/js?id=G-EHXNCTSYLK",t.async=!0,document.head.append(t),window._p5play_gtagged=!0,t.onload=()=>{window.dataLayer??=[],window.gtag=function(){dataLayer.push(arguments)},gtag("js",new Date),gtag("config","G-EHXNCTSYLK"),gtag("event","p5play_v3_24")}}const i=t.DEGREES;t.angleMode(i);const s=(i,s,r)=>new e.Vec2(i*r/t.world.meterSize,s*r/t.world.meterSize),r=(i,s,r)=>new e.Vec2(i/r*t.world.meterSize,s/r*t.world.meterSize),o=e.Settings.linearSlop,h=e.Settings.angularSlop/60,a=t=>Math.abs(t)<=o,n=(t,e)=>Math.abs(t-Math.round(t))<=(e||o)?Math.round(t):t,l=(e,s)=>{let r=t._angleMode==i?360:t.TWO_PI,o=(e-s)%r,h=(r-Math.abs(o))*-Math.sign(o);return(Math.abs(o)<Math.abs(h)?o:h)||0},d={_collisions:["_collides","_colliding","_collided"],_overlappers:["_overlaps","_overlapping","_overlapped"]};this.P5Play=class{constructor(){if(this.sprites={},this.groups={},this.groupsCreated=0,this.spritesCreated=0,this.spritesDrawn=0,this.images={},this.disableImages=!1,this.palettes=[],this.friendlyRounding=!0,this.storeRemovedGroupRefs=!0,this.os={},this.context="web",window.matchMedia?this.hasMouse=!window.matchMedia("(any-hover: none)").matches:this.hasMouse=!0,this.standardizeKeyboard=!1,"object"==typeof navigator){let t=navigator.userAgent.indexOf("iPhone OS");if(t>-1){let e=navigator.userAgent.substring(t+10,t+12);this.os.platform="iOS",this.os.version=e}else{let t=navigator.userAgentData?.platform;!t&&navigator.platform&&(t=navigator.platform.slice(3),"Mac"==t?t="macOS":"Win"==t?t="Windows":"Lin"==t&&(t="Linux")),this.os.platform=t}}this.renderStats=!1,this._renderStats={x:10,y:20,font:"monospace"},this._fps=60,this._fpsArr=[60],this._collides={},this._colliding={},this._collided={},this._overlaps={},this._overlapping={},this._overlapped={}}onImageLoad(){}},this.p5play=new t.P5Play,delete t.P5Play;const p=console.log;this.log=console.log,this.Sprite=class{constructor(i,s,r,o,h){this._isSprite=!0,this.idNum;let a,l,d=[...arguments];if(void 0!==d[0]&&d[0]._isGroup&&(a=d[0],d=d.slice(1)),void 0!==d[0]&&("string"==typeof d[0]||d[0]instanceof t.Ani||d[0]instanceof p5.Image)&&(l=d[0],d=d.slice(1)),1==d.length&&"number"==typeof d[0])throw new C("Sprite",0,[d[0]]);if(Array.isArray(d[0])){if(i=void 0,s=void 0,r=d[0],o=void 0,h=d[1],Array.isArray(h))throw new C("Sprite",1,[`[[${r}], [${o}]]`])}else i=d[0],s=d[1],r=d[2],o=d[3],h=d[4];"string"==typeof r&&(h=r,r=void 0),"string"==typeof o&&(!function(t){if("d"==t||"s"==t||"k"==t||"n"==t)return!0;let e=t.slice(0,2);return"dy"==e||"st"==e||"ki"==e||"no"==e}(o)?r=_(r,o):h=o,o=void 0),this.idNum=t.p5play.spritesCreated,this._uid=1e3+this.idNum,t.p5play.sprites[this._uid]=this,t.p5play.spritesCreated++,this.groups=[],this.animations=new t.Anis,this.joints=[],this.joints.removeAll=()=>{for(;this.joints.length;)this.joints.at(-1).remove()},this.watch,this.mod={},this._removed=!1,this._life=2147483647,this._visible=!0,this._pixelPerfect=!1,this._aniChangeCount=0,this._draw=()=>this.__draw(),this._hasOverlap={},this._collisions={},this._overlappers={},a??=t.allSprites,this._tile="",this.tileSize=a.tileSize||1;let p=this;this._position={x:0,y:0},this._pos=t.createVector.call(t),Object.defineProperty(this._pos,"x",{get(){if(!p.body)return p._position.x;let e=p.body.getPosition().x/p.tileSize*t.world.meterSize;return t.p5play.friendlyRounding?n(e):e},set(i){if(p.body){let s=new e.Vec2(i*p.tileSize/t.world.meterSize,p.body.getPosition().y);p.body.setPosition(s)}p._position.x=i}}),Object.defineProperty(this._pos,"y",{get(){if(!p.body)return p._position.y;let e=p.body.getPosition().y/p.tileSize*t.world.meterSize;return t.p5play.friendlyRounding?n(e):e},set(i){if(p.body){let s=new e.Vec2(p.body.getPosition().x,i*p.tileSize/t.world.meterSize);p.body.setPosition(s)}p._position.y=i}}),this._canvasPos=t.createVector.call(t),Object.defineProperty(this._canvasPos,"x",{get(){let e=p._pos.x-t.camera.x;return"2d"==t.canvas.renderer&&(e+=t.canvas.hw/t.camera._zoom),e}}),Object.defineProperty(this._canvasPos,"y",{get(){let e=p._pos.y-t.camera.y;return"2d"==t.canvas.renderer&&(e+=t.canvas.hh/t.camera._zoom),e}}),this._velocity={x:0,y:0},this._direction=0,this._vel=t.createVector.call(t),Object.defineProperties(this._vel,{x:{get(){let e;return e=p.body?p.body.getLinearVelocity().x:p._velocity.x,e/=p.tileSize,t.p5play.friendlyRounding?n(e):e},set(t){t*=p.tileSize,p.body?p.body.setLinearVelocity(new e.Vec2(t,p.body.getLinearVelocity().y)):p._velocity.x=t,(t||this.y)&&(p._direction=this.heading())}},y:{get(){let e;return e=p.body?p.body.getLinearVelocity().y:p._velocity.y,e/=p.tileSize,t.p5play.friendlyRounding?n(e):e},set(t){t*=p.tileSize,p.body?p.body.setLinearVelocity(new e.Vec2(p.body.getLinearVelocity().x,t)):p._velocity.y=t,(t||this.x)&&(p._direction=this.heading())}}}),this._mirror={_x:1,_y:1,get x(){return this._x<0},set x(t){p.watch&&(p.mod[20]=!0),this._x=t?-1:1},get y(){return this._y<0},set y(t){p.watch&&(p.mod[20]=!0),this._y=t?-1:1}},this._heading="right",this._layer=a._layer,this._layer??=t.allSprites._getTopLayer()+1,a.dynamic&&(h??="dynamic"),a.kinematic&&(h??="kinematic"),a.static&&(h??="static"),h??=a.collider,h&&"string"==typeof h||(h="dynamic"),this.collider=h,i??=a.x,void 0===i&&(i="2d"!=t.canvas?.renderer||t._webgpuFallback?0:t.canvas.hw/this.tileSize,r&&(this._vertexMode=!0)),s??=a.y,void 0===s&&(s="2d"!=t.canvas?.renderer||t._webgpuFallback?0:t.canvas.hh/this.tileSize);let g=!1;if(void 0===r&&(r=a.w||a.width||a.d||a.diameter||a.v||a.vertices,o||a.d||a.diameter||(o=a.h||a.height,g=!0)),"function"==typeof i&&(i=i(a.length)),"function"==typeof s&&(s=s(a.length)),"function"==typeof r&&(r=r(a.length)),"function"==typeof o&&(o=o(a.length)),this.x=i,this.y=s,!a._isAllSpritesGroup&&!l){for(let t in a.animations){l=t;break}l||(l=a._img,"function"==typeof l&&(l=l(a.length)),l&&(this._img=!0))}for(let e=a;e;e=t.p5play.groups[e.parent])this.groups.push(e);if(this.groups.reverse(),l){let e=this.tileSize;this._img||l instanceof p5.Image?(this.image="string"!=typeof l?l:new t.EmojiImage(l,r),r||1==this._img.w&&1==this._img.h||(r=(this._img.defaultWidth||this._img.w)/e,o??=(this._img.defaultHeight||this._img.h)/e)):("string"==typeof l?this._changeAni(l):this._ani=l.clone(),r||1==this._ani.w&&1==this._ani.h||(r=(this._ani.defaultWidth||this._ani.w)/e,o??=(this._ani.defaultHeight||this._ani.h)/e))}if(this.groups=[],this.mouse=new t._SpriteMouse,this._rotation=0,this._rotationSpeed=0,this._bearing=0,this._scale=new u,Object.defineProperty(this._scale,"x",{get(){return this._x},set(t){if(t==this._x)return;p.watch&&(p.mod[26]=!0);let e=Math.abs(t/this._x);p._w*=e,p._hw*=e,p._resizeColliders({x:e,y:1}),this._x=t,this._avg=.5*(this._x+this._y)}}),Object.defineProperty(this._scale,"y",{get(){return this._y},set(t){if(t==this._y)return;p.watch&&(p.mod[26]=!0);let e=Math.abs(t/this._y);p._h&&(this._h*=e,this._hh*=e),p._resizeColliders({x:1,y:e}),this._y=t,this._avg=.5*(this._x+this._y)}}),this._offset={_x:0,_y:0,get x(){return this._x},set x(t){t!=this._x&&(p.watch&&(p.mod[21]=!0),p._offsetCenterBy(t-this._x,0))},get y(){return this._y},set y(t){t!=this._y&&(p.watch&&(p.mod[21]=!0),p._offsetCenterBy(0,t-this._y))}},this._massUndef=!0,void 0===r&&(this._dimensionsUndef=!0,this._widthUndef=!0,r=this.tileSize>1?1:50,void 0===o&&(this._heightUndef=!0)),g&&(o??=this.tileSize>1?1:50),this._shape=a.shape,3!=this.__collider)this._vertexMode?this.addCollider(r):this.addCollider(0,0,r,o),this.shape=this._shape;else{if(this.w=r,Array.isArray(r))throw new Error('Cannot set the collider type of a sprite with a polygon or chain shape to "none". To achieve the same effect, use .overlaps(allSprites) to have your sprite overlap with the allSprites group.');void 0!==r&&void 0===o?this.shape="circle":(this.shape="box",this.h=o)}this.prevPos={x:i,y:s},this.prevRotation=0,this._dest={x:i,y:s},this._destIdx=0,this._debug=!1,this.text,a._isAllSpritesGroup||t.allSprites.push(this),a.push(this);let f=a.vel.x||0,m=a.vel.y||0;"function"==typeof f&&(f=f(a.length-1)),"function"==typeof m&&(m=m(a.length-1)),this.vel.x=f,this.vel.y=m;let y=["ani","collider","x","y","w","h","d","diameter","dynamic","height","kinematic","static","vel","width"];for(let e of t.Sprite.propsAll){if(y.includes(e))continue;let i=a[e];void 0!==i&&("function"==typeof i&&c(i)&&(i=i(a.length-1)),"object"==typeof i?i instanceof p5.Color?this[e]=t.color(...i.levels):this[e]=Object.assign({},i):this[e]=i)}y=["add","animation","animations","autoCull","contains","GroupSprite","Group","idNum","length","mod","mouse","p","parent","Sprite","Subgroup","subgroups","velocity"];for(let e=0;e<this.groups.length;e++){let i=this.groups[e],s=Object.keys(i);for(let e of s){if(!isNaN(e)||"_"==e[0]||y.includes(e)||t.Sprite.propsAll.includes(e))continue;let s=i[e];void 0!==s&&("function"==typeof s&&c(s)&&(s=s(i.length-1)),this[e]="object"==typeof s?Object.assign({},s):s)}}{let e=t.random(.12,.96),i=t.random(.12,.96),s=t.random(.12,.96);1!=t._colorFormat&&(e*=255,i*=255,s*=255),this.color??=t.color(e,i,s)}this._textFill??=t.color(0),this._textSize??=1==this.tileSize?t.canvas?t.textSize():12:.8}addCollider(i,r,o,h){if(this._removed)return void console.error("Can't add colliders to a sprite that was removed.");3==this.__collider&&(this._collider="dynamic",this.__collider=0);let a={};a.shape=this._parseShape(...arguments),"chain"==a.shape.m_type&&(a.density=0,a.restitution=0),a.density??=this.density||5,a.friction??=this.friction||.5,a.restitution??=this.bounciness||.2,this.body?this.body.m_gravityScale||=1:(this.body=t.world.createBody({position:s(this.x,this.y,this.tileSize),type:this.collider}),this.body.sprite=this);let n=new e.Vec2(this.body.getLocalCenter());this.body.createFixture(a),this.watch&&(this.mod[19]=!0),this.body.setMassData({mass:this.body.getMass(),center:n,I:this.body.getInertia()})}addSensor(e,i,r,o){if(this._removed)return void console.error("Can't add sensors to a sprite that was removed.");let h=this._parseShape(...arguments);this.body||(this.body=t.world.createBody({position:s(this.x,this.y,this.tileSize),type:"dynamic",gravityScale:0}),this.body.sprite=this,this.mass=0,this._massUndef=!0,this.rotation=this._rotation,this.vel=this._velocity),this.body.createFixture({shape:h,isSensor:!0}),this._sortFixtures(),this._hasSensors=!0}_parseShape(i,r,o,h){let n,l,d,p,u=[...arguments];if(0==u.length?(i=0,r=0,o=this._w,h=this._h):u.length<=2&&(i=0,r=0,o=u[0],h=u[1],this._vertexMode=!0),Array.isArray(o)||"string"==typeof h?(isNaN(o)||(o=Number(o)),"number"!=typeof o&&Array.isArray(o[0])&&(this._originMode??="start"),"string"==typeof h?(n=_(o,h),h=void 0):n=o):(l=void 0!==o&&void 0===h?"circle":"box",o??=this.tileSize>1?1:50,h??=o,d=s(o-.08,h-.08,this.tileSize)),"box"==l)p=e.Box(d.x/2,d.y/2,s(i,r,this.tileSize),0);else if("circle"==l)p=e.Circle(s(i,r,this.tileSize),d.x/2);else if(n){let c,g,f=[{x:0,y:0}],m={x:0,y:0},y={x:0,y:0},w={x:0,y:0},v=Array.isArray(n[0]);function x(){m.x<y.x&&(y.x=m.x),m.y<y.y&&(y.y=m.y),m.x>w.x&&(w.x=m.x),m.y>w.y&&(w.y=m.y)}if(v){this._vertexMode&&(c=n[0][0],g=n[0][1],this.fixture&&this._relativeOrigin?(c=this.x-this._relativeOrigin.x,g=this.y-this._relativeOrigin.y,f.pop()):(this.x=c,this.y=g));for(let S=0;S<n.length;S++){if(this._vertexMode){if(0==S&&!this.fixture)continue;m.x=n[S][0]-c,m.y=n[S][1]-g}else m.x+=n[S][0],m.y+=n[S][1];f.push({x:m.x,y:m.y}),x()}}else{let A=1;n.length%2&&(A=n[n.length-1]);let C=A>0?1:-1;A=Math.abs(A);let k=0;for(let M=0;M<A;M++){for(let z=0;z<n.length-1;z+=2){let T=n[z];k+=n[z+1],m.x+=T*t.cos(k),m.y+=T*t.sin(k),f.push({x:m.x,y:m.y}),x()}k*=C}}let b=!1;if(a(Math.abs(f[0].x)-Math.abs(f[f.length-1].x))&&a(Math.abs(f[0].y)-Math.abs(f[f.length-1].y))?(l="chain"!=this._shape?"polygon":"chain",this._originMode="center",this._isConvexPoly(f.slice(0,-1))&&(b=!0)):l="chain",o=w.x-y.x,h=w.y-y.y,"start"==this._originMode)for(let j=0;j<f.length;j++)f[j]=s(f[j].x,f[j].y,this.tileSize);else{let O=0,P=0,F=0,I=0,D=f.length;("polygon"==l||b)&&D--;for(let L=0;L<D;L++)F+=f[L].x,I+=f[L].y;O=F/D,P=I/D,this.fixture||(this._relativeOrigin={x:O,y:P}),this._vertexMode&&v&&(this.fixture?(O=this._relativeOrigin.x,P=this._relativeOrigin.y):(this.x+=O,this.y+=P));for(let B=0;B<f.length;B++){let W=f[B];f[B]=s(W.x+i-O,W.y+r-P,this.tileSize)}}(!b||f.length-1>e.Settings.maxPolygonVertices||"chain"==this._shape)&&(l="chain"),"polygon"==l?p=e.Polygon(f):"chain"==l&&(p=e.Chain(f,!1))}if(this.shape??=l,this.fixtureList){this._extents??={t:this.hh,b:this.hh,l:this._hw,r:this._hw};let G=this._extents,N=i-.5*o,E=i+.5*o,R=r-.5*h,U=r+.5*h;N<G.l&&(G.l=N),E>G.r&&(G.r=E),R<G.t&&(G.t=R),U>G.b&&(G.b=U),this._totalWidth=G.r-G.l,this._totalHeight=G.b-G.t;let V=Math.abs;this._largestExtent=Math.max(V(G.l),V(G.r),V(G.t),V(G.b))}else this._w=o,this._hw=.5*o,1!=this.__shape&&(this._h=h,this._hh=.5*h);return p}removeColliders(){this.body&&(this._removeContacts(0),this._removeFixtures(0))}removeSensors(){this.body&&(this._removeContacts(1),this._removeFixtures(1),this._hasSensors=!1)}_removeFixtures(e){let i;for(let s=this.fixtureList;s;s=s.getNext())if(void 0===e||s.m_isSensor==e){let e=s.m_next;s.destroyProxies(t.world.m_broadPhase),i?i.m_next=e:this.body.m_fixtureList=e}else i=s}_removeContacts(e){if(!this.body)return;let i=this.body.m_contactList;for(;i;){let s=i.contact;i=i.next,void 0!==e&&s.m_fixtureA.m_isSensor!=e||t.world.destroyContact(s)}}_offsetCenterBy(t,e){if(!t&&!e)return;if(this._offset._x+=t,this._offset._y+=e,!this.body)return;let i=s(t,e,this.tileSize);this.__offsetCenterBy(i.x,i.y)}__offsetCenterBy(t,e){for(let i=this.body.m_fixtureList;i;i=i.m_next){let s=i.m_shape;if("circle"!=s.m_type){let i=s.m_vertices;for(let s of i)s.x+=t,s.y+=e}else s.m_p.x+=t,s.m_p.y+=e}}_cloneBodyProps(){let t={},e=["bounciness","density","drag","friction","heading","isSuperFast","rotation","rotationDrag","rotationLock","rotationSpeed","scale","vel","x","y"];this._massUndef&&this._dimensionsUndef||e.push("mass");for(let i of e)"object"==typeof this[i]?t[i]=Object.assign({},this[i]):t[i]=this[i];return t}get animation(){return this._ani}set animation(t){this.changeAni(t)}get ani(){return this._ani}set ani(t){this.changeAni(t)}get anis(){return this.animations}get autoDraw(){return this._autoDraw}set autoDraw(t){this._autoDraw=t}get allowSleeping(){return this.body?.isSleepingAllowed()}set allowSleeping(t){this.watch&&(this.mod[5]=!0),this.body&&this.body.setSleepingAllowed(t)}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){this._autoUpdate=t}get bounciness(){if(this.fixture)return this.fixture.getRestitution()}set bounciness(t){this.watch&&(this.mod[7]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setRestitution(t)}get collider(){return this._collider}set collider(e){if(e==this._collider)return;let i=(e=e.toLowerCase())[0];if("d"==i&&(e="dynamic"),"s"==i&&(e="static"),"k"==i&&(e="kinematic"),"n"==i&&(e="none"),e==this._collider)return;if("none"==e&&("chain"==this._shape||"polygon"==this._shape))return void console.error('Cannot set the collider type of a polygon or chain collider to "none". To achieve the same effect, use .overlaps(allSprites) to have your sprite overlap with the allSprites group.');if(this._removed)throw new Error("Cannot change the collider type of a sprite that was removed.");let s=this.__collider;this._collider=e,this.__collider=["d","s","k","n"].indexOf(i),this.watch&&(this.mod[8]=!0),void 0!==s&&(3!=this.__collider?(this.body&&this.body.setType(e),3==s&&(this.addCollider(),this.x=this._position.x,this.y=this._position.y,this.vel.x=this._velocity.x,this.vel.y=this._velocity.y,this.rotation=this._rotation,this.rotationSpeed=this._rotationSpeed)):(this.removeColliders(),this.fixture?.m_isSensor?this.body.m_gravityScale=0:(this._position.x=this.x,this._position.y=this.y,this._velocity.x=this.vel.x,this._velocity.y=this.vel.y,this._rotation=this.rotation,this._rotationSpeed=this.rotationSpeed,t.world.destroyBody(this.body),this.body=null)))}_parseColor(e){return e instanceof p5.Color?e:"object"!=typeof e?1==e.length?t.colorPal(e):t.color(e):t.color(...e.levels)}get color(){return this._color}set color(t){this.watch&&(this.mod[9]=!0),this._color=this._parseColor(t)}get colour(){return this._color}set colour(t){this.color=t}get fill(){return this._color}set fill(t){this.color=t}get fillColor(){return this._color}set fillColor(t){this.color=t}get stroke(){return this._stroke}set stroke(t){this.watch&&(this.mod[29]=!0),this._stroke=this._parseColor(t)}get strokeColor(){return this._stroke}set strokeColor(t){this.stroke=t}get strokeWeight(){return this._strokeWeight}set strokeWeight(t){this.watch&&(this.mod[30]=!0),this._strokeWeight=t}get textColor(){return this._textFill}set textColor(t){this.watch&&(this.mod[32]=!0),this._textFill=this._parseColor(t)}get textColour(){return this._textFill}set textColour(t){this.textColor=t}get textFill(){return this._textFill}set textFill(t){this.textColor=t}get textSize(){return this._textSize}set textSize(t){this.watch&&(this.mod[33]=!0),this._textSize=t}get textStroke(){return this._textStroke}set textStroke(t){this.watch&&(this.mod[34]=!0),this._textStroke=this._parseColor(t)}get textStrokeWeight(){return this._textStrokeWeight}set textStrokeWeight(t){this.watch&&(this.mod[35]=!0),this._textStrokeWeight=t}get tile(){return this._tile}set tile(t){this.watch&&(this.mod[36]=!0),this._tile=t}get tileSize(){return this._tileSize}set tileSize(t){this.watch&&(this.mod[37]=!0),this._tileSize=t}get bearing(){return this._bearing}set bearing(t){this.watch&&(this.mod[6]=!0),this._bearing=t}get debug(){return this._debug}set debug(t){this.watch&&(this.mod[10]=!0),this._debug=t}get density(){if(this.fixture)return this.fixture.getDensity()}set density(t){this.watch&&(this.mod[11]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setDensity(t)}_getDirectionAngle(e){e=e.toLowerCase().replaceAll(/[ _-]/g,"");let i={up:-90,down:90,left:180,right:0,upright:-45,rightup:-45,upleft:-135,leftup:-135,downright:45,rightdown:45,downleft:135,leftdown:135,forward:this.rotation,backward:this.rotation+180}[e];return"radians"==t._angleMode&&(i=t.radians(i)),i}get direction(){return 0!==this.vel.x||0!==this.vel.y?t.atan2(this.vel.y,this.vel.x):this._isTurtleSprite?this.rotation:this._direction}set direction(e){this.watch&&(this.mod[12]=!0),"string"==typeof e&&(this._heading=e,e=this._getDirectionAngle(e)),this._direction=e,this._isTurtleSprite&&(this.rotation=e);let i=this.speed;this.vel.x=t.cos(e)*i,this.vel.y=t.sin(e)*i}get drag(){return this.body?.getLinearDamping()}set drag(t){this.watch&&(this.mod[13]=!0),this.body&&this.body.setLinearDamping(t)}get draw(){return this._display}set draw(t){this._userDefinedDraw=!0,this._draw=t}get dynamic(){return this.body?.isDynamic()}set dynamic(t){this.collider=t?"dynamic":"kinematic"}get fixture(){return this.fixtureList}get fixtureList(){return this.body?this.body.m_fixtureList:null}get friction(){if(this.fixture)return this.fixture.getFriction()}set friction(t){this.watch&&(this.mod[14]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setFriction(t)}get heading(){return this._heading}set heading(t){this.direction=t}get img(){return this._img||this._ani?.frameImage}set img(t){this.image=t}get image(){return this._img||this._ani?.frameImage}set image(e){"string"==typeof e&&(e=e.includes(".")?t.loadImage(e):new t.EmojiImage(e,this.w)),this._img=this._extendImage(e)}_extendImage(t){return t.offset??={x:0,y:0},t._scale??={x:1,y:1},t.scale||Object.defineProperty(t,"scale",{get:()=>t._scale,set:e=>{"number"==typeof e&&(e={x:e,y:e}),t._scale=e}}),t}get isMoving(){return 0!=this.vel.x||0!=this.vel.y}get isSuperFast(){return this.body?.isBullet()}set isSuperFast(t){this.watch&&(this.mod[16]=!0),this.body&&this.body.setBullet(t)}get kinematic(){return this.body?.isKinematic()}set kinematic(t){this.collider=t?"kinematic":"dynamic"}get layer(){return this._layer}set layer(t){this.watch&&(this.mod[17]=!0),this._layer=t}get life(){return this._life}set life(t){this.watch&&(this.mod[18]=!0),this._life=t}get mass(){return this.body?.getMass()}set mass(t){if(!this.body)return;this.watch&&(this.mod[19]=!0);const i={I:0,center:new e.Vec2(this.body.getLocalCenter()),mass:0};this.body.getMassData(i),i.mass=t>0?t:1e-8,this.body.setMassData(i),delete this._massUndef}resetMass(){if(!this.body)return;let t=new e.Vec2(this.body.getLocalCenter());this.watch&&(this.mod[19]=!0),this.body.resetMassData(),this.body.setMassData({mass:this.body.getMass(),center:t,I:this.body.getInertia()})}resetCenterOfMass(){this.watch&&(this.mod[19]=!0),this.body.resetMassData();let{x:t,y:e}=this.body.getLocalCenter();if(0==t&&0==e)return;this.__offsetCenterBy(-t,-e),this.body.resetMassData();let i=this.body.getPosition();this.body.setPosition({x:i.x+t,y:i.y+e})}get mirror(){return this._mirror}set mirror(t){this.watch&&(this.mod[20]=!0),void 0!==t.x&&(this._mirror.x=t.x),void 0!==t.y&&(this._mirror.y=t.y)}get offset(){return this._offset}set offset(t){t.x??=this._offset._x,t.y??=this._offset._y,t.x==this._offset._x&&t.y==this._offset._y||(this.watch&&(this.mod[21]=!0),this._offsetCenterBy(t.x-this._offset._x,t.y-this._offset._y))}get opacity(){return this._opacity??1}set opacity(t){this.watch&&(this.mod[41]=!0),this._opacity=t}get previousPosition(){return this.prevPos}set previousPosition(t){this.prevPos=t}get previousRotation(){return this.prevRotation}set previousRotation(t){this.prevRotation=t}get pixelPerfect(){return this._pixelPerfect}set pixelPerfect(t){this.watch&&(this.mod[22]=!0),this._pixelPerfect=t}get removed(){return this._removed}set removed(t){t&&!this._removed&&(this.watch&&(this.mod[23]=!0),this._removed=!0,this._remove())}get rotation(){if(!this.body)return this._rotation||0;let e=this.body.getAngle();return e=t.p5play.friendlyRounding?n(e,h):e,t._angleMode==i&&(e=t.degrees(e)),e}set rotation(e){this.body?(t._angleMode==i&&(e=t.radians(e%360)),this.body.setAngle(e),this.body.synchronizeTransform()):this._rotation=e}get rotationDrag(){return this.body?.getAngularDamping()}set rotationDrag(t){this.body&&(this.watch&&(this.mod[24]=!0),this.body.setAngularDamping(t))}get rotationLock(){return this.body?.isFixedRotation()}set rotationLock(t){if(!this.body)return;this.watch&&(this.mod[25]=!0);let e=this.mass;this.body.setFixedRotation(t),this.mass=e}get rotationSpeed(){if(this.body){let e=this.body.getAngularVelocity()/60;return t._angleMode==i?t.degrees(e):e}return this._rotationSpeed}set rotationSpeed(e){this.body?(e*=60,t._angleMode==i&&(e=t.radians(e)),this.body.setAngularVelocity(e)):this._rotationSpeed=e}get scale(){return this._scale}set scale(t){if(0==t&&(t=.01),"number"==typeof t?t={x:t,y:t}:(t.x??=this._scale._x,t.y??=this._scale._y),t.x==this._scale._x&&t.y==this._scale._y)return;this.watch&&(this.mod[26]=!0);let e={x:Math.abs(t.x/this._scale._x),y:Math.abs(t.y/this._scale._y)};this._w*=e.x,this._hw*=e.x,this._h&&(this._h*=e.y,this._hh*=e.y),this._resizeColliders(e),this._scale._x=t.x,this._scale._y=t.y,this._scale._avg=t.x}get sleeping(){if(this.body)return!this.body.isAwake()}set sleeping(t){this.body&&(this.watch&&(this.mod[28]=!0),this.body.setAwake(!t))}get speed(){return t.createVector(this.vel.x,this.vel.y).mag()}set speed(e){let i=this.direction;this.vel.x=t.cos(i)*e,this.vel.y=t.sin(i)*e}get static(){return this.body?.isStatic()}set static(t){this.collider=t?"static":"dynamic"}get tint(){return this._tint}set tint(t){this.watch&&(this.mod[38]=!0),this._tint=this._parseColor(t)}get tintColor(){return this._tint}set tintColor(t){this.tint=t}set vertices(t){if(3==this.__collider)throw new Error('Cannot set vertices of a sprite with collider type of "none".');this.watch&&(this.mod[27]=!0),this._removeFixtures(),this._originMode="start",this.addCollider(t),this._hasSensors&&this.addDefaultSensors()}get vertices(){return this._getVertices()}_getVertices(e){let i=this.fixture.getShape(),s=[...i.m_vertices];"polygon"==i.m_type&&s.unshift(s.at(-1));let r=this.x,o=this.y;for(let i=0;i<s.length;i++){let h=[s[i].x/this.tileSize*t.world.meterSize+r,s[i].y/this.tileSize*t.world.meterSize+o];t.p5play.friendlyRounding&&(h[0]=n(h[0]),h[1]=n(h[1])),s[i]=e?h:t.createVector(h[0],h[1])}return s}get visible(){return this._visible}set visible(t){this.watch&&(this.mod[39]=!0),this._visible=t}get x(){return this._pos.x}set x(t){this._pos.x=t}get y(){return this._pos.y}set y(t){this._pos.y=t}get pos(){return this._pos}set pos(i){if(this.body){let s=new e.Vec2(i.x*this.tileSize/t.world.meterSize,i.y*this.tileSize/t.world.meterSize);this.body.setPosition(s)}this._position.x=i.x,this._position.y=i.y}get position(){return this._pos}set position(t){this.pos=t}get canvasPos(){return this._canvasPos}get w(){return this._w}set w(t){if(t<0&&(t=.01),t==this._w)return;this.watch&&(this.mod[40]=!0);let e=t/this._w;this._w=t,this._hw=.5*t,this._resizeColliders({x:e,y:1}),delete this._widthUndef,delete this._dimensionsUndef}get hw(){return this._hw}set hw(t){throw new C("Sprite.hw")}get width(){return this._w}set width(t){this.w=t}get halfWidth(){return this.hw}set halfWidth(t){throw new C("Sprite.hw")}get h(){return this._h||this._w}set h(t){if(t<0&&(t=.01),1==this.__shape)return void(this.w=t);if(t==this._h)return;this.watch&&(this.mod[15]=!0);let e=t/this._h;this._h=t,this._hh=.5*t,this._resizeColliders({x:1,y:e}),delete this._heightUndef,delete this._dimensionsUndef}get hh(){return this._hh||this._hw}set hh(t){throw new C("Sprite.hh")}get height(){return this.h}set height(t){this.h=t}get halfHeight(){return this.hh}set halfHeight(t){throw new C("Sprite.hh")}get d(){return this._w}set d(t){t<0&&(t=.01);let e=1!=this.__shape;if(e||this._w!=t){if(this.watch&&(this.mod[40]=!0),!e){let e=t/this._w;this._resizeColliders({x:e,y:e})}this._w=t,this._hw=.5*t,e&&(this.shape="circle")}}get diameter(){return this._w}set diameter(t){this.d=t}get r(){return this._hw}set r(t){this.d=2*t}get radius(){return this._hw}set radius(t){this.d=2*t}_resizeColliders(t){if(this.body){for(let e=this.fixtureList;e;e=e.getNext()){if(e.m_isSensor)continue;let i=e.m_shape;if("circle"==i.m_type)1!=t.x?i.m_radius*=t.x:i.m_radius*=t.y;else for(let e of i.m_vertices)e.x*=t.x,e.y*=t.y}(this._widthUndef||this._heightUndef)&&this.resetMass(),this.body.synchronizeFixtures()}}_isConvexPoly(t){t:for(let i=0;i<2;i++){1==i&&(t=t.reverse());for(let s=0;s<t.length;++s){const r=s,o=s<t.length-1?r+1:0,h=t[r],a=e.Vec2.sub(t[o],h);for(let s=0;s<t.length;++s){if(s==r||s==o)continue;const n=e.Vec2.sub(t[s],h);if(e.Vec2.cross(a,n)<0){if(0==i)continue t;return!1}}}break}return!0}get shape(){return this._shape}set shape(e){if(e==this._shape)return;let i=t.Sprite.shapeTypes.indexOf(e);if(-1==i)throw new Error('Invalid shape type: "'+e+'"\nThe valid shape types are: "'+t.Sprite.shapeTypes.join('", "')+'"');if(3==this.__collider&&i>=2)return void console.error('Cannot set the collider shape to chain or polygon if the sprite has a collider type of "none". To achieve the same effect, use .overlaps(allSprites) to have your sprite overlap with the allSprites group.');let s,r,o=this.__shape;if(this.__shape=i,this._shape=e,this.watch&&(this.mod[27]=!0),void 0===o)return;if(0==this.__shape?(this._h=this._w,this._hh=this._hw):(this._h=void 0,this._hh=void 0),1!=o&&1!=this.__shape?s=this._getVertices(!0):r=this._w,this._removeFixtures(),3!=this.__collider)if(s)this._originMode??="center",this.addCollider(s);else if(1==o){let t=this._w*Math.sin(Math.PI/12);this.addCollider(0,0,[t,-30,12])}else this.addCollider();this._hasSensors&&this.addDefaultSensors();let h=this._offset._x,a=this._offset._y;(h||a)&&(this._offset._x=0,this._offset._y=0,this._offsetCenterBy(h,a))}get update(){return this._update}set update(t){this._customUpdate=t}get vel(){return this._vel}set vel(t){this.vel.x=t.x,this.vel.y=t.y}get velocity(){return this._vel}set velocity(t){this.vel=t}get gravityScale(){return this.body?.getGravityScale()}set gravityScale(t){this.body&&(this.watch&&(this.mod[42]=!0),this.body.setGravityScale(t))}_update(){this._ani?.update&&this._ani.update();for(let t in this.mouse)-1==this.mouse[t]&&(this.mouse[t]=0);this._customUpdate&&this._customUpdate(),this.autoUpdate&&(this.autoUpdate=null)}_step(){this.life-=t.world.timeScale,2147483647!=this._life&&this._life<=0&&this.remove(),this.body||this._removed||(this.rotation+=this._rotationSpeed,this.x+=this.vel.x,this.y+=this.vel.y),this.watch&&(this.x!=this.prevX&&(this.mod[0]=this.mod[2]=!0),this.y!=this.prevY&&(this.mod[1]=this.mod[2]=!0),this.rotation!=this.prevRotation&&(this.mod[3]=this.mod[4]=!0)),(this.body||this._removed)&&this.__step()}__step(){let e,i=this;for(let s in d)for(let r in this[s]){if(r>=1e3){if(i._isGroup||i._uid>=r)continue;e=t.p5play.sprites[r]}else{if(i._isGroup&&i._uid>=r)continue;e=t.p5play.groups[r]}let o=i[s][r]+1;e&&0!=o&&-2!=o?(this[s][r]=o,e[s][i._uid]=o):(delete i[s][r],e&&delete e[s][i._uid])}}___step(){let e,i,s,r,o=this,h=!0;for(let a in d){for(let n in this[a]){if(n>=1e3){if(o._isGroup||o._uid>=n)continue;e=t.p5play.sprites[n]}else{if(o._isGroup&&o._uid>=n)continue;e=t.p5play.groups[n]}if(o._isGroup||e?._isGroup)continue;if(s=o._hasOverlap[e._uid]??e._hasOverlap[o._uid],h&&!1!==s||!h&&!0!==s)continue;let l=o[a][n];for(let s=0;s<3;s++){if(0==s&&1!=l&&-3!=l)continue;if(1==s&&-1==l)continue;if(2==s&&l>=1)continue;i=d[a][s];let h=t.p5play[i][o._uid];if(h){r=h[e._uid],r&&r.call(o,o,e,l);for(let t of e.groups)r=h[t._uid],r&&r.call(o,o,e,l)}let n=t.p5play[i][e._uid];if(n){r=n[o._uid],r&&r.call(e,e,o,l);for(let t of o.groups)r=n[t._uid],!r||h&&r==h[t._uid]||r.call(e,e,o,l)}}}h=!1}if(this._removed&&0==Object.keys(this._collisions).length&&0==Object.keys(this._overlappers).length){this._isSprite?delete t.p5play.sprites[this._uid]:t.p5play.storeRemovedGroupRefs||delete t.p5play.groups[this._uid];for(let e in d)for(let i of d[e])delete t.p5play[i][this._uid]}}__draw(){if(!t.p5play.disableImages)if(this._ani)this._ani.draw(this._offset._x,this._offset._y,0,this._scale._x,this._scale._y);else if(this._img){let e=this._img,i=1!=this._scale._x||1!=this._scale._y||1!=e.scale.x||1!=e.scale.y;i&&(t.push(),t.scale(this._scale._x*e.scale.x,this._scale._y*e.scale.y)),t.image(e,this._offset._x+e.offset.x,this._offset._y+e.offset.y),i&&t.pop()}if(!this._ani&&!this._img||this.debug||t.p5play.disableImages)if(this.debug&&(t.noFill(),t.stroke(0,255,0),t.line(0,-2,0,2),t.line(-2,0,2,0)),3!=this.__collider){this.debug||0===this._strokeWeight?t.noStroke():2==this.__shape?t.stroke(this.stroke||this.color):this._stroke&&t.stroke(this._stroke);for(let e=this.fixtureList;e;e=e.getNext()){if(this.debug)e.m_isSensor?t.stroke(255,255,0,127):t.stroke(0,255,0,127);else if(e.m_isSensor)continue;this._drawFixture(e)}}else 0!==this._strokeWeight&&t.stroke(this._stroke||120),0==this.__shape?t.rect(this._offset._x,this._offset._y,this.w*this.tileSize,this.h*this.tileSize):1==this.__shape&&t.circle(this._offset._x,this._offset._y,this.d*this.tileSize);void 0!==this.text&&(t.textAlign(t.CENTER,t.CENTER),t.fill(this._textFill),this._textStrokeWeight&&t.strokeWeight(this._textStrokeWeight),this._textStroke?t.stroke(this._textStroke):t.noStroke(),t.textSize(this.textSize*this.tileSize),t.text(this.text,0,0))}_display(){let e,i=this.x*this.tileSize+t.world.origin.x,s=this.y*this.tileSize+t.world.origin.y;if(!this._userDefinedDraw){let e;if(e=this._totalWidth?Math.max(this._totalWidth,this._totalHeight):void 0!==this._h?Math.max(this._w,this._h):this._w,this.ani&&!t.p5play.disableImages&&(e=Math.max(e,this.ani.w,this.ani.h)),"chain"!=this.shape&&t.camera.isActive&&(i+e<t.camera.bound.min.x||i-e>t.camera.bound.max.x||s+e<t.camera.bound.min.y||s-e>t.camera.bound.max.y))return void(this._visible=null)}if(this._visible=!0,t.p5play.spritesDrawn++,this._pixelPerfect){let e,r;this.ani&&this.ani.length&&!t.p5play.disableImages?(e=this.ani[this.ani._frame].w,r=this.ani[this.ani._frame].h):(e=this._w,r=this._h),i=e%2==0?Math.round(i):Math.round(i-.5)+.5,s=r%2==0?Math.round(s):Math.round(s-.5)+.5}else i=n(i),s=n(s);for(let t of this.joints)t.visible?this._uid==t.spriteA._uid?(!t.spriteB._visible||this.layer<=t.spriteB.layer)&&t._display():(!t.spriteA._visible||this.layer<t.spriteA.layer)&&t._display():t.visible??=!0;0!=this._opacity&&(t.push(),t.imageMode("center"),t.rectMode("center"),t.ellipseMode("center"),t.translate(i,s),this.rotation&&t.rotate(this.rotation),1==this._mirror._x&&1==this._mirror._y||t.scale(this._mirror._x,this._mirror._y),t.fill(this.color),void 0!==this._strokeWeight&&t.strokeWeight(this._strokeWeight),this._opacity&&(e=t.ctx.globalAlpha,t.ctx.globalAlpha=this._opacity),this._tint&&t.tint(this._tint),this._draw(),t.pop(),this._opacity&&(t.ctx.globalAlpha=e),this._cameraActiveWhenDrawn=t.camera.isActive,t.camera.isActive||(t.camera._wasOff=!0),this.autoDraw&&(this.autoDraw=null))}_drawFixture(e){const i=e.m_shape;if("polygon"==i.m_type||"chain"==i.m_type){if("chain"==i.m_type){if(0==t._strokeWeight)return;t.push(),t.noFill()}let e=i.m_vertices;t.beginShape();for(let i=0;i<e.length;i++)t.vertex(e[i].x*t.world.meterSize,e[i].y*t.world.meterSize);"chain"!=i.m_type?t.endShape("close"):(t.endShape(),t.pop())}else if("circle"==i.m_type){const e=2*i.m_radius*t.world.meterSize;t.ellipse(i.m_p.x*t.world.meterSize,i.m_p.y*t.world.meterSize,e,e)}else"edge"==i.m_type&&t.line(i.m_vertex1.x*t.world.meterSize,i.m_vertex1.y*t.world.meterSize,i.m_vertex2.x*t.world.meterSize,i.m_vertex2.y*t.world.meterSize)}_args2Vec(t,e){return Array.isArray(t)?{x:t[0],y:t[1]}:("object"==typeof t&&(e=t.y,t=t.x),{x:t||0,y:e||0})}_parseForceArgs(){let i=arguments;"number"!=typeof i[0]||1!=i.length&&"number"==typeof i[1]?2==i.length&&"number"!=typeof i[1]&&(i[2]=i[1],i[1]=void 0):(i[3]=i[2],i[2]=i[1],i[1]=t.sin(this._bearing)*i[0],i[0]=t.cos(this._bearing)*i[0]);let r={};return r.forceVector=new e.Vec2(this._args2Vec(i[0],i[1])),void 0!==i[2]&&(r.poa=this._args2Vec(i[2],i[3]),r.poa=s(r.poa.x,r.poa.y,this.tileSize)),r}applyForce(t,e){if(!this.body)return;if("game.thegamebox.ca"==location.host)return this.applyForceScaled(...arguments);let{forceVector:i,poa:s}=this._parseForceArgs(...arguments);s?this.body.applyForce(i,s):this.body.applyForceToCenter(i)}applyForceScaled(t,e){if(!this.body)return;let{forceVector:i,poa:s}=this._parseForceArgs(...arguments);i.mul(this.mass),s?this.body.applyForce(i,s):this.body.applyForceToCenter(i)}attractTo(i,s,r,o,h){if(!this.body||0!=this.__collider)return void console.error("attractTo can only be used on sprites with dynamic colliders");if("number"!=typeof i){let e=i;if(!e||e==t.mouse&&!t.mouse.isActive)return;r=s,s=e.y,i=e.x}if(this.x==i&&this.y==s)return;let a=s-this.y,n=i-this.x,l=r/Math.sqrt(a*a+n*n),d=new e.Vec2(n*l,a*l);this.body.applyForceToCenter(d)}repelFrom(e,i,s,r,o){if(this.body&&0==this.__collider){if("number"!=typeof e){let r=e;if(!r||r==t.mouse&&!t.mouse.isActive)return;s=i,i=r.y,e=r.x}this.attractTo(e,i,-s,r,o)}else console.error("repelFrom can only be used on sprites with dynamic colliders")}applyTorque(t){this.body&&this.body.applyTorque(t)}moveTowards(e,i,s){if(void 0!==e){if("number"!=typeof e&&null!==e){let r=e;if(r==t.mouse&&!t.mouse.isActive)return;if(!r||void 0===r.x||void 0===r.y)throw"sprite.moveTowards/moveAway ERROR: movement destination not defined.";s=i,i=r.y,e=r.x}if(s??=.1,null!=e){let t=e-this.x;a(t)?this.vel.x=0:this.vel.x=t*s*this.tileSize}if(null!=i){let t=i-this.y;a(t)?this.vel.y=0:this.vel.y=t*s*this.tileSize}}}moveAway(t,e,i){this.moveTowards(...arguments),this.vel.x*=-1,this.vel.y*=-1}move(e,i,s){if(!e)return Promise.resolve(!1);let r=isNaN(arguments[0]);r&&(e=1,i=arguments[0],s=arguments[1]),"string"==typeof i&&(r=!0,this._heading=i,i=this._getDirectionAngle(i)),i??=this.direction;let o=t.cos(i)*e,h=t.sin(i)*e;return 1==this.tileSize||!r&&i%90!=0||e%.5!=0?(o+=this.x,h+=this.y,i%45==0&&(o=n(o),h=n(h))):(o=Math.round(2*(this.x+Math.round(o)))/2,h=Math.round(2*(this.y+Math.round(h)))/2),this.moveTo(o,h,s)}moveTo(e,i,s){if("number"!=typeof e&&e){let r=e;if(r==t.mouse&&!t.mouse.isActive)return;if(!r||void 0===r.x||void 0===r.y)throw"sprite.moveTo ERROR: destination not defined.";s=i,i=r.y,e=r.x}if(null!=e&&e!=this.x?(this._dest.x=e,e=!0):(this._dest.x=this.x,e=!1),null!=i&&i!=this.y?(this._dest.y=i,i=!0):(this._dest.y=this.y,i=!1),this._destIdx++,!e&&!i)return Promise.resolve(!0);if(s??=this.speed||(this.tileSize<=1?1:.1),s<=0)return console.warn("sprite.move: speed should be a positive number"),Promise.resolve(!1);let r=this._dest.y-this.y,o=this._dest.x-this.x,h=s/Math.sqrt(r*r+o*o);this.vel.x=o*h,this.vel.y=r*h;let a=this.direction<0?this.direction+360:this.direction,n=a-.1,l=a+.1,d=t.world.velocityThreshold;d=Math.min(d,.1*s);let p=.51*s,u=e&&i,c=this._destIdx;return(async()=>{let s,r;do{if(await t.sleep(),c!=this._destIdx)return!1;let o=this.direction<0?this.direction+360:this.direction;if(u&&(o<=n||o>=l)||Math.abs(this.vel.x)<=d&&Math.abs(this.vel.y)<=d)return!1;e&&(s=this.vel.x>0?this._dest.x-this.x:this.x-this._dest.x),i&&(r=this.vel.y>0?this._dest.y-this.y:this.y-this._dest.y)}while(e&&s>p||i&&r>p);return this.x=this._dest.x,this.y=this._dest.y,this.vel.x=0,this.vel.y=0,!0})()}rotateTowards(t,e){if(1==this.__collider)return void new C(0);let i,s,r,o=arguments;"number"!=typeof o[0]?(i=o[0].x,s=o[0].y,e=o[1],r=o[2]):arguments.length>2&&(i=o[0],s=o[1],e=o[2],r=o[3]),void 0!==i?t=this.angleToFace(i,s,r):t-=this.rotation,e??=.1,this.rotationSpeed=t*e}angleTo(e,i){if("object"==typeof e){let s=e;if(s==t.mouse&&!t.mouse.isActive)return 0;if(void 0===s.x||void 0===s.y)return console.error("sprite.angleTo ERROR: rotation destination not defined, object given with no x or y properties"),0;i=s.y,e=s.x}return t.atan2(i-this.y,e-this.x)}rotationToFace(t,e,i){return"object"==typeof t&&(i=e,e=t.y,t=t.x),Math.abs(t-this.x)<.01&&Math.abs(e-this.y)<.01?0:this.angleTo(t,e)+(i||0)}angleToFace(t,e,i){let s=this.rotationToFace(t,e,i);return l(s,this.rotation)}rotateTo(e,s,r){if(1==this.__collider)return void new C(0);let o=arguments;if("number"!=typeof o[0]?e=this.rotationToFace(o[0].x,o[0].y,r):o.length>2&&(r=o[3],s=o[2],e=this.rotationToFace(o[0],o[1],r)),e==this.rotation)return;let h=t._angleMode==i?360:t.TWO_PI;return(e=(e-this.rotation)%h)<0&&s>0&&(e+=h),e>0&&s<0&&(e-=h),s??=this.rotationSpeed||Math.sign(e),this.rotate(e,s)}rotateMinTo(t,e,i){if(1==this.__collider)return void new C(0);let s=arguments;return"number"!=typeof s[0]?t=this.rotationToFace(s[0].x,s[0].y,i):s.length>2&&(i=s[3],e=s[2],t=this.rotationToFace(s[0],s[1],i)),t!=this.rotation?(t=l(t,this.rotation),e??=this.rotationSpeed>.1?this.rotationSpeed:1,e=Math.abs(e)*Math.sign(t),this.rotate(t,e)):void 0}rotate(e,i){if(1==this.__collider)return void new C(0);if(isNaN(e))return void new C(1,[e]);if(0==e)return;i??=this.rotationSpeed||1;let s=e>0&&i>0;s||(e=-Math.abs(e),i=-Math.abs(i)),this.rotationSpeed=i;let r=Math.abs(i),o=this.rotation+e;this._rotateIdx??=0,this._rotateIdx++;let h=this._rotateIdx;return(async()=>{let e=.01;do{let a=Math.abs(o-this.rotation);if(r>a&&(this.rotationSpeed=a*Math.sign(i)),await t.sleep(),this._rotateIdx!=h)return!1;if(s&&this.rotationSpeed<e||!s&&this.rotationSpeed>-.01)return!1}while((s&&o>this.rotation||!s&&o<this.rotation)&&e<Math.abs(o-this.rotation));return this.rotationSpeed=0,this.rotation=o,!0})()}addAni(){if(t.p5play.disableImages)return void(this._ani=new t.Ani);let e,i,s=[...arguments];return s[0]instanceof t.Ani?(i=s[0],i._addedToSpriteOrGroup&&(i=i.clone()),e=i.name||"default",i.name=e):s[1]instanceof t.Ani?(e=s[0],i=s[1],i._addedToSpriteOrGroup&&(i=i.clone()),i.name=e):(i=new t.Ani(this,...s),e=i.name),this.animations[e]=i,this._ani=i,i._addedToSpriteOrGroup=!0,!this._dimensionsUndef||1==i.w&&1==i.h||(this.w=i.w,this.h=i.h),i}addImage(){return this.addAni(...arguments)}addAnis(){let t,e=arguments;1==e.length?t=e[0]:(this.spriteSheet=e[0],t=e[1]);for(let e in t){let i=t[e];this.addAni(e,i)}}addImages(){return this.addAnis(...arguments)}async changeAni(e){if(t.p5play.disableImages)return;if(arguments.length>1)e=[...arguments];else if(e instanceof t.Ani){if(e==this._ani)return;e=[e]}else if(!Array.isArray(e)){if(e==this._ani?.name)return;e=[e]}let i,s;this._aniChangeCount++;for(let r=0;r<e.length;r++){let o=e[r];(o instanceof t.Ani||o instanceof p5.Image||"string"==typeof o&&1!=o.length&&o.includes("."))&&(o=this.addAni(o),e[r]=o),"string"==typeof o&&(o={name:o},e[r]=o),o.name.length>1&&("!"==o.name[0]&&(o.name=o.name.slice(1),o.start=-1,o.end=0),"<"!=o.name[0]&&">"!=o.name[0]||(o.name=o.name.slice(1),o.flipX=!0),"^"==o.name[0]&&(o.name=o.name.slice(1),o.flipY=!0),"**"==o.name&&(i=!0,e=e.slice(0,-1)),";;"==o.name&&(s=!0,e=e.slice(0,-1)))}let r=this._aniChangeCount;do{for(let t=0;t<e.length;t++){let i=e[t];!i.start&&e.length>1&&(i.start=0),await this._playSequencedAni(i)}}while(i&&r==this._aniChangeCount);1!=e.length&&s&&this._ani.stop()}_playSequencedAni(t){return new Promise((e=>{let{name:i,start:s,end:r,flipX:o,flipY:h}=t;this._changeAni(i),o&&(this._ani.scale.x=-this._ani.scale.x),h&&(this._ani.scale.y=-this._ani.scale.y),s<0&&(s=this._ani.length+s),void 0!==s&&(this._ani._frame=s),void 0!==r?this._ani.goToFrame(r):this._ani._frame==this._ani.lastFrame&&e(),this._ani._onComplete=this._ani._onChange=()=>{o&&(this._ani.scale.x=-this._ani.scale.x),h&&(this._ani.scale.y=-this._ani.scale.y),this._ani._onComplete=this._ani._onChange=null,e()}}))}changeAnimation(){return this.changeAni(...arguments)}_changeAni(e){this._ani?._onChange&&this._ani._onChange(),this._ani?.onChange&&this._ani.onChange();let i=this.animations[e];if(!i)for(let t=this.groups.length-1;t>=0;t--){if(i=this.groups[t].animations[e],i){i=i.clone();break}}if(!i)throw t.noLoop(),new C("Sprite.changeAnimation",[e]);this._ani=i,this._ani.name=e,this.resetAnimationsOnChange&&(this._ani._frame=0)}remove(){this.removed=!0}_remove(){this.body&&t.world.destroyBody(this.body),this.body=null;for(let t of this.groups)t.remove(this)}toString(){return"s"+this.idNum}_setContactCB(e,i,s,r){let o;o=0==s?d._collisions[r]:d._overlappers[r];let h=t.p5play[o],a=h[this._uid]??={};a[e._uid]!=i&&(a[e._uid]=i,a=h[e._uid],a&&a[this._uid]&&(delete a[this._uid],0==Object.keys(a).length&&delete h[e._uid]))}_validateCollideParams(t,e){if(!t)throw new C("Sprite.collide",2);if(!t._isSprite&&!t._isGroup)throw new C("Sprite.collide",0,[t]);if(e&&"function"!=typeof e)throw new C("Sprite.collide",1,[e])}_ensureCollide(t,e,i){if(!1!==this._hasOverlap[t._uid]&&(this._hasOverlap[t._uid]=!1),!1!==t._hasOverlap[this._uid]&&(t._hasOverlap[this._uid]=!1,t._isGroup))for(let e of t)e._hasOverlap[this._uid]=!1,this._hasOverlap[e._uid]=!1}collide(t,e){return this.collides(t,e)}collides(t,e){return this._validateCollideParams(t,e),this._ensureCollide(t),e&&this._setContactCB(t,e,0,0),1==this._collisions[t._uid]||this._collisions[t._uid]<=-3}colliding(t,e){this._validateCollideParams(t,e),this._ensureCollide(t),e&&this._setContactCB(t,e,0,1);let i=this._collisions[t._uid];return i<=-3?1:i>0?i:0}collided(t,e){return this._validateCollideParams(t,e),this._ensureCollide(t),e&&this._setContactCB(t,e,0,2),this._collisions[t._uid]<=-1}_validateOverlapParams(t,e){if(!t)throw new C("Sprite.overlap",2);if(!t._isSprite&&!t._isGroup)throw new C("Sprite.overlap",0,[t]);if(e&&"function"!=typeof e)throw new C("Sprite.overlap",1,[e])}_ensureOverlap(t){if(this._hasSensors||this.addDefaultSensors(),!t._hasSensors)if(t._isSprite)t.addDefaultSensors();else{for(let e of t)e._hasSensors||e.addDefaultSensors();t._hasSensors=!0}if(this._hasOverlap[t._uid]||(this._removeContactsWith(t),this._hasOverlap[t._uid]=!0),!t._hasOverlap[this._uid]&&(t._removeContactsWith(this),t._hasOverlap[this._uid]=!0,t._isGroup))for(let e of t)e._hasOverlap[this._uid]=!0,this._hasOverlap[e._uid]=!0}overlap(t,e){return this.overlaps(t,e)}overlaps(t,e){return this._validateOverlapParams(t,e),this._ensureOverlap(t),e&&this._setContactCB(t,e,1,0),1==this._overlappers[t._uid]||this._overlappers[t._uid]<=-3}overlapping(t,e){this._validateOverlapParams(t,e),this._ensureOverlap(t),e&&this._setContactCB(t,e,1,1);let i=this._overlappers[t._uid];return i<=-3?1:i>0?i:0}overlapped(t,e){return this._validateOverlapParams(t,e),this._ensureOverlap(t),e&&this._setContactCB(t,e,1,2),this._overlappers[t._uid]<=-1}_removeContactsWith(t){if(t._isGroup)for(let e of t)this._removeContactsWith(e);else this.__removeContactsWith(t)}__removeContactsWith(e){if(this.body)for(let i=this.body.getContactList();i;i=i.next){let s=i.contact;s.m_fixtureA.m_body.sprite._uid!=e._uid&&s.m_fixtureB.m_body.sprite._uid!=e._uid||t.world.destroyContact(s)}}_sortFixtures(){let t,e,i=null,s=null;for(let r=this.fixtureList;r;r=r.getNext())r.m_isSensor?(s?s.m_next=r:s=r,e=r):(i?i.m_next=r:i=r,t=r);s&&(e.m_next=null),i&&(t.m_next=s),this.body.m_fixtureList=i||s}addDefaultSensors(){let t;if(this.body&&this.fixtureList){for(let e=this.fixtureList;e;e=e.getNext())e.m_isSensor||(t=e.m_shape,this.body.createFixture({shape:t,isSensor:!0}));this._sortFixtures()}else this.addSensor();this._hasSensors=!0}distanceTo(e){return t.dist(this.x,this.y,e.x,e.y)}},t.Sprite.propTypes={x:"Float64",y:"Float64",vel:"Vec2",rotation:"number",rotationSpeed:"number",allowSleeping:"boolean",bearing:"number",bounciness:"number",collider:"Uint8",color:"color",debug:"boolean",density:"number",direction:"number",drag:"number",friction:"number",h:"number",isSuperFast:"boolean",layer:"number",life:"Int32",mass:"number",mirror:"Vec2_boolean",offset:"Vec2",pixelPerfect:"boolean",removed:"boolean",rotationDrag:"number",rotationLock:"boolean",scale:"Vec2",shape:"Uint8",sleeping:"boolean",stroke:"color",strokeWeight:"number",text:"string",textColor:"color",textSize:"number",textStroke:"color",textStrokeWeight:"number",tile:"string",tileSize:"number",tint:"color",visible:"boolean",w:"number",opacity:"number",gravityScale:"number"},t.Sprite.props=Object.keys(t.Sprite.propTypes),t.Sprite.propsAll=t.Sprite.props.concat(["autoDraw","autoUpdate","colour","d","diameter","dynamic","fill","height","heading","kinematic","resetAnimationsOnChange","speed","spriteSheet","static","textColour","textFill","width"]),t.Sprite.colliderTypes=["d","s","k","n"],t.Sprite.shapeTypes=["box","circle","chain","polygon"],t.Turtle=function(e){if(t.allSprites.tileSize>1)throw new Error("Turtle can't be used when allSprites.tileSize is greater than 1.");e??=25;let i=new t.Sprite(e,e,[[e,.4*e],[-e,.4*e],[0,.8*-e]]);i.color="green",i._isTurtleSprite=!0,i._prevPos={x:i.x,y:i.y};let s=i.move;return i.move=function(){return this._prevPos.x=this.x,this._prevPos.y=this.y,s.call(this,...arguments)},i},this.Ani=class extends Array{constructor(){super();let e,i=[...arguments];if(this.name="default","object"==typeof i[0]&&(i[0]._isSprite||i[0]._isGroup)&&(e=i[0],i=i.slice(1),this._addedToSpriteOrGroup=!0),e??=t.allSprites,"string"!=typeof i[0]||1!=i[0].length&&i[0].includes(".")||(this.name=i[0],i=i.slice(1)),this._frame=0,this._cycles=0,this.targetFrame=-1,this.offset={x:e.anis.offset.x??0,y:e.anis.offset.y??0},this._frameDelay=e.anis.frameDelay||4,this.demoMode=e.anis.demoMode??!1,this.playing=!0,this.visible=!0,this.looping=e.anis.looping??!0,this.endOnFirstFrame=e.anis.endOnFirstFrame??!1,this.frameChanged=!1,this.onComplete=this.onChange=null,this._onComplete=this._onChange=null,this.rotation=e.anis.rotation??0,this._scale=new u,0!=i.length&&"number"!=typeof i[0]){if(e.animations[this.name]=this,e._ani=this,Array.isArray(i[0])&&"string"==typeof i[0][0]&&(i=[...i[0]]),2!=i.length||"string"!=typeof i[0]||"string"!=typeof i[1]&&"number"!=typeof i[1])if("string"==typeof i.at(-1)||i.at(-1)instanceof p5.Image)for(let s=0;s<i.length;s++)i[s]instanceof p5.Image?this.push(i[s]):this.push(t.loadImage(i[s]));else{let r,o=e.spriteSheet;if(i[0]instanceof p5.Image||"string"==typeof i[0]){if(i.length>=3)throw new C("Ani",1);o=i[0],r=i[1]}else r=i[0];let h=this;if(o instanceof p5.Image&&1!=o.width&&1!=o.height)this.spriteSheet=o,a();else{let n;n="string"==typeof o?o:o.url,t._incrementPreload(),this.spriteSheet=t.loadImage(n,(()=>{a(),t._decrementPreload()})),"string"==typeof o&&(e.spriteSheet=this.spriteSheet)}function a(){Array.isArray(r)&&(r="object"==typeof r[0]?{frames:r}:4==r.length?{pos:r.slice(0,2),size:r.slice(2)}:{pos:r});let{w:i,h:s,width:o,height:a,size:n,row:l,col:d,line:p,x:u,y:c,pos:_,frames:g,frameCount:f,frameDelay:m,frameSize:y,delay:w,rotation:v}=r;y??=n||e.anis.frameSize,w&&(h.frameDelay=w),m&&(h.frameDelay=m),v&&(h.rotation=v),g&&Array.isArray(g)?f=g.length:f??=g||1,i??=o||e.anis.w,s??=a||e.anis.h,u??=d||0,c??=p||l||0,_&&(u=_[0],c=_[1]),"number"==typeof y?i=s=y:y&&(i=y[0],s=y[1]);let x=e.tileSize;if(i&&s?(i*=x,s*=x):!e._dimensionsUndef&&e.w&&e.h?(i??=e.w*x,s??=e.h*x):1!=x?(i??=x,s??=x):f?(i??=h.spriteSheet.width/f,s??=h.spriteSheet.height):i=s=h.spriteSheet.width<h.spriteSheet.height?h.spriteSheet.width:h.spriteSheet.height,Array.isArray(g)){let e=Math.round(h.spriteSheet.width/i);for(let r of g){let o;"number"==typeof r?(c=Math.floor(r/e)*s,u=r%e*i,o={x:u,y:c,w:i,h:s}):2==r.length?(u=r[0]*i,c=r[1]*s,o={x:u,y:c,w:i,h:s}):o={x:r[0],y:r[1],w:r[2],h:r[3]},o.defaultWidth=o.w*t._defaultImageScale,o.defaultHeight=o.h*t._defaultImageScale,h.push(o)}}else{(1!=x||_||void 0!==p||void 0!==l||void 0!==d)&&(u*=i,c*=s);for(let e=0;e<f;e++){let e={x:u,y:c,w:i,h:s};e.defaultWidth=i*t._defaultImageScale,e.defaultHeight=s*t._defaultImageScale,h.push(e),u+=i,u>=h.spriteSheet.width&&(u=0,c+=s,c>=h.spriteSheet.height&&(c=0))}}}}else{let l,d,p=i[0];isNaN(i[1])?l=i[1]:d=Number(i[1]);let c=p.lastIndexOf("."),_=0,g=0;for(let w=c-1;w>=0&&!isNaN(p.charAt(w));w--)_++;if(l)for(let v=l.length-5;v>=0&&!isNaN(l.charAt(v));v--)g++;let f,m=p.slice(c),y=p.slice(0,c-_);if(l&&(f=l.slice(0,c-g)),l&&y!=f)this.push(t.loadImage(p)),this.push(t.loadImage(l));else{let x,b=parseInt(p.slice(c-_,c),10);if(d??=parseInt(l.slice(c-g,c),10),d<b){let S=d;d=b,b=S}if(l&&_!=g)for(let A=b;A<=d;A++)x=y+A+m,this.push(t.loadImage(x));else for(let k=b;k<=d;k++)x=y+t.nf(k,_)+m,this.push(t.loadImage(x))}}1==this.length&&(this.playing=!1)}}get frame(){return this._frame}set frame(t){if(t<0||t>=this.length)throw new C("Ani.frame",[t,this.length]);this._frame=t,this._cycles=0}get frameDelay(){return this._frameDelay}set frameDelay(t){t<=0&&(t=1),this._frameDelay=t}get scale(){return this._scale}set scale(t){"number"==typeof t&&(t={x:t,y:t}),this._scale._x=t.x,this._scale._y=t.y,this._scale._avg=t.x}clone(){this.length||console.error(`The animation named "${this.name}" must be loaded before it can be properly copied. Sprites need their own copy of a group's animation. Try loading the animation in the preload function and creating new group sprites in the setup function.`);let e=new t.Ani;e.spriteSheet=this.spriteSheet;for(let t=0;t<this.length;t++)e.push(this[t]);return e.name=this.name,e.offset.x=this.offset.x,e.offset.y=this.offset.y,e.frameDelay=this.frameDelay,e.playing=this.playing,e.looping=this.looping,e.rotation=this.rotation,e}draw(e,i,s,r,o){if(this.x=e||0,this.y=i||0,s??=this.rotation,!this.visible)return;r??=1,o??=1,t.push(),t.imageMode("center"),t.translate(this.x,this.y),t.rotate(s),t.scale(r*this._scale._x,o*this._scale._y);let h=this.offset.x,a=this.offset.y,n=this[this._frame];if(void 0!==n)if(this.spriteSheet){let{x:e,y:i,w:s,h:r}=n;this.demoMode?t.image(this.spriteSheet,h,a,this.spriteSheet.w,this.spriteSheet.h,e-this.spriteSheet.w/2+s/2,i-this.spriteSheet.h/2+r/2):t.image(this.spriteSheet,h,a,n.defaultWidth||s,n.defaultHeight||r,e,i,s,r)}else t.image(n,h,a);else console.warn('p5play: "'+this.name+'" animation not loaded yet or frame '+this._frame+" does not exist. Load this animation in the preload function if you need to use it at the start of your program.");t.pop()}update(){if(this.playing)if(this._cycles++,this._cycles%this.frameDelay==0){if(this._cycles=0,this.frameChanged=!0,(-1==this.targetFrame&&this._frame==this.lastFrame||this._frame==this.targetFrame)&&(this.endOnFirstFrame&&(this._frame=0),this.looping?this.targetFrame=-1:this.playing=!1,this._onComplete&&this._onComplete(),this.onComplete&&this.onComplete(),!this.looping))return;this.targetFrame>this._frame&&-1!==this.targetFrame?this._frame++:this.targetFrame<this._frame&&-1!==this.targetFrame?this._frame--:this.targetFrame===this._frame&&-1!==this.targetFrame?this.playing=!1:this.looping?this._frame>=this.lastFrame?this._frame=0:this._frame++:this._frame<this.lastFrame&&this._frame++}else this.frameChanged=!1}play(t){return this.playing=!0,void 0!==t&&this._frame!=t&&(this._frame=t,this._cycles=0),this.targetFrame=-1,new Promise((t=>{this._onComplete=()=>{this._onComplete=null,t()}}))}pause(t){this.playing=!1,t&&(this._frame=t)}stop(t){this.playing=!1,t&&(this._frame=t)}rewind(){return this.looping=!1,this.goToFrame(0)}loop(){this.looping=!0,this.playing=!0}noLoop(){this.looping=!1}nextFrame(){this._frame<this.length-1?this._frame=this._frame+1:this.looping&&(this._frame=0),this.targetFrame=-1,this.playing=!1,this._cycles=0}previousFrame(){this._frame>0?this._frame=this._frame-1:this.looping&&(this._frame=this.length-1),this.targetFrame=-1,this.playing=!1,this._cycles=0}goToFrame(t){if(!(t<0||t>=this.length))return this.targetFrame=t,this._cycles=0,this.targetFrame!==this._frame&&(this.playing=!0),new Promise((t=>{this._onComplete=()=>{this._onComplete=null,t()}}))}get lastFrame(){return this.length-1}get frameImage(){let e=this[this._frame];if(e instanceof p5.Image)return e;let{x:i,y:s,w:r,h:o}=e,h=t.createImage(r,o);return h.copy(this.spriteSheet,this.offset.x,this.offset.y,r,o,i,s,r,o),h}get w(){return this.width}get width(){let t=this[this._frame];return t instanceof p5.Image?t.width:t?t.w:1}get defaultWidth(){return this[this._frame].defaultWidth}get h(){return this.height}get height(){let t=this[this._frame];return t instanceof p5.Image?t.height:t?t.h:1}get defaultHeight(){return this[this._frame].defaultHeight}},t.Ani.props=["demoMode","endOnFirstFrame","frameDelay","frameSize","looping","offset","rotation","scale"],t.SpriteAnimation=t.Ani,this.Anis=class{#t={};constructor(){let e=this,i=[...t.Ani.props,"w","h"],s=["offset","scale"];for(let t of i)Object.defineProperty(this,t,{get:()=>e.#t[t],set(i){e.#t[t]=i;for(let s in e){let r=e[s];r instanceof Ani&&(r[t]=i)}}});for(let t of s){this.#t[t]={_x:0,_y:0};for(let i of["x","y"])Object.defineProperty(this.#t[t],i,{get:()=>e.#t[t]["_"+i],set(s){e.#t[t]["_"+i]=s;for(let r in e){let o=e[r];o instanceof Ani&&(o[t][i]=s)}}})}}get width(){return this.w}set width(t){this.w=t}get height(){return this.h}set height(t){this.h=t}},this.Group=class extends Array{constructor(...e){let i;if(e[0]instanceof t.Group&&(i=e[0],e=e.slice(1)),super(...e),"number"==typeof e[0])return;for(let e of this)if(!(e instanceof t.Sprite))throw new Error("A group can only contain sprites");if(this._isGroup=!0,this.x,this.y,this.vel,this.rotation,this.rotationSpeed,this.autoDraw,this.allowSleeping,this.autoUpdate,this.bounciness,this.collider,this.color,this.debug,this.density,this.direction,this.drag,this.friction,this.h,this.isSuperFast,this.layer,this.life,this.mass,this.mirror,this.offset,this.pixelPerfect,this.removed,this.rotationDrag,this.rotationLock,this.scale,this.shape,this.sleeping,this.stroke,this.strokeWeight,this.text,this.textColor,this.tile,this.tileSize,this.visible,this.w,this.bearing,this.d,this.dynamic,this.heading,this.kinematic,this.resetAnimationsOnChange,this.speed,this.static,this.idNum,t.p5play.groupsCreated<999)this.idNum=t.p5play.groupsCreated;else{for(let e=1;e<t.p5play.groups.length;e++)if(!t.p5play.groups[e]?.removed){this.idNum=e;break}if(!this.idNum){console.warn("ERROR: Surpassed the limit of 999 groups in memory. Use less groups or delete groups from the p5play.groups array to recycle ids.");for(let e=1;e<t.p5play.groups.length;e++)if(!t.p5play.groups[e].length){this.idNum=e;break}this.idNum??=1}}if(this._uid=this.idNum,t.p5play.groups[this._uid]=this,t.p5play.groupsCreated++,t.allSprites||(this._isAllSpritesGroup=!0),this.subgroups=[],i instanceof t.Group){i.subgroups.push(this);let e=i;do{e=t.p5play.groups[e.parent],e.subgroups.push(this)}while(!e._isAllSpritesGroup);this.parent=i._uid}else this._isAllSpritesGroup||(t.allSprites.subgroups.push(this),this.parent=0);this.animations=new t.Anis,this._hasOverlap={},this._collisions={},this._overlappers={};let s=this;this.Sprite=class extends t.Sprite{constructor(){super(s,...arguments)}},this.GroupSprite=this.Sprite,this.Group=class extends t.Group{constructor(){super(s,...arguments)}},this.Subgroup=this.Group,this.mouse={presses:null,pressing:null,pressed:null,holds:null,holding:null,held:null,released:null,hovers:null,hovering:null,hovered:null};for(let t in this.mouse)this.mouse[t]=function(e){for(let i of s)if(i.mouse[t](e))return!0;return!1};for(let e of t.Sprite.propsAll)"ani"!=e&&"velocity"!=e&&"width"!=e&&"height"!=e&&"diameter"!=e&&Object.defineProperty(this,e,{get(){let i=s["_"+e];if(void 0===i&&!s._isAllSpritesGroup){let r=t.p5play.groups[s.parent];r&&(i=r[e])}return i},set(t){s["_"+e]=t;for(let i of s.subgroups)i["_"+e]=t;for(let i=0;i<s.length;i++){let r=s[i],o=t;"function"==typeof t&&(o=t(i)),r[e]=o}}});let r=["mirror","offset","scale","vel"];for(let e of r){e="_"+e,this[e]="vel"!=e?{}:new t.Vector,this[e]._x=0,this[e]._y=0;for(let i of["x","y"])Object.defineProperty(this[e],i,{get(){let r=s[e]["_"+i],o=s.length-1;if(void 0===r&&!s._isAllSpritesGroup){let h=t.p5play.groups[s.parent];h&&(r=h[e][i],o=h.length-1)}return r},set(t){s[e]["_"+i]=t;for(let r=0;r<s.length;r++){let o=s[r],h=t;"function"==typeof t&&(h=t(r)),o[e][i]=h}}})}this._isAllSpritesGroup&&(this.autoCull=!0,this.tileSize=1,this.autoDraw=!0,this.autoUpdate=!0),this.add=this.push,this.contains=this.includes}_getTopLayer(){if(0==this.length)return 0;if(1==this.length&&void 0===this[0]._layer)return 0;let t=this[0]._layer;for(let e of this)e._layer>t&&(t=e._layer);return t}get ani(){return this._ani}set ani(t){this.addAni(t);for(let e of this)e.changeAni(t)}get animation(){return this._ani}set animation(t){this.ani=t}get anis(){return this.animations}get img(){return this._img}set img(t){this.image=t}get image(){return this._img}set image(e){"function"!=typeof e?("string"==typeof e&&(e=e.includes(".")?t.loadImage(e):new t.EmojiImage(e,this.w||this.width||this.d||this.diameter)),this._img=t.Sprite.prototype._extendImage(e)):this._img=e}get amount(){return this.length}set amount(t){let e=t-this.length,i=e>0;e=Math.abs(e);for(let t=0;t<e;t++)i?new this.Sprite:this[this.length-1].remove()}get diameter(){return this.d}set diameter(t){this.d=t}get width(){return this.w}set width(t){this.w=t}get height(){return this.h}set height(t){this.h=t}get velocity(){return this.vel}set velocity(t){this.vel=t}_resetCentroid(){let t=0,e=0;for(let i of this)t+=i.x,e+=i.y;return this.centroid={x:t/this.length,y:e/this.length},this.centroid}_resetDistancesFromCentroid(){for(let t of this)t.distCentroid={x:t.x-this.centroid.x,y:t.y-this.centroid.y}}_validateCollideParams(t,e){if(e&&"function"!=typeof e)throw new C("Group.collide",1,[e]);if(!t)throw new C("Group.collide",2);if(!t._isGroup&&!t._isSprite)throw new C("Group.collide",0,[t])}_setContactCB(e,i,s,r){if(e._isSprite){let t=function(t,e,s){return i.call(e,e,t,s)};return void e._setContactCB(this,t,s,r)}let o;o=0==s?d._collisions[r]:d._overlappers[r];let h=t.p5play[o],a=h[this._uid]??={};if(a[e._uid]!=i){a[e._uid]=i;for(let t of this){(h[t._uid]??={})[e._uid]=i}if(this._uid!=e._uid&&(a=h[e._uid],a&&a[this._uid])){this._uid!=e._uid&&delete a[this._uid];for(let t of e)a=h[t._uid],a&&a[this._uid]&&(delete a[this._uid],0==Object.keys(a).length&&delete h[t._uid]);0==Object.keys(a).length&&delete h[e._uid]}}}_ensureCollide(t){if(!1!==this._hasOverlap[t._uid]){this._hasOverlap[t._uid]=!1;for(let e of this)if(e._hasOverlap[t._uid]=!1,t._hasOverlap[e._uid]=!1,this._uid==t._uid)for(let i of t)e._hasOverlap[i._uid]=!1,i._hasOverlap[e._uid]=!1}if(!1!==t._hasOverlap[this._uid]&&(t._hasOverlap[this._uid]=!1,t._isGroup))for(let e of t){e._hasOverlap[this._uid]=!1,this._hasOverlap[e._uid]=!1;for(let t of this)e._hasOverlap[t._uid]=!1,t._hasOverlap[e._uid]=!1}}collide(t,e){return this.collides(t,e)}collides(t,e){return this._validateCollideParams(t,e),this._ensureCollide(t),e&&this._setContactCB(t,e,0,0),1==this._collisions[t._uid]||this._collisions[t._uid]<=-3}colliding(t,e){this._validateCollideParams(t,e),this._ensureCollide(t),e&&this._setContactCB(t,e,0,1);let i=this._collisions[t._uid];return i<=-3?1:i>0?i:0}collided(t,e){return this._validateCollideParams(t,e),this._ensureCollide(t),e&&this._setContactCB(t,e,0,2),this._collisions[t._uid]<=-1}_validateOverlapParams(t,e){if(e&&"function"!=typeof e)throw new C("Group.overlap",1,[e]);if(!t)throw new C("Group.overlap",2);if(!t._isGroup&&!t._isSprite)throw new C("Group.overlap",0,[t])}_ensureOverlap(t){if(!this._hasSensors){for(let t of this)t._hasSensors||t.addDefaultSensors();this._hasSensors=!0}if(!t._hasSensors)if(t._isSprite)t.addDefaultSensors();else{for(let e of t)e._hasSensors||e.addDefaultSensors();t._hasSensors=!0}if(1!=this._hasOverlap[t._uid]){this._removeContactsWith(t),this._hasOverlap[t._uid]=!0;for(let e of this)if(e._hasOverlap[t._uid]=!0,t._hasOverlap[e._uid]=!0,this._uid==t._uid)for(let i of t)e._hasOverlap[i._uid]=!0,i._hasOverlap[e._uid]=!0}if(1!=t._hasOverlap[this._uid]&&(t._removeContactsWith(this),t._hasOverlap[this._uid]=!0,t._isGroup))for(let e of t){e._hasOverlap[this._uid]=!0,this._hasOverlap[e._uid]=!0;for(let t of this)e._hasOverlap[t._uid]=!0,t._hasOverlap[e._uid]=!0}}overlap(t,e){return this.overlaps(t,e)}overlaps(t,e){return this._validateOverlapParams(t,e),this._ensureOverlap(t),e&&this._setContactCB(t,e,1,0),1==this._overlappers[t._uid]||this._overlappers[t._uid]<=-3}overlapping(t,e){this._validateOverlapParams(t,e),this._ensureOverlap(t),e&&this._setContactCB(t,e,1,1);let i=this._overlappers[t._uid];return i<=-3?1:i>0?i:0}overlapped(t,e){return this._validateOverlapParams(t,e),this._ensureOverlap(t),e&&this._setContactCB(t,e,1,2),this._overlappers[t._uid]<=-1}_removeContactsWith(t){for(let e of this)e._removeContactsWith(t)}applyForce(){for(let t of this)t.applyForce(...arguments)}applyForceScaled(){for(let t of this)t.applyForceScaled(...arguments)}attractTo(){for(let t of this)t.attractTo(...arguments)}applyTorque(){for(let t of this)t.applyTorque(...arguments)}move(t,e,i){let s=[];for(let r of this)s.push(r.move(t,e,i));return Promise.all(s)}moveTo(e,i,s){if("number"!=typeof e){let r=e;if(r==t.mouse&&!t.mouse.isActive)return;s=i,i=r.y,e=r.x}let r=this._resetCentroid(),o=[];for(let t of this){let h={x:t.x-r.x+e,y:t.y-r.y+i};o.push(t.moveTo(h.x,h.y,s))}return Promise.all(o)}moveTowards(e,i,s){if("number"!=typeof e){let r=e;if(r==t.mouse&&!t.mouse.isActive)return;s=i,i=r.y,e=r.x}if(void 0!==e||void 0!==i){this._resetCentroid();for(let t of this){void 0===t.distCentroid&&this._resetDistancesFromCentroid();let r={x:t.distCentroid.x+e,y:t.distCentroid.y+i};t.moveTowards(r.x,r.y,s)}}}moveAway(e,i,s){if("number"!=typeof e){let r=e;if(r==t.mouse&&!t.mouse.isActive)return;s=i,i=r.y,e=r.x}if(void 0!==e||void 0!==i){this._resetCentroid();for(let t of this){void 0===t.distCentroid&&this._resetDistancesFromCentroid();let r={x:t.distCentroid.x+e,y:t.distCentroid.y+i};t.moveAway(r.x,r.y,s)}}}push(...e){this.removed&&(console.warn("Adding a sprite to a group that was removed. Use `group.removeAll()` to remove all of a group's sprites without removing the group itself. Restoring the group in p5play's memory."),t.p5play.groups[this._uid]=this,this.removed=!1);for(let i of e){if(!(i instanceof t.Sprite))throw new Error("You can only add sprites to a group, not "+typeof i);if(i.removed){console.error("Can't add a removed sprite to a group");continue}let e;for(let s in this._hasOverlap){let r=this._hasOverlap[s];r&&!i._hasSensors&&i.addDefaultSensors(),e=s>=1e3?t.p5play.sprites[s]:t.p5play.groups[s],e&&!e.removed&&(r?e._ensureOverlap(i):e._ensureCollide(i))}for(let e in d){let s=d[e];for(let e of s){let s=t.p5play[e],r=s[this._uid];if(!r)continue;let o=s[i._uid]??={};for(let t in r)o[t]=r[t]}}super.push(i),this.parent&&t.p5play.groups[this.parent].push(i),i.groups.push(this)}return this.length}repelFrom(){for(let t of this)t.repelFrom(...arguments)}size(){return this.length}toString(){return"g"+this.idNum}cull(e,i,s,r,o){if(void 0===s){o=i,e=i=s=r=e}if(isNaN(e)||isNaN(i)||isNaN(s)||isNaN(r))throw new TypeError("The culling boundary must be defined with numbers");if(o&&"function"!=typeof o)throw new TypeError("The callback to group.cull must be a function");let h=t.camera.x-t.canvas.hw/t.camera.zoom,a=t.camera.y-t.canvas.hh/t.camera.zoom,n=-s+h,l=-e+a,d=t.width+r+h,p=t.height+i+a,u=0;for(let t=0;t<this.length;t++){let e=this[t];"chain"!=e.shape&&((e.x<n||e.y<l||e.x>d||e.y>p)&&(u++,o?o(e,u):e.remove(),e.removed&&t--))}return u}remove(t){if(void 0===t)return this.removeAll(),void(this._isAllSpritesGroup||(this.removed=!0));let e;if(e="number"==typeof t?t>=0?t:this.length+t:this.indexOf(t),-1==e)return;let i=this[e];return this.splice(e,1),i}splice(e,i){let s=super.splice(e,i);if(!s)return;let r=[];for(let t of s){if(t.removed)continue;let e=this._uid;do{r.push(e);let i=t.groups.findIndex((t=>t._uid==e)),s=t.groups.splice(i,1);e=s[0].parent}while(e)}for(let e of r){let i=t.p5play.groups[e];for(let e in d)for(let s in i[e]){if(0==i[e][s])continue;let r;r=s>=1e3?t.p5play.sprites[s]:t.p5play.groups[s];let o=!1;for(let t of i)if(t[e][r._uid]>0){o=!0;break}o||(i[e][r._uid]=-2,r[e][i._uid]=-2)}}return s}pop(){return this.remove(this.length-1)}shift(){return this.remove(0)}unshift(){return console.error("unshift is not supported for groups"),this.length}removeAll(){for(;this.length>0;)this.at(-1).remove()}_step(){this.__step()}draw(){let e=[...this];e.sort(((t,e)=>t._layer-e._layer));for(let i=0;i<e.length;i++){let s=e[i];!1===s._visible||t.p5play._inPostDraw&&!s.autoDraw||s.draw()}this._autoDraw&&(this._autoDraw=null)}update(){for(let e of this)t.p5play._inPostDraw&&!this.autoUpdate||e.update();this._autoUpdate&&(this._autoUpdate=null)}},t.Group.prototype.addAni=t.Group.prototype.addAnimation=t.Group.prototype.addImg=t.Group.prototype.addImage=t.Sprite.prototype.addAnimation=t.Sprite.prototype.addImg=t.Sprite.prototype.addAni,t.Group.prototype.addAnis=t.Group.prototype.addAnimations=t.Group.prototype.addImgs=t.Group.prototype.addImages=t.Sprite.prototype.addAnimations=t.Sprite.prototype.addImgs=t.Sprite.prototype.addAnis,t.Group.prototype.__step=t.Sprite.prototype.__step,t.Group.prototype.___step=t.Sprite.prototype.___step,this.World=class extends planck.World{constructor(){super(new e.Vec2(0,0),!0),this.mod={},this.origin={x:0,y:0},this.contacts=[],this.on("begin-contact",this._beginContact),this.on("end-contact",this._endContact);let i=this;this._gravity={get x(){return i.m_gravity.x},set x(e){if((e=Math.round(e||0))!=i.m_gravity.x){i.mod[0]=!0;for(let e of t.allSprites)e.sleeping=!1;i.m_gravity.x=e}},get y(){return i.m_gravity.y},set y(e){if((e=Math.round(e||0))!=i.m_gravity.y){i.mod[0]=!0;for(let e of t.allSprites)e.sleeping=!1;i.m_gravity.y=e}}},this._timeScale=1,this._updateTimeStep(),this.velocityIterations=8,this.positionIterations=3,this.velocityThreshold=.19,this.physicsTime=0,this.meterSize=60,this.mouseTracking??=!0,this.mouseSprite=null,this.mouseSprites=[],this.autoStep=!0,window.Event&&(this.steppedEvent=new window.Event("p5play_worldStepped"))}get gravity(){return this._gravity}set gravity(t){this._gravity.x=t.x,this._gravity.y=t.y}get timeScale(){return this._timeScale}set timeScale(t){if(t<0||t>2)return console.error("world.timeScale must be between 0 and 2");this._timeScale!=t&&(this._timeScale=t,this._updateTimeStep())}_updateTimeStep(){this._timeStep=1/(t._targetFrameRate||60)*this._timeScale}get velocityThreshold(){return e.Settings.velocityThreshold}set velocityThreshold(t){e.Settings.velocityThreshold=t}step(e,i,s){for(let e of t.allSprites)e.prevPos.x=e.x,e.prevPos.y=e.y,e.prevRotation=e.rotation;super.step(e||this._timeStep,i||this.velocityIterations,s||this.positionIterations),this.physicsTime+=e||this._timeStep;let r=Object.values(t.p5play.sprites),o=Object.values(t.p5play.groups);for(let t of r)t._step();for(let t of o)t._step();for(let t of r)t.___step();for(let t of o)t.___step();t.canvas.dispatchEvent&&t.canvas.dispatchEvent(this.steppedEvent),this.autoStep&&(this.autoStep=null)}get realTime(){return t.millis()/1e3}getSpritesAt(i,s,r,o=!0){"object"==typeof i&&(s=i.y,i=i.x);const h=new e.Vec2(i/t.world.meterSize,s/t.world.meterSize),a=new e.AABB;a.lowerBound=new e.Vec2(h.x-.001,h.y-.001),a.upperBound=new e.Vec2(h.x+.001,h.y+.001);let n=[];if(this.queryAABB(a,(t=>(t.getShape().testPoint(t.getBody().getTransform(),h)&&n.push(t),!0))),0==n.length)return[];r??=t.allSprites;let l=[];for(let t of n){const e=t.m_body.sprite;e._cameraActiveWhenDrawn==o&&(l.find((t=>t._uid==e._uid))||l.push(e))}return l.sort(((t,e)=>-1*(t._layer-e._layer))),l}getSpriteAt(t,e,i){return this.getSpritesAt(t,e,i)[0]}getMouseSprites(){let e=this.getSpritesAt(t.mouse.x,t.mouse.y);if(t.camera._wasOff){let i=this.getSpritesAt(t.mouse.canvasPos.x,t.mouse.canvasPos.y,t.allSprites,!1);i.length&&(e=[...i,...e])}return e}_beginContact(t){let e=t.m_fixtureA,i=t.m_fixtureB,s="_collisions";e.m_isSensor&&(s="_overlappers"),e=e.m_body.sprite,i=i.m_body.sprite,e[s][i._uid]=0,i[s][e._uid]=0;for(let t of i.groups)(!e[s][t._uid]||e[s][t._uid]<0)&&(e[s][t._uid]=0,t[s][e._uid]=0);for(let t of e.groups){(!i[s][t._uid]||i[s][t._uid]<0)&&(i[s][t._uid]=0,t[s][i._uid]=0);for(let e of i.groups)(!t[s][e._uid]||t[s][e._uid]<0)&&(t[s][e._uid]=0,e[s][t._uid]=0)}}_endContact(t){let e=t.m_fixtureA,i=t.m_fixtureB,s="_collisions";e.m_isSensor&&(s="_overlappers"),e=e.m_body.sprite,i=i.m_body.sprite,e[s][i._uid]=0!=e[s][i._uid]?-2:-4,i[s][e._uid]=0!=i[s][e._uid]?-2:-4;for(let t of i.groups){let i=!1;for(let r of t)if(r[s][e._uid]>=0){i=!0;break}i||(t[s][e._uid]=0!=t[s][e._uid]?-2:-4,e[s][t._uid]=0!=e[s][t._uid]?-2:-4)}for(let t of e.groups){let e=!1;for(let r of t)if(r[s][i._uid]>=0){e=!0;break}if(!e){t[s][i._uid]=0!=t[s][i._uid]?-2:-4,i[s][t._uid]=0!=i[s][t._uid]?-2:-4;for(let e of i.groups)t[s][e._uid]=0!=t[s][e._uid]?-2:-4,e[s][t._uid]=0!=e[s][t._uid]?-2:-4}}}_findContact(t,e,i){let s=e[t][i._uid];if(s)return s;for(let r of i.groups)if(s=e[t][r._uid],s)return s;for(let r of e.groups){if(s=r[t][i._uid],s)return s;for(let e of i.groups)if(r._uid==e._uid&&(s=r[t][e._uid],s))return s}return!1}get allowSleeping(){return this.getAllowSleeping()}set allowSleeping(t){this.setAllowSleeping(t)}rayCast(t,e,i){return this.rayCastAll(t,e,i,(()=>!0))[0]}rayCastAll(e,i,r,o){let h,a=t.allSprites.tileSize,n=s(e.x,e.y,a);if("number"==typeof arguments[1])h=s(e.x+r*t.cos(i),e.y+r*t.sin(i),a);else{let t=arguments[1];o??=arguments[2],h=s(t.x,t.y,a)}let l=[],d=1;super.rayCast(n,h,(function(t,e,i,s){let r=t.getBody().sprite,h=o&&o(r);return l.push({sprite:r,fraction:s}),h?(s<d&&(d=s),s):1})),l.sort(((t,e)=>t.fraction-e.fraction));let p=[];for(let t of l)t.fraction<=d&&p.push(t.sprite);return p}},this.Camera=class{constructor(){this._pos=t.createVector.call(t),this.__pos={x:0,y:0,rounded:{}},this.isActive=!1,this.bound={min:{x:0,y:0},max:{x:0,y:0}},this._zoomIdx=-1,this._zoom=1,this._destIdx=0}get pos(){return this._pos}set pos(t){this.x=t.x,this.y=t.y}get position(){return this._pos}set position(t){this.x=t.x,this.y=t.y}_calcBoundsX(e){let i=t.canvas.hw/this._zoom;this.bound.min.x=e-i,this.bound.max.x=e+i}_calcBoundsY(e){let i=t.canvas.hh/this._zoom;this.bound.min.y=e-i,this.bound.max.y=e+i}get x(){return this._pos.x}set x(e){if(void 0===e||isNaN(e))return;this._pos.x=e;let i=-e;"2d"==t.canvas.renderer&&(i+=t.canvas.hw/this._zoom),this.__pos.x=i,t.allSprites.pixelPerfect&&(this.__pos.rounded.x=Math.round(i)),this._calcBoundsX(e)}get y(){return this._pos.y}set y(e){if(void 0===e||isNaN(e))return;this._pos.y=e;let i=-e;"2d"==t.canvas.renderer&&(i+=t.canvas.hh/this._zoom),this.__pos.y=i,t.allSprites.pixelPerfect&&(this.__pos.rounded.y=Math.round(i)),this._calcBoundsY(e)}moveTo(e,i,s){if(void 0===e)return;if(isNaN(e)&&(s=i,i=e.y,e=e.x),s??=1,s<=0)return console.warn("camera.moveTo: speed should be a positive number"),Promise.resolve(!1);let r=i-this.y,o=e-this.x,h=Math.sqrt(r*r+o*o),a=s/h,n=o*a,l=r*a;this._destIdx++;let d=this._destIdx,p=Math.ceil(h/s);return(async()=>{for(let e=0;e<p;e++)if(this.x+=n,this.y+=l,await t.sleep(),d!=this._destIdx)return!1;return this.x=e,this.y=i,!0})()}get zoom(){return this._zoom}set zoom(e){if(void 0===e||isNaN(e))return;this._zoom=e;let i=-this._pos.x;"2d"==t.canvas.renderer&&(i+=t.canvas.hw/e);let s=-this._pos.y;"2d"==t.canvas.renderer&&(s+=t.canvas.hh/e),this.__pos.x=i,this.__pos.y=s,t.allSprites.pixelPerfect&&(this.__pos.rounded.x=Math.round(i),this.__pos.rounded.y=Math.round(s)),this._calcBoundsX(this._pos.x),this._calcBoundsY(this._pos.y)}zoomTo(e,i){if(e==this._zoom)return Promise.resolve(!0);i??=.1;let s=Math.abs(e-this._zoom),r=Math.round(s/i);e<this.zoom&&(i=-i),this._zoomIdx++;let o=this._zoomIdx;return(async()=>{for(let e=0;e<r;e++){if(o!=this._zoomIdx)return!1;this.zoom+=i,await t.sleep()}return this.zoom=e,!0})()}on(){this.isActive||(t.push(),t.scale(this._zoom),t.allSprites.pixelPerfect?(this.__pos.rounded.x??=Math.round(this.__pos.x),this.__pos.rounded.y??=Math.round(this.__pos.y),t.translate(this.__pos.rounded.x,this.__pos.rounded.y)):t.translate(this.__pos.x,this.__pos.y),this.isActive=!0)}off(){this.isActive&&(t.pop(),this.isActive=!1)}},e.Fixture.prototype.shouldCollide=function(t){let e=this,i=t;return!(!e.m_isSensor||!i.m_isSensor)||!e.m_isSensor&&!i.m_isSensor&&(e=e.m_body.sprite,i=i.m_body.sprite,!(e._hasOverlap[i._uid]??i._hasOverlap[e._uid]))},this.Tiles=class{constructor(e,i,s,r,o){"string"==typeof e&&("\n"==e[0]&&(e=e.slice(1)),e=(e=e.replaceAll("\t"," ")).split("\n")),i??=0,s??=0,r??=1,o??=1;let h=new t.Group;for(let a=0;a<e.length;a++)for(let n=0;n<e[a].length;n++){let l,d,p=e[a][n];if(" "==p||"."==p)continue;let u=Object.values(t.p5play.groups);for(d of u)if(l=d.animations[p],l)break;if(l){h.push(new d.Sprite(l,i+n*r,s+a*o));continue}let c,_=!1;for(d of u)if(d.tile==p){_=!0;break}if(_)h.push(new d.Sprite(i+n*r,s+a*o));else{for(c of t.allSprites)if(c.tile==p){_=!0;break}if(!_)throw"Tile not found: "+p;c.x=i+n*r,c.y=s+a*o}}return h}},this.createTiles=function(e,i,s,r,o){return new t.Tiles(e,i,s,r,o)},this.Joint=class{constructor(i,s,r){if(!i?._isSprite||!s?._isSprite)throw new Error("The Joint constructor requires two sprites as input.");if(i.body||i.addDefaultSensors(),s.body||s.addDefaultSensors(),this.spriteA=i,this.spriteB=s,r??="glue",this.type=r,"glue"==r){let t=e.WeldJoint({},i.body,s.body,i.body.getWorldCenter());this._createJoint(t)}let o=this;if("glue"!=r&&"slider"!=r&&"rope"!=r)for(let i of["A","B"]){if("A"==i&&"wheel"==r)continue;const s="_offset"+i;this[s]=t.createVector.call(t);for(let r of["x","y"])Object.defineProperty(this[s],r,{get(){let e=o._j["m_localAnchor"+i][r]/o["sprite"+i].tileSize*t.world.meterSize;return t.p5play.friendlyRounding?n(e):e},set(s){if(o._j["m_localAnchor"+i][r]=s/t.world.meterSize*o["sprite"+i].tileSize,"distance"==o.type||"rope"==o.type)o._j.m_length=e.Vec2.distance(o._j.m_bodyA.getWorldPoint(o._j.m_localAnchorA),o._j.m_bodyB.getWorldPoint(o._j.m_localAnchorB));else if("hinge"==o.type||"wheel"==o.type){let t;t="A"==i?"B":"A",o._j["m_localAnchor"+t][r]=o._j["m_body"+t].getLocalPoint(o._j["m_body"+i].getWorldPoint(o._j["m_localAnchor"+i]))[r]}}})}let h=[];"distance"!=r&&"glue"!=r&&"rope"!=r||h.push("enableMotor","maxPower","motorSpeed","power","speed"),"rope"==r&&h.push("damping","springiness");let a={};for(let t of h)a[t]={value:null,enumerable:!1};Object.defineProperties(this,a),this.visible=!0,i.joints.push(this),s.joints.push(this)}_createJoint(e){this._j=t.world.createJoint(e)}_display(){this._draw(this.spriteA.x,this.spriteA.y,this.spriteB.x,this.spriteB.y),this.visible=null}_draw(e,i,s,r){r?t.line(e,i,s,r):t.point(e,i)}get draw(){return this._display}set draw(t){this._draw=t}get offsetA(){return this._offsetA}set offsetA(t){this._offsetA.x=t.x,this._offsetA.y=t.y}get offsetB(){return this._offsetB}set offsetB(t){this._offsetB.x=t.x,this._offsetB.y=t.y}get springiness(){return this._springiness}set springiness(e){if(e>0&&(e=e<.1?t.map(e,0,.1,30,4):e<.5?t.map(e,.1,.5,4,2.5):e<.8?t.map(e,.5,.8,2.5,1):e<.9?t.map(e,.8,.9,1,.5):t.map(e,.9,1,.5,.2)),this._springiness=e,"wheel"!=this.type)return this._j.setFrequency(e);this._j.setSpringFrequencyHz(e)}get damping(){return"wheel"!=this.type?this._j.getDampingRatio():this._j.getSpringDampingRatio()}set damping(t){"wheel"==this.type?this._j.setSpringDampingRatio(t):this._j.setDampingRatio(t)}get speed(){return this._j.getJointSpeed()}set speed(t){this._j.isMotorEnabled()||this._j.enableMotor(!0),this._j.setMotorSpeed(t)}get motorSpeed(){return this._j.getMotorSpeed()}get enableMotor(){return this._j.isMotorEnabled()}set enableMotor(t){this._j.enableMotor(t)}get maxPower(){return this._j.getMaxMotorTorque()}set maxPower(t){!this._j.isMotorEnabled()&&t&&this._j.enableMotor(!0),this._j.setMaxMotorTorque(t),t||this._j.enableMotor(!1)}get power(){return this._j.getMotorTorque()}get collideConnected(){return this._j.getCollideConnected()}set collideConnected(t){this._j.m_collideConnected=t}get reactionForce(){return this._j.getReactionForce(t.world._timeStep)}get reactionTorque(){return this._j.getReactionTorque(t.world._timeStep)}remove(){this._removed||(this.spriteA.joints.splice(this.spriteA.joints.indexOf(this),1),this.spriteB.joints.splice(this.spriteB.joints.indexOf(this),1),t.world.destroyJoint(this._j),this._removed=!0)}},this.GlueJoint=class extends t.Joint{constructor(t,e){super(...arguments,"glue")}},this.DistanceJoint=class extends t.Joint{constructor(t,i){super(...arguments,"distance");let s=e.DistanceJoint({},t.body,i.body,t.body.getWorldCenter(),i.body.getWorldCenter());this._createJoint(s)}_display(){let t,e;(this.offsetA.x||this.offsetA.y)&&(t=this.spriteA.body.getWorldPoint(this._j.m_localAnchorA),t=r(t.x,t.y,this.spriteA.tileSize)),(this.offsetB.x||this.offsetB.y)&&(e=this.spriteB.body.getWorldPoint(this._j.m_localAnchorB),e=r(e.x,e.y,this.spriteB.tileSize)),this._draw(t?t.x:this.spriteA.x,t?t.y:this.spriteA.y,e?e.x:this.spriteB.x,e?e.y:this.spriteB.y),this.visible=null}},this.WheelJoint=class extends t.Joint{constructor(s,r){super(...arguments,"wheel");let o=e.WheelJoint({maxMotorTorque:1e3,frequencyHz:4,dampingRatio:.7},s.body,r.body,r.body.getWorldCenter(),new e.Vec2(0,1));this._createJoint(o),this._angle=t._angleMode==i?90:1.5707963267948966}_display(){let e,i,s=this.spriteA.x,o=this.spriteA.y;if(this.offsetB.x||this.offsetB.y){let t=this.spriteB.body.getWorldPoint(this._j.m_localAnchorB);t=r(t.x,t.y,this.spriteB.tileSize),e=t.x,i=t.y}else e=this.spriteB.x,i=this.spriteB.y;let h=t.tan(this.spriteA.rotation),a=t.tan(this._angle+this.spriteA.rotation),n=(i-o+h*s-a*e)/(h-a),l=h*(n-s)+o;this._draw(n,l,e,i),this.visible=null}get angle(){return this._angle}set angle(i){i!=this._angle&&(this._angle=i,this._j.m_localXAxisA=new e.Vec2(t.cos(i),t.sin(i)),this._j.m_localXAxisA.normalize(),this._j.m_localYAxisA=e.Vec2.crossNumVec2(1,this._j.m_localXAxisA))}},this.HingeJoint=class extends t.Joint{constructor(t,i){super(...arguments,"hinge");let s=e.RevoluteJoint({},t.body,i.body,t.body.getWorldCenter());this._createJoint(s)}_display(){const e=this.offsetA.x,i=this.offsetA.y,s=this.spriteA.rotation,r=e*t.cos(s)-i*t.sin(s),o=e*t.sin(s)+i*t.cos(s);this._draw(this.spriteA.x+r,this.spriteA.y+o),this.visible=null}get range(){return this.upperLimit-this.lowerLimit}set range(t){t/=2,this.upperLimit=t,this.lowerLimit=-t}get lowerLimit(){let e=this._j.getLowerLimit();return"radians"==t._angleMode?e:t.degrees(e)}set lowerLimit(e){this._j.isLimitEnabled()||this._j.enableLimit(!0),this.spriteA.body.setAwake(!0),this.spriteB.body.setAwake(!0),t._angleMode==i&&(e=t.radians(e)),this._j.m_lowerAngle=e}get upperLimit(){let e=this._j.getUpperLimit();return"radians"==t._angleMode?e:t.degrees(e)}set upperLimit(e){this._j.isLimitEnabled()||this._j.enableLimit(!0),this.spriteA.body.setAwake(!0),this.spriteB.body.setAwake(!0),t._angleMode==i&&(e=t.radians(e)),this._j.m_upperAngle=e}get angle(){let e=this._j.getJointAngle();return"radians"==t._angleMode?e:t.radians(e)}},t.RevoluteJoint=t.HingeJoint,this.SliderJoint=class extends t.Joint{constructor(t,i){super(...arguments,"slider");let s=e.PrismaticJoint({lowerTranslation:-1,upperTranslation:1,enableLimit:!0,maxMotorForce:50,motorSpeed:0,enableMotor:!0},t.body,i.body,t.body.getWorldCenter(),new e.Vec2(1,0));this._createJoint(s),this._angle=0}get angle(){return this._angle}set angle(i){i!=this._angle&&(this._angle=i,this._j.m_localXAxisA=new e.Vec2(t.cos(i),t.sin(i)),this._j.m_localXAxisA.normalize(),this._j.m_localYAxisA=e.Vec2.crossNumVec2(1,this._j.m_localXAxisA))}get range(){return this.upperLimit-this.lowerLimit}set range(t){t/=2,this.upperLimit=t,this.lowerLimit=-t}get lowerLimit(){return this._j.getLowerLimit()/this.spriteA.tileSize*t.world.meterSize}set lowerLimit(e){this._j.isLimitEnabled()||this._j.enableLimit(!0),e=e*this.spriteA.tileSize/t.world.meterSize,this._j.setLimits(e,this._j.getUpperLimit())}get upperLimit(){return this._j.getUpperLimit()/this.spriteA.tileSize*t.world.meterSize}set upperLimit(e){this._j.isLimitEnabled()||this._j.enableLimit(!0),e=e*this.spriteA.tileSize/t.world.meterSize,this._j.setLimits(this._j.getLowerLimit(),e)}},t.PrismaticJoint=t.SliderJoint,this.RopeJoint=class extends t.Joint{constructor(t,i){super(...arguments,"rope");let s=e.RopeJoint({maxLength:1},t.body,i.body,t.body.getWorldCenter());this._createJoint(s),this._j.m_localAnchorB.x=0,this._j.m_localAnchorB.y=0}get maxLength(){return e=this._j.getMaxLength(),i=this.spriteA.tileSize,e/i*t.world.meterSize;var e,i}set maxLength(e){var i,s;this._j.setMaxLength((i=e,s=this.spriteA.tileSize,i*s/t.world.meterSize))}},this.GrabJoint=class extends this.Joint{constructor(i,s){"object"!=typeof s&&(s=mouse),super(i,i,"grab");let r=e.MouseJoint({maxForce:1e3,frequencyHz:3,dampingRatio:.9,target:i.body.getPosition()},i.body,i.body,new e.Vec2(s.x/t.world.meterSize,s.y/t.world.meterSize));this._createJoint(r),this._target={x:s.x,y:s.y}}_draw(){t.line(this.spriteA.x,this.spriteA.y,this._target.x,this._target.y)}get target(){return this._target}set target(i){let s=this._target.x=i.x,r=this._target.y=i.y;this._j.setTarget(new e.Vec2(s/t.world.meterSize,r/t.world.meterSize))}set maxForce(t){this._j.setMaxForce(t)}};class u{constructor(){let t=this;Object.defineProperties(this,{x:{get:()=>t._x,set(e){e!=t._x&&(t._x=e,t._avg=.5*(t._x+t._y))},configurable:!0,enumerable:!0},y:{get:()=>t._y,set(e){e!=t._y&&(t._y=e,t._avg=.5*(t._x+t._y))},configurable:!0,enumerable:!0},_x:{value:1,enumerable:!1,writable:!0},_y:{value:1,enumerable:!1,writable:!0},_avg:{value:1,enumerable:!1,writable:!0}})}valueOf(){return this._avg}}function c(t){return!/^(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*\s*(?:(?:(?:async\s(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*\s*)?function|class)(?:\s|(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*)|(?:[_$\w][\w0-9_$]*\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*\()|(?:\[\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*(?:(?:['][^']+['])|(?:["][^"]+["]))\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*\]\())/.test(t.toString())}function _(t,e){let i=t,s=e.toLowerCase();if("triangle"==s?i=[i,-120,3]:"square"==s?i=[i,-90,4]:"pentagon"==s?i=[i,-72,5]:"hexagon"==s?i=[i,-60,6]:"septagon"==s?i=[i,-51.4285714286,7]:"octagon"==s?i=[i,-45,8]:"enneagon"==s?i=[i,-40,9]:"decagon"==s?i=[i,-36,10]:"hendecagon"==s?i=[i,-32.7272727273,11]:"dodecagon"==s&&(i=[i,-30,12]),i==t)throw new Error("Invalid, not a regular polygon: "+e);return i}if(t.p5play.palettes=[{a:"aqua",b:"black",c:"crimson",d:"darkviolet",e:"peachpuff",f:"olive",g:"green",h:"hotpink",i:"indigo",j:"navy",k:"khaki",l:"lime",m:"magenta",n:"brown",o:"orange",p:"pink",q:"turquoise",r:"red",s:"skyblue",t:"tan",u:"blue",v:"violet",w:"white",x:"gold",y:"yellow",z:"gray"}],this.colorPal=(e,i)=>{if(e instanceof p5.Color)return e;"number"==typeof i&&(i=t.p5play.palettes[i]),i??=t.p5play.palettes[0];let s=i[e];return s?t.color(s):t.color(0,0,0,0)},this.EmojiImage=function(e,i){t.push(),t.textSize(i);let s=t.createGraphics(i,1.25*i);s.textSize(i),s.textAlign(t.CENTER),s.text(e,i/2,i);let r=s.drawingContext,o=s._pixelDensity||1,h=s.canvas.width,a=s.canvas.height,n=r.getImageData(0,0,h,a).data,l=h,d=0,p=a,u=0,c=3;for(let t=0;t<a;t++)for(let e=0;e<h;e++)0!==n[c]&&(e<l&&(l=e),e>d&&(d=e),t<p&&(p=t),t>u&&(u=t)),c+=4;return p=Math.floor(p/o),u=Math.floor(u/o),l=Math.floor(l/o),d=Math.floor(d/o),s=s.get(l,p,d-l+1,u-p+1),t.pop(),s.url=e,s},this.spriteArt=(e,i,s)=>{i??=1,"number"==typeof s&&(s=t.p5play.palettes[s]),s??=t.p5play.palettes[0];let r=e;"string"==typeof e&&(r=(e=(e=(e=e.trim()).replace(/\r*\n\t+/g,"\n")).replace(/\s+$/g,"")).split("\n"));let o=0;for(let t of r)t.length>o&&(o=t.length);let h=r.length,a=t.createImage(o*i,h*i);a.loadPixels();for(let t=0;t<r.length;t++)for(let e=0;e<r[t].length;e++)for(let o=0;o<i;o++)for(let h=0;h<i;h++){let n=this.colorPal(r[t][e],s);a.set(e*i+o,t*i+h,n)}return a.updatePixels(),a.w=a.width,a.h=a.height,t.p5play.onImageLoad(a),a},this.createSprite=function(){return new t.Sprite(...arguments)},this.createGroup=function(){return new t.Group(...arguments)},this.loadAnimation=this.loadAni=function(){return new t.Ani(...arguments)},this.animation=function(t,e,i,s,r,o){t.visible&&t.update(),t.draw(e,i,s,r,o)},this.delay=t=>new Promise(t?e=>{setTimeout(e,t)}:requestAnimationFrame),this.sleep=e=>e?t.delay(e):new Promise((e=>{if(t.canvas.dispatchEvent){t.canvas.addEventListener("p5play_worldStepped",(function i(){t.canvas.removeEventListener("p5play_worldStepped",i),e()}))}else setTimeout(e,1e3*t.world._timeStep)})),this.play=t=>{if(!t?.play)throw new Error("Tried to play your sound but it wasn't a sound object.");return new Promise((e=>{t.play(),t.onended((()=>e()))}))},window.location){let e=location.hostname;switch(e){case"":case"127.0.0.1":case"localhost":case"p5play.org":case"editor.p5js.org":case"codepen.io":case"codera.app":case"aug4th.com":case"cdpn.io":case"glitch.com":case"replit.com":case"stackblitz.com":case"jsfiddle.net":case"aijs.io":case"preview-aijs.web.app":case"quinton-ashley.github.io":break;default:if(/^[\d\.]+$/.test(e)||e.endsWith("stackblitz.io")||e.endsWith("glitch.me")||e.endsWith("replit.dev")||e.endsWith("codehs.com")||e.endsWith("codehs.me")||e.endsWith("openprocessing.org")||location.origin.endsWith("preview.p5js.org"))break;!async function(){if(document.getElementById("p5play-intro"))return;t._incrementPreload();let e=document.createElement("div");e.id="p5play-intro",e.style="position: absolute; width: 100%; height: 100%; top: 0; left: 0; z-index: 1000; background-color: black;";let i=document.createElement("img");i.style="position: absolute; top: 50%; left: 50%; width: 80vmin; height: 40vmin; margin-left: -40vmin; margin-top: -20vmin; z-index: 1001; opacity: 1; scale: 1; transition: scale 1.5s, opacity 0.4s ease-in-out;",i.onerror=()=>{i.style.imageRendering="pixelated",i.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAABACAYAAADS1n9/AAABbGlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAACiRfZC/S0JhGIWfm4VgNkQNDg13igYr0SCXBjWQIkisQG26Xn+C2sfVCKMtWkPoP8igOWgoIgxaGhqCqCGitqamgpaSL+69hS51lvfhcDgcXujxaEKUeoFypWbEo2E1kUypzhcUFCxpelWEYrEFk39vlxT4uLezt+Nm12u7uRvciV6Wj88XNx88k/wvVyZb1YEvwKcLowaKF4ht1ITJW8CwkUimQGmYnLf5wOS0zSdWZjkeAeUaUPWClgHlFfCmu/x8F5dL6/rPMnO9O1tZWTJ7gBFmKVJFUEKjjkqMwB/5KSsfYQ1BHYMieQrUUAkhrIYsKnNU0JnAi4ofH3785p/tuo+7n/95O972M8y0pJRnHW++BUfT4DrteGNBGOyHq1OhGZplOYCeXA7eDmEgCUM34Fqt5gJ+e707DH1PUr6PgnMP2g0pP/elbDfB8QgXlW8Y/mq9pjC8gwAABSxJREFUeJztnb9y2zAMxulcpnbNntfJ3D5n97xO966Z3aNP9NHgBxAgQVmO8bvLNZZIiCI+gH8kpyl4bk7P3gErOJ/PZ0+zp9NpmZ9CAM54O7+wSgQhAEdWOb+wQgSvzZHAj5+/50x9/WkOeRMZwIkm+medXyAi8M4CL82R4KkIATjQRL8nJJN4XysEsAKv9L8DIYAnJyaBk8CUTDLA51/bbP7jHWSQRZPByADeTDp/tM4ozT4AVHSwO1kEMBMY/dTLFNcMcN5oSgTHYHBi2fPrS4qo98Mh/a+C8/ErdyJYw8cbb/bzH/ncGQY8aOYAnpThZ4XGerZdrn209fxIe6rVQw52Oif4NquAfF+d+Y6NSeej9C9F/714WAHkyP5uoxcSCBKSic5WMhwCciTlcnUaRSmVRlw5x0UiVx6VqW1Ru1zbaHl6TXS9Efae3GmuNzpXYDMA7VT6OxKE9nhPKNy1ZlHbEdL/qPNRdHsy2i5WAIk41yt6emM1Jw5OcL12eg4VR1rWmRCGAVEAGjhncseLQ7SOebZV6t4TxWEBcFHHOayO7PoHUcpy/y5FSP+jWJ06KoKRDAUngZxDUXrVlOsdR0jX8vjsxaqI1dilG0ciWdjgHcN4GqgERdcR1/VayjwgBFDzQG/yJEaASKgSIYBnAgg8BKAARRWKvkcjDwMhgAKIjkcACREJlgOuAu5K7Qgwaz0KeQaOOn9vTCsBwLwApMiZdOBROpnj3u2bdX5aPQfwaOBuDIr1HveYryldl30wBO4RZ4AS1aXCbFr2skezTa5b2+7Z7Z2nNjZKh3Jja3HGHtlAcnwyOj+/HIIFUACd0TizbhzTQU1ddAzYg+WYY5d0TM5dXql6A2VzO7n0jUS6kTtXuseVQ4Im01icXxgfApgOuvy8pevPjD3VuRrhRpu29trG2GI7eWPFkKCJerZdzH2UV8NUAsiqR8pnG5YdJjjNZA+8aYvqIq6dQqNfC9N5YofvDNuO3HbQ/tNG+dwVQOmwS8QAg/kY26lABF17Aqq65DgSlSkzMR2ZpM53hmsve32mvehLIvIcoFyIaUB9vhZB3bBmbJ6cLJkfrb4PRj+FmSAeCsbxiXF+0mSAG5WhDtjSfT32S3TtUb6wsMS6Qkd4TtKQoI62b0FTPkW3EQQ6G908KgcB5aA9BKir4WFf59q4ZNneF0eYZ/4SUxtB4lg88rVoLnqEa7CAOqz9J0Y9Caw/N44FnX0zYQPHRXsI4RqQ0Zk/B1iNUB5RYKohgN4svNG8GiApCpbr2QN2uHN08nmBGSK4ttyLkd1D1TBgxGUV4F1OOk/PSWUTENsRqJ3ovo1M5gHo+4A13/YPRd4sS2c7V/m1795WMJvZlNvIUv1RTtzXw2mqncXbnsSSqCJwIuCua3GetX4zBBj+ntDlBCeCYGNg2Vo7UXIeR6nv9fSPE0EIoAdwfs095xis85NeAC/SyWDSCQLXJ6cT9T2Ajo+MQOhkgWTMBMh55iecPSxDQHBLEwCG7WfJkd13CYS6mvpXrJPAoKURQdILATnSkrKbjTJLugc7piGAQWZEkDS7dMIj5utWulQf2SNIzk8hgD6zIoBQRy36n0U0k/sQgAIogjT/Z9saHO1pV3YhACUuImCcNWRPsGVZ1ocAjEAh9JwmOAsyaG9kPycEMAAUQWIcp3CWt71gB84SP34JJ7Gzm0I1A/a0hGomsTigF6VWZ3pEfQjAAY3jLM7yticRAnAEOW7GUd72ECEAZ2qneTjL294NKaX/gKttC9Kft4MAAAAASUVORK5CYII="};let s=window._p5play_intro_image;""==s||s?.includes("made_with_p5play")?((s.includes("bit.")||s.includes("pixel"))&&(i.style.imageRendering="pixelated"),i.src=s):i.src="https://p5play.org/assets/made_with_p5play.webp",await new Promise((t=>i.onload=t)),e.append(i),document.body.append(e),await t.delay(),i.offsetHeight,i.style.scale=1.2,await t.delay(1100),i.style.opacity=0,await t.delay(400),e.style.display="none",e.remove(),document.getElementById("p5play-intro")?.remove(),t._decrementPreload()}()}}let g=p5.disableFriendlyErrors;p5.disableFriendlyErrors=!0;const f=t.createCanvas;this.createCanvas=function(){let e,i,s,r=[...arguments];if("string"==typeof r[0])if(r[0].includes(":")){let t=r[0].split(":"),i=Number(t[0]),s=Number(t[1]),o=window.innerWidth,h=window.innerWidth*(s/i);h>window.innerHeight&&(o=window.innerHeight*(i/s),h=window.innerHeight),r[0]=Math.round(o),r.splice(1,0,Math.round(h)),e="fullscreen"}else r=[0,0,...r];if(r[0]||(r[0]=window.innerWidth,r[1]=window.innerHeight,e="fullscreen"),"string"==typeof r[2]){let t=r[2].toLowerCase().split(" ");"pixelated"==t[0]?(i="pixelated",t[1]?(e="centered",s=Number(t[1].slice(1))):e="fullscreen",r.splice(2,1)):"fullscreen"==t[0]&&(e="fullscreen",r.splice(2,1))}let o=f.call(t,...r);t.ctx=t.drawingContext;let h=o.canvas||o;return o.GL&&(h.renderer="webgl"),"webgpu"!=h.renderer&&(h.renderer="2d"),h.tabIndex=0,h.w=r[0],h.h=r[1],h.addEventListener&&(h.addEventListener("keydown",(function(t){" "!=t.key&&"/"!=t.key&&"ArrowUp"!=t.key&&"ArrowDown"!=t.key&&"ArrowLeft"!=t.key&&"ArrowRight"!=t.key||t.preventDefault()})),h.addEventListener("mouseover",(()=>{this.mouse.isOnCanvas=!0,this.mouse.isActive=!0})),h.addEventListener("mouseleave",(()=>{this.mouse.isOnCanvas=!1})),h.addEventListener("touchstart",(t=>t.preventDefault())),h.addEventListener("contextmenu",(t=>t.preventDefault()))),h.save??=t.saveCanvas.bind(t),h.resize??=t.resizeCanvas.bind(t),h.hw=.5*h.w,h.hh=.5*h.h,h.mouse={x:t.mouseX,y:t.mouseY},"2d"!=h.renderer||t._webgpuFallback?(t.camera.x=0,t.camera.y=0,"webgl"==h.renderer&&(t._textCache=!1),t._webgpuFallback||(t.p5play._renderStats={x:10-h.hw,y:20-h.hh})):(t.camera.x=t.camera.ogX=h.hw,t.camera.y=t.camera.ogY=h.hh),g||(p5.disableFriendlyErrors=!1),t.displayMode(e,i,s),o},this.Canvas=class{constructor(t,e,i,s){this.w,this.width,this.h,this.height,this.hw,this.hh,this.mouse}resize(){}save(){}},this.canvas=t.canvas,t.Canvas=function(){return t.createCanvas(...arguments).canvas};const m=t.resizeCanvas;this.resizeCanvas=(e,i)=>{e??=window.innerWidth,i??=window.innerHeight,m.call(t,e,i);let s=t.canvas;s.w=s.width/t.pixelDensity(),s.h=s.height/t.pixelDensity(),s.hw=.5*s.w,s.hh=.5*s.h,s.fullscreen&&(s.w/s.h>window.innerWidth/window.innerHeight?(s.style.width="100%!important",s.style.height="auto!important"):(s.style.width="auto!important",s.style.height="100%!important")),"2d"==s.renderer?(t.camera.x=s.hw,t.camera.y=s.hh):(t.camera.x=0,t.camera.y=0)};const y=t.frameRate;this.frameRate=function(e){let i=y.call(t,e);return e&&t.world._updateTimeStep(),i};const w=t.background;this.background=function(){let e=arguments;1==e.length&&1==e[0]?.length?w.call(t,t.colorPal(e[0])):w.call(t,...e)};const v=t.fill;this.fill=function(){let e=arguments;1==e.length&&1==e[0]?.length?v.call(t,t.colorPal(e[0])):v.call(t,...e)};const x=t.stroke;this.stroke=function(){let e=arguments;1==e.length&&1==e[0]?.length?x.call(t,t.colorPal(e[0])):x.call(t,...e)};const b=t.loadImage;this.loadImage=this.loadImg=function(){if(t.p5play.disableImages)return t._decrementPreload(),{w:16,width:16,h:16,height:16,pixels:[]};let e,i=arguments,s=i[0],r=t.p5play.images[s];if("function"==typeof i[i.length-1]&&(e=i[i.length-1]),r)return r.width<=1&&r.height<=1||!r.pixels.length?e?(r.cbs.push(e),r.calls++):t._decrementPreload():(e&&e(),t._decrementPreload()),r;return r=b.call(t,s,(e=>{if(e.w||(Object.defineProperty(e,"w",{get:function(){return this.width}}),Object.defineProperty(e,"h",{get:function(){return this.height}})),e.cbs){for(let t of e.cbs)t(e);for(let i=1;i<e.calls;i++)t._decrementPreload();e.cbs=[]}t.p5play.onImageLoad(r)})),r.cbs=[],r.calls=1,e&&r.cbs.push(e),r.url=s,t.p5play.images[s]=r,r};const S=t.image;t.image=function(){t.p5play.disableImages||S.call(t,...arguments)},t.displayMode||"object"!=typeof document||(document.head.insertAdjacentHTML("beforeend","<style>\nhtml, body {\n\tmargin: 0;\n\tpadding: 0;\n}\nbody.hasFrameBorder {\n\tdisplay: block;\n}\n.p5Canvas {\n\toutline: none;\n\t-webkit-touch-callout: none;\n\t-webkit-text-size-adjust: none;\n\t-webkit-user-select: none;\n\toverscroll-behavior: none;\n}\n.p5-pixelated {\n\timage-rendering: pixelated;\n\tfont-smooth: never;\n\t-webkit-font-smoothing: none;\n}\n.p5-centered,\n.p5-maxed,\n.p5-fullscreen {\n display: flex;\n\talign-items: center;\n\tjustify-content: center;\n}\nmain.p5-centered,\nmain.p5-maxed,\n.p5-fullscreen {\n\theight: 100vh;\n}\nmain {\n\toverscroll-behavior: none;\n}\n</style>"),t._adjustDisplay=()=>{let e=t.canvas,i=e.style,s=e.parentElement;i&&s&&e.displayMode&&("pixelated"==e.renderQuality&&(e.classList.add("p5-pixelated"),t.pixelDensity(1),t.noSmooth&&t.noSmooth(),t.textFont&&t.textFont("monospace")),"normal"==e.displayMode?(s.classList.remove("p5-centered","p5-maxed","p5-fullscreen"),i.width=e.w*e.displayScale+"px",i.height=e.h*e.displayScale+"px"):(s.classList.add("p5-"+e.displayMode),s=s.getBoundingClientRect(),e.w/e.h>s.width/s.height?("centered"==e.displayMode?(i.width=e.w*e.displayScale+"px",i.maxWidth="100%"):i.width="100%",i.height="auto",i.maxHeight=""):(i.width="auto",i.maxWidth="","centered"==e.displayMode?(i.height=e.h*e.displayScale+"px",i.maxHeight="100%"):i.height="100%")))},t.displayMode=(e="normal",i="default",s=1)=>{let r=t.canvas;"string"==typeof s&&(s=parseFloat(s.slice(1))),Object.assign(r,{displayMode:e,renderQuality:i,displayScale:s}),t._adjustDisplay()});let A={generic:["Ah! I found an error","Oh no! Something went wrong","Oof! Something went wrong","Houston, we have a problem","Whoops, having trouble here"],Sprite:{constructor:{base:"Sorry I'm unable to make a new Sprite",0:"What is $0 for? If you're trying to specify the x position of the sprite, please specify the y position as well.",1:"If you're trying to specify points for a chain Sprite, please use an array of position arrays.\n$0",2:"Invalid input parameters: $0"},hw:{0:"I can't change the halfWidth of a Sprite directly, change the sprite's width instead."},hh:{1:"I can't change the halfHeight of a Sprite directly, change the sprite's height instead."},rotate:{0:"Can't use this function on a sprite with a static collider, try changing the sprite's collider type to kinematic.",1:'Can\'t use "$0" for the angle of rotation, it must be a number.'},rotateTo:{},rotateMinTo:{},rotateTowards:{},changeAnimation:'I can\'t find any animation named "$0".',collide:{0:"I can't make that sprite collide with $0. Sprites can only collide with another sprite or a group.",1:"The collision callback has to be a function.",2:"You're trying to check for an collision with a sprite or group that doesn't exist!"},overlap:{0:"I can't make that sprite overlap with $0. Sprites can only overlap with another sprite or a group.",1:"The overlap callback has to be a function.",2:"You're trying to check for an overlap with a sprite or group that doesn't exist!"}},Ani:{constructor:{base:"Hey so, I tried to make a new Ani but couldn't",1:"The name of the animation must be the first input parameter."},frame:"Index $0 out of bounds. That means there is no frame $0 in this animation. It only has $1 frames!"},Group:{constructor:{base:"Hmm awkward! Well it seems I can't make that new Group you wanted"}}};A.Group.collide=A.Sprite.collide,A.Group.overlap=A.Sprite.overlap,A.Sprite.rotateTo[0]=A.Sprite.rotateMinTo[0]=A.Sprite.rotateTowards[0]=A.Sprite.rotate[0];class C extends Error{constructor(t,e,i){super(),"string"!=typeof t&&(i=e,e=t,t=(t=this.stack.match(/\n\s*at ([^\(]*)/)[1]).slice(0,-1)),"number"!=typeof e&&(i=e,e=void 0),"new"==t.slice(0,3)&&(t=t.slice(4));let s=(t=t.split("."))[0];t=t[1]||"constructor";let r=this.stack.match(/\/([^p\/][^5][^\/:]*:[^\/:]+):/);r&&(r=r[1].split(":"),r=" in "+r[0]+" at line "+r[1]),r=" using "+s+"."+t+". ",i=i||[];let o,h=A[s][t];o=h.base?h.base+r:A.generic[Math.floor(Math.random()*A.generic.length)]+r,void 0!==e&&(h=h[e]),h&&(h=h.replace(/\$([0-9]+)/g,((t,e)=>i[e])),o+=h),p5._friendlyError(o,t)}}this.allSprites=new t.Group,this.world=new t.World,this.camera=new t.Camera,this.InputDevice=class{constructor(){this.holdThreshold=12,this._default=0}_ac(t){return t}presses(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),1==this[t]||-3==this[t]}pressing(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),-3==this[t]?1:this[t]>0?this[t]:0}pressed(t){return this.released(t)}holds(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),this[t]==this.holdThreshold}holding(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),this[t]>=this.holdThreshold?this[t]:0}held(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),-2==this[t]}released(t){return t??=this._default,void 0===this[t]&&(t=this._ac(t)),this[t]<=-1}releases(t){return this.released(t)}},this._Mouse=class extends t.InputDevice{constructor(){super(),this._default="left";let e=this;this._pos=t.createVector.call(t),Object.defineProperty(this._pos,"x",{get:()=>e.x,set(t){e.x=t}}),Object.defineProperty(this._pos,"y",{get:()=>e.y,set(t){e.y=t}}),this.x=0,this.y=0,this.canvasPos={},this.left=0,this.center=0,this.right=0,this.drag={left:0,center:0,right:0},this._dragFrame={left:!1,center:!1,right:!1},this.isOnCanvas=!1,this.isActive=!1,this._visible=!0,this._cursor="default",this._ogX=0,this._ogY=0}_ac(t){return"left"==(t=t.toLowerCase()).slice(0,4)?t="left":"right"==t.slice(0,5)?t="right":"middle"==t.slice(0,6)&&(t="center"),t}_update(){t.mouse.canvasPos.x=t.mouseX,t.mouse.canvasPos.y=t.mouseY,t.camera.x==t.camera.ogX&&t.camera.y==t.camera.ogY&&1==t.camera.zoom?(this.x=t.mouseX,this.y=t.mouseY):"webgpu"!=t.canvas.renderer?(this.x=(t.mouseX-t.canvas.hw)/t.camera.zoom+t.camera.x,this.y=(t.mouseY-t.canvas.hh)/t.camera.zoom+t.camera.y):(this.x=t.mouseX/t.camera.zoom+t.camera.x,this.y=t.mouseY/t.camera.zoom+t.camera.y)}get pos(){return this._pos}get position(){return this._pos}get cursor(){return t.canvas.style.cursor}set cursor(e){e!=this._cursor&&(t.cursor(e),this._cursor=e)}get visible(){return this._visible}set visible(e){this._visible=e,t.canvas.style.cursor=e?"default":"none"}drags(t){return t??=this._default,1==this.drag[t]}dragging(t){return t??=this._default,this.drag[t]>0?this.drag[t]:0}dragged(t){return t??=this._default,this.drag[t]<=-1}},this.mouse=new t._Mouse,this._SpriteMouse=class extends t._Mouse{constructor(){super(),delete this.canvasPos,this.hover=0}hovers(){return 1==this.hover}hovering(){return this.hover>0?this.hover:0}hovered(){return this.hover<=-1}};const k=function(e){if(t.mouse.isActive=!0,t.mouse[e]++,t.world.mouseSprites.length){let i=t.world.mouseSprite?.mouse;i&&(i[e]=0,i.hover=0,i.drag[e]=0),ms=t.world.mouseSprites[0],t.world.mouseSprite=ms,i=ms.mouse,i[e]=1,i.hover<=0&&(i.hover=1)}},M=t._onmousedown;t._onmousedown=function(e){if(!t._setupDone)return;let i="left";1===e.button?i="center":2===e.button&&(i="right"),k.call(t,i),M.call(t,e)};const z=function(e){let i=t.mouse;i[e]>0&&(i._dragFrame[e]=!0)},T=t._onmousemove;t._onmousemove=function(e){if(!t._setupDone)return;let i="left";1===e.button?i="center":2===e.button&&(i="right"),z.call(t,i),T.call(t,e)};const j=function(e){let i=t.mouse;i[e]>=i.holdThreshold?i[e]=-2:i[e]>1?i[e]=-1:i[e]=-3,i.drag[e]>0&&(i.drag[e]=-1);let s=t.world.mouseSprite?.mouse;s&&(s.hover>1?(s[e]>=t.mouse.holdThreshold?s[e]=-2:s[e]>1?s[e]=-1:s[e]=-3,s.drag[e]>0&&(s.drag[e]=-1)):(s[e]=0,s.drag[e]=0))},O=t._onmouseup;if(t._onmouseup=function(e){if(!t._setupDone)return;let i="left";1===e.button?i="center":2===e.button&&(i="right"),j.call(t,i),O.call(t,e)},this._Touch=class extends t.InputDevice{constructor(e){super(),this.x,this.y,this.id=e.identifier,this._default="duration",this.holdThreshold=t.touches.holdThreshold,this.duration=1,this.drag=0,this._dragFrame=!1,this.canvasPos={},this._update(e)}_update(e){let i=t.canvas;const s=i.getBoundingClientRect(),r=i.scrollWidth/i.w||1,o=i.scrollHeight/i.h||1,h=this.canvasPos.x=(e.clientX-s.left)/r,a=this.canvasPos.y=(e.clientY-s.top)/o;t.camera.x==i.hw&&t.camera.y==i.hh&&1==t.camera.zoom?(this.x=h,this.y=a):(this.x=(h-i.hw)/t.camera.zoom+t.camera.x,this.y=(a-i.hh)/t.camera.zoom+t.camera.y),this.force=e.force}},this.touches=[],t.touches.holdThreshold=12,t._ontouchstart=function(e){if(t._setupDone){t.getAudioContext&&"suspended"==t.getAudioContext()?.state&&t.userStartAudio();for(let i of e.changedTouches)t.touches.push(new t._Touch(i)),1==t.touches.length&&(t.mouseX=t.touches[0].x,t.mouseY=t.touches[0].y,t.mouse._update(),t.world.mouseSprites=t.world.getMouseSprites(),t._onmousedown(e));t.touchStarted&&!t.touchStarted(e)&&e.preventDefault()}},t._ontouchmove=function(e){if(t._setupDone){for(let i of e.changedTouches){let s=t.touches.find((t=>t.id==i.identifier));s._update(i),s._dragFrame=!0,s.id==t.touches[0].id&&(t.mouseX=t.touches[0].x,t.mouseY=t.touches[0].y,t.mouse._update(),t._onmousemove(e))}t.touchMoved&&!t.touchMoved(e)&&e.preventDefault()}},t._ontouchend=function(e){if(t._setupDone){for(let i of e.changedTouches){let s=t.touches.find((t=>t.id==i.identifier));s._update(i),s.duration>=s.holdThreshold?s.duration=-2:s.duration>1?s.duration=-1:s.duration=-3,s.drag>0&&(s.drag=-1),s.id==t.touches[0].id&&(t.mouseX=t.touches[0].x,t.mouseY=t.touches[0].y,t.mouse._update(),t._onmouseup(e))}t.touchEnded&&!t.touchEnded(e)&&e.preventDefault()}},this._Keyboard=class extends t.InputDevice{constructor(){super(),this._default=" ",this.alt=0,this.arrowUp=0,this.arrowDown=0,this.arrowLeft=0,this.arrowRight=0,this.backspace=0,this.capsLock=0,this.control=0,this.enter=0,this.meta=0,this.shift=0,this.tab=0;let t=this._simpleKeyControls={arrowUp:"up",arrowDown:"down",arrowLeft:"left",arrowRight:"right"};t.w=t.W="up",t.s=t.S="down",t.a=t.A="left",t.d=t.D="right",t.i=t.I="up2",t.k=t.K="down2",t.j=t.J="left2",t.l=t.L="right2"}get visible(){return this._inp==document.activeElement}set visible(t){this._inp||(this._inp=Object.assign(document.createElement("input"),{type:"text",style:"position: fixed; height: 0; padding: 0; border: none; opacity: 0.0001; pointer-events: none;"}),document.body.appendChild(this._inp)),this._visible=t,t?this._inp.focus():this._inp.blur()}_ac(t){if(1!=t.length){if(!isNaN(t)){if(38==t)return"arrowUp";if(40==t)return"arrowDown";if(37==t)return"arrowLeft";if(39==t)return"arrowRight";if(t>=10)throw new Error("Use key names with the keyboard input functions, not keyCode numbers!");return t}t=t.replaceAll(/[ _-]/g,"")}if(1!=(t=t.toLowerCase()).length){if("arrowup"==t)return"arrowUp";if("arrowdown"==t)return"arrowDown";if("arrowleft"==t)return"arrowLeft";if("arrowright"==t)return"arrowRight";if("capslock"==t)return"capsLock"}return t}_pre(t){(!this[t]||this[t]<0)&&(this[t]=1)}_rel(t){this[t]>=this.holdThreshold?this[t]=-2:this[t]>1?this[t]=-1:this[t]=-3}get cmd(){return this.meta}get command(){return this.meta}get ctrl(){return this.control}get space(){return this[" "]}get spacebar(){return this[" "]}get opt(){return this.alt}get option(){return this.alt}get win(){return this.meta}get windows(){return this.meta}},this.kb=new t._Keyboard,this.keyboard=t.kb,"object"==typeof navigator&&navigator.keyboard){const e=navigator.keyboard;window==window.top?e.getLayoutMap().then((e=>{"w"!=e.get("KeyW")&&(t.p5play.standardizeKeyboard=!0)})):t.p5play.standardizeKeyboard=!0}else t.p5play.standardizeKeyboard=!0;function P(t){let e=t.code;return 4==e.length&&"Key"==e.slice(0,3)?e[3].toLowerCase():t.key}const F=t._onkeydown;t._onkeydown=function(t){let e=t.key;if(this.p5play.standardizeKeyboard&&(e=P(t)),e.length>1)e=e[0].toLowerCase()+e.slice(1);else{let t=e.toLowerCase(),i=e.toUpperCase();t!=i&&(e!=i?this.kb._pre(i):this.kb._pre(t))}this.kb._pre(e);let i=this.kb._simpleKeyControls[e];i&&this.kb._pre(i),F.call(this,t)};const I=t._onkeyup;t._onkeyup=function(t){let e=t.key;if(this.p5play.standardizeKeyboard&&(e=P(t)),e.length>1)e=e[0].toLowerCase()+e.slice(1);else{let t=e.toLowerCase(),i=e.toUpperCase();t!=i&&(e!=i?this.kb._rel(i):this.kb._rel(t))}this.kb._rel(e);let i=this.kb._simpleKeyControls[e];if(i&&this.kb._rel(i),t.shiftKey){let t=e.toLowerCase();this.kb[t]>0&&this.kb._rel(t)}I.call(this,t)},this.Contro=class extends t.InputDevice{constructor(t){super(),this._default="a",this.connected=!0,this.a=0,this.b=0,this.x=0,this.y=0,this.l=0,this.r=0,this.lt=0,this.rt=0,this.select=0,this.start=0,this.lsb=0,this.rsb=0,this.up=0,this.down=0,this.left=0,this.right=0,this.leftStick={x:0,y:0},this.rightStick={x:0,y:0},this.leftTrigger=0,this.rightTrigger=0,this.buttonMapping={a:0,b:1,x:2,y:3,l:4,r:5,lt:6,rt:7,select:8,start:9,lsb:10,rsb:11,up:12,down:13,left:14,right:15},this.axeMapping={leftStick:{x:0,y:1},rightStick:{x:2,y:3},leftTrigger:4,rightTrigger:5},this.isMock=!1,"string"!=typeof t?(this.gamepad=t,this.id=t.id):(this.gamepad={},this.id=t,this.isMock=!0),this._axeTriggers=this.gamepad.axes&&void 0!==this.gamepad.axes[this.axeMapping.leftTrigger],this.hasAnalogTriggers=this._axeTriggers||void 0,this.id.includes("GuliKit")&&(this.buttonMapping.a=1,this.buttonMapping.b=0,this.buttonMapping.x=3,this.buttonMapping.y=2)}_ac(t){return"lb"==(t=t.toLowerCase())?t="l":"rb"==t?t="r":"leftstickbutton"==t?t="lsb":"rightstickbutton"==t&&(t="rsb"),t}_update(){if(this.isMock)return;if(this.gamepad=navigator.getGamepads()[this.gamepad.index],!this.gamepad?.connected)return;let t=this.gamepad;for(let e in this.buttonMapping){let i=this.buttonMapping[e],s=t.buttons[i];s&&(s.pressed?this[e]++:this[e]=this[e]>0?-1:0)}return this.leftStick.x=t.axes[this.axeMapping.leftStick.x],this.leftStick.y=t.axes[this.axeMapping.leftStick.y],this.rightStick.x=t.axes[this.axeMapping.rightStick.x],this.rightStick.y=t.axes[this.axeMapping.rightStick.y],this._axeTriggers?(this.leftTrigger=t.axes[this.axeMapping.leftTrigger],this.rightTrigger=t.axes[this.axeMapping.rightTrigger]):(this.leftTrigger=t.buttons[this.buttonMapping.lt].value,this.rightTrigger=t.buttons[this.buttonMapping.rt].value,void 0===this.hasAnalogTriggers&&(this.leftTrigger||this.rightTrigger)&&(this.hasAnalogTriggers=!Number.isInteger(this.leftTrigger)||!Number.isInteger(this.rightTrigger))),!0}_reset(){for(let t in this.buttonMapping)this[t]=0;this.leftStick.x=0,this.leftStick.y=0,this.rightStick.x=0,this.rightStick.y=0,this.leftTrigger=0,this.rightTrigger=0}get cross(){return this.a}get circle(){return this.b}get square(){return this.x}get triangle(){return this.y}get ls(){return this.leftStick}get rs(){return this.rightStick}get lb(){return this.l}get rb(){return this.r}get l1(){return this.l}get r1(){return this.r}get zl(){return this.lt}get zr(){return this.rt}get l2(){return this.leftTrigger}get r2(){return this.rightTrigger}get leftStickButton(){return this.lsb}get rightStickButton(){return this.rsb}get l3(){return this.lsb}get r3(){return this.rsb}},this._Contros=class extends Array{constructor(){if(super(),window&&(window.addEventListener("gamepadconnected",(t=>{this._onConnect(t.gamepad)})),window.addEventListener("gamepaddisconnected",(t=>{this._onDisconnect(t.gamepad)}))),"object"!=typeof navigator||!navigator.getGamepads)return;let t=navigator.getGamepads();for(let e of t)e&&this._onConnect(e)}swap(e,i){let s=this[e];this[e]=this[i],this[i]=s,0!=e&&0!=i||(t.contro=this[0],!t._q5&&t._isGlobal&&(window.contro=this[0]))}remove(t){this[t]=null}onConnect(t){return!0}onDisconnect(t){return!1}_onConnect(e){if(e){for(let t=0;t<this.length;t++)if(e.index==this[t].gamepad?.index)return this[t].connected=!0,void p("contros["+t+"] reconnected: "+e.id);if(p(e),this.onConnect(e)){let i=new t.Contro(e),s=0;for(let t=0;t<this.length;t++)if(!this[t]){s=t;break}this[s]=i,p("contros["+s+"] connected: "+e.id),0==s&&(t.contro=i,t._isGlobal&&(window.contro=i))}}}_onDisconnect(t){if(t)for(let e=0;e<this.length;e++)if(this[e].gamepad?.index===t.index)return this[e].connected=!1,p("contros["+e+"] disconnected: "+t.id),void(this.onDisconnect(t)?this.remove(e):this[e]._reset())}_update(){for(let t of this)t.connected&&t._update()}},this.contros=new t._Contros,this.controllers=t.contros,this.contro=new t.Contro("mock0"),t._webgpuFallback&&(t._beginRender=!1),this.getFPS??=()=>t.p5play._fps,this.renderStats=(t,e)=>{console.error("p5play: renderStats() function is deprecated. Use `p5play.renderStats = true` instead.")}})),p5.prototype.registerMethod("pre",(function(){const t=this;t._q5||(t.p5play._preDrawFrameTime=performance.now()),t.p5play.spritesDrawn=0,t.mouse._update(),t.contros._update()})),p5.prototype.registerMethod("post",(function(){const t=this;if(t.allSprites.autoCull&&t.allSprites.cull(1e4),t.allSprites._autoDraw&&(t.camera.on(),t.allSprites.draw(),t.camera.off()),t.allSprites._autoDraw??=!0,t.p5play.renderStats){let e=t.p5play._renderStats;if(e.fontSize||(1==t.allSprites.tileSize||t.allSprites.tileSize>16?e.fontSize=16:e.fontSize=10,e.gap=1.25*e.fontSize),!t.p5play._fpsAvg||t.frameCount%20==0){let e=0,i=t.p5play._fpsArr.length;for(let s=0;s<i;s++)e+=t.p5play._fpsArr[s];e=Math.round(e/i);let s,r=Math.min(...t.p5play._fpsArr);t.p5play._fpsAvg=e,t.p5play._fpsMin=r,t.p5play._fpsMax=Math.max(...t.p5play._fpsArr),t.p5play._fpsArr=[],s=r>55?t.color(30,255,30):r>25?t.color(255,100,30):t.color(255,30,30),t.p5play._statsColor=s}t.p5play._fpsArr.push(t.getFPS()),t.push(),t.fill(0,0,0,128),t.rect(e.x-5,e.y-e.fontSize,8.5*e.fontSize,5*e.gap+5),t.fill(t.p5play._statsColor),t.textAlign("left"),t.textSize(e.fontSize),e.font&&t.textFont(e.font);let i=e.x,s=e.y;t.text("sprites: "+t.p5play.spritesDrawn,i,s),t.text("display: "+Math.round(t.frameRate())+"hz",i,s+e.gap),t.text("fps avg: "+t.p5play._fpsAvg,i,s+2*e.gap),t.text("fps min: "+t.p5play._fpsMin,i,s+3*e.gap),t.text("fps max: "+t.p5play._fpsMax,i,s+4*e.gap),t.pop(),e.show=!1}t.world.autoStep&&t.world.timeScale>0&&t.world.step(),t.world.autoStep??=!0,t.allSprites._autoUpdate&&t.allSprites.update(),t.allSprites._autoUpdate??=!0;for(let e of t.allSprites)e.autoDraw??=!0,e.autoUpdate??=!0;for(let e in t.kb)"holdThreshold"!=e&&(t.kb[e]<0?t.kb[e]=0:t.kb[e]>0&&t.kb[e]++);for(let e=0;e<t.touches.length;e++){let i=t.touches[e];i.duration++,i._dragFrame?(i.drag++,i._dragFrame=!1):i.drag<0&&(i.drag=0),i.duration<=0&&(t.touches.splice(e,1),e--)}let e=t.mouse,i=t.world.mouseSprite?.mouse;for(let t of["left","center","right"])e[t]<0?e[t]=0:e[t]>0&&e[t]++,i?.hover&&(i[t]=e[t]),e._dragFrame[t]?(e.drag[t]++,i&&(i.drag[t]=e.drag[t]),e._dragFrame[t]=!1):e.drag[t]<0&&(e.drag[t]=0,i&&(i.drag[t]=0));if(t.world.mouseTracking&&t.mouse.isActive){let s=t.world.getMouseSprites();for(let t=0;t<s.length;t++){let e=s[t];0==t?e.mouse.hover++:e.mouse.hover>0?e.mouse.hover=-1:e.mouse.hover<0&&(e.mouse.hover=0)}e.left<=0&&e.center<=0&&e.right<=0&&(t.world.mouseSprite=null);let r=t.world.mouseSprite,o=e.drag.left>0||e.drag.center>0||e.drag.right>0;for(let e of t.world.mouseSprites)if(!s.includes(e)){let i=e.mouse;i.hover>0&&(i.hover=-1,i.left=i.center=i.right=0),o||e!=r||(t.world.mouseSprite=r=null)}r&&(s.includes(r)||s.push(r),i.x=r.x-e.x,i.y=r.y-e.y),t.world.mouseSprites=s}t.camera.off(),t._q5||(t.p5play._postDrawFrameTime=performance.now(),t.p5play._fps=Math.round(1e3/(t.p5play._postDrawFrameTime-t.p5play._preDrawFrameTime))||1),t.p5play._inPostDraw=!1}));