From c5aa995247fac77f25231edb02996ebb74bdf0bb Mon Sep 17 00:00:00 2001 From: Quinton Ashley Date: Sun, 10 Sep 2023 07:45:16 -0500 Subject: [PATCH] 3.12.5 --- p5play.js | 2 +- p5play.min.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/p5play.js b/p5play.js index 36157b2d..8eae883b 100644 --- a/p5play.js +++ b/p5play.js @@ -449,7 +449,7 @@ p5.prototype.registerMethod('init', function p5playInit() { let ts = this.tileSize; if (!w && (this._ani.w != 1 || this._ani.h != 1)) { w = this._ani.w / ts; - if (this.shape != 'circle') { + if (!h && this.shape != 'circle') { h = this._ani.h / ts; } } diff --git a/p5play.min.js b/p5play.min.js index 8d739489..b53e9564 100644 --- a/p5play.min.js +++ b/p5play.min.js @@ -4,4 +4,4 @@ * @author quinton-ashley * @license gpl-v3-only */ -p5.prototype.registerMethod("init",(function(){if(void 0===window.planck)throw"planck.js must be loaded before p5play";const t=this,e=console.log;this.log=console.log;const i=planck,s=60;if(this.p5play??={},this.p5play.os??={},this.p5play.context??="web",this.p5play.standardizeKeyboard??=!1,this.p5play.sprites={},this.p5play.groups={},this.p5play.groupsCreated=0,this.p5play.spritesCreated=0,this.p5play.spritesDrawn=0,this.p5play._renderStats={},this.p5play.disableImages=!1,void 0===window._p5play_gtagged&&"undefined"==typeof process){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_12")}}this.angleMode("degrees");const r=(t,e,r)=>new i.Vec2(t*r/s,e*r/s),o=(t,e,r)=>new i.Vec2(t/r*s,e/r*s),h=t=>Math.abs(t)<=i.Settings.linearSlop,n=t=>Math.abs(t-Math.round(t))<=i.Settings.linearSlop?Math.round(t):t,a={_collisions:["_collides","_colliding","_collided"],_overlappers:["_overlaps","_overlapping","_overlapped"]};this.Sprite=class{constructor(e,r,o,h,a){this.p=t,this.idNum,this.watch,this.mod=[];let u,c,_=[...arguments];if(void 0!==_[0]&&_[0]instanceof this.p.Group&&(u=_[0],_=_.slice(1)),_.length||(this._noArgs=!0),void 0!==_[0]&&isNaN(_[0])&&("string"==typeof _[0]||_[0]instanceof this.p.SpriteAnimation||_[0]instanceof p5.Image)&&(c=_[0],_=_.slice(1)),1==_.length&&"number"==typeof _[0])throw new v("Sprite",0,[_[0]]);if(e=_[0],r=_[1],o=_[2],h=_[3],a=_[4],this._originMode="center",Array.isArray(e)&&(e=void 0,r=void 0,o=_[0],h=_[1],a=_[2]),Array.isArray(o)||"string"==typeof h){if(isNaN(o)||(o=Number(o)),"number"!=typeof o&&Array.isArray(o[0])&&(this._originMode="start"),void 0!==h){if(Array.isArray(h))throw new v("Sprite",1,[`[[${o}], [${h}]]`]);!function(t){let e=t.slice(0,2);return"d"==t||"s"==t||"k"==t||"n"==t||"dy"==e||"st"==e||"ki"==e||"no"==e}(h)?o=d(o,h):a=h,h=void 0}}else isNaN(o)&&(a=o,o=void 0);this.idNum=this.p.p5play.spritesCreated,this._uid=1e3+this.idNum,this.p.p5play.sprites[this._uid]=this,this.p.p5play.spritesCreated++,this.groups=[],this.animations=new this.p.SpriteAnimations,this.joints=[],this.joints.removeAll=()=>{for(let t of this.joints)t.remove()},this._removed=!1,this._life=2147483647,this._visible=!0,this._pixelPerfect=!1,this._aniChangeCount=0,this._collides={},this._colliding={},this._collided={},this._hasOverlap={},this._overlaps={},this._overlapping={},this._overlapped={},this._collisions={},this._overlappers={},u??=this.p.allSprites,u.dynamic&&(a??="dynamic"),u.kinematic&&(a??="kinematic"),u.static&&(a??="static"),a??=u.collider,this._shape=u.shape,this.tileSize=u.tileSize||1;let f=this;if(this._position={x:0,y:0},this._pos=t.createVector.call(t),Object.defineProperty(this._pos,"x",{get(){if(!f.body)return f._position.x;let t=f.body.getPosition().x/f.tileSize*s;return n(t)},set(t){if(f.body){let e=new i.Vec2(t*f.tileSize/s,f.body.getPosition().y);f.body.setPosition(e)}f._position.x=t}}),Object.defineProperty(this._pos,"y",{get(){if(!f.body)return f._position.y;let t=f.body.getPosition().y/f.tileSize*s;return n(t)},set(t){if(f.body){let e=new i.Vec2(f.body.getPosition().x,t*f.tileSize/s);f.body.setPosition(e)}f._position.y=t}}),this._velocity={x:0,y:0},this._vel=t.createVector.call(t),Object.defineProperties(this._vel,{x:{get(){let t;return t=f.body?f.body.getLinearVelocity().x:f._velocity.x,n(t/f.tileSize)},set(t){t*=f.tileSize,f.body?f.body.setLinearVelocity(new i.Vec2(t,f.body.getLinearVelocity().y)):f._velocity.x=t}},y:{get(){let t;return t=f.body?f.body.getLinearVelocity().y:f._velocity.y,n(t/f.tileSize)},set(t){t*=f.tileSize,f.body?f.body.setLinearVelocity(new i.Vec2(f.body.getLinearVelocity().x,t)):f._velocity.y=t}}}),this._mirror={_x:1,_y:1,get x(){return this._x<0},set x(t){f.watch&&(f.mod[22]=!0),this._x=t?-1:1},get y(){return this._y<0},set y(t){f.watch&&(f.mod[22]=!0),this._y=t?-1:1}},this._heading="right",this._layer=u._layer,this._layer??=this.p.allSprites._getTopLayer()+1,a??=u.collider,a&&"string"==typeof a||(a="dynamic"),this.collider=a,e??=u.x,void 0===e&&(e=this.p.width/this.p.allSprites.tileSize/2,this._vertexMode=!0),r??=u.y,void 0===r&&(r=this.p.height/this.p.allSprites.tileSize/2),null==o&&(o=u.w||u.width||u.d||u.diameter,h??=u.h||u.height),"function"==typeof e&&(e=e(u.length)),"function"==typeof r&&(r=r(u.length)),"function"==typeof o&&(o=o(u.length)),"function"==typeof h&&(h=h(u.length)),this.x=e,this.y=r,!u._isAllSpritesGroup&&!c)for(let t in u.animations){c=t;break}for(let t=u;t;t=this.p.p5play.groups[t.parent])this.groups.push(t);if(this.groups.reverse(),c){c instanceof p5.Image?this.addAni(c):"string"==typeof c?this._changeAni(c):this._ani=c.clone();let t=this.tileSize;o||1==this._ani.w&&1==this._ani.h||(o=this._ani.w/t,"circle"!=this.shape&&(h=this._ani.h/t))}if(this.groups=[],this.mouse=new this.p._SpriteMouse,"none"!=this.collider)this._vertexMode?this.addCollider(o,h):this.addCollider(0,0,o,h);else{if(this.w=o||(this.tileSize>1?1:50),this.h=h||this.w,Array.isArray(o))throw new Error('Cannot set the collider type of a sprite with a polygon or chain shape to "none". Try having the sprite overlap with other sprites instead.');this._shape=void 0!==o&&void 0===h?"circle":"box"}u._isAllSpritesGroup||this.p.allSprites.push(this),u.push(this),this._scale=new l,Object.defineProperty(this._scale,"x",{get(){return this._x},set(t){if(t==this._x)return;f.watch&&(f.mod[28]=!0);let e=t/this._x;f._w*=e,f._hw*=e,f._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;f.watch&&(f.mod[28]=!0);let e=t/this._y;f._h&&(this._h*=e,this._hh*=e),f._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&&(f.watch&&(f.mod[23]=!0),f._offsetCenterBy(t-this._x,0))},get y(){return this._y},set y(t){t!=this._y&&(f.watch&&(f.mod[23]=!0),f._offsetCenterBy(0,t-this._y))}},this._angle=0,this._rotationSpeed=0,this._bearing=0,this.prevPos={x:e,y:r},this.prevRotation=0,this._dest={x:e,y:r},this._destIdx=0,this.drag=0,this.debug=!1,this._shift={};let g=u.vel.x||0,y=u.vel.y||0;"function"==typeof g&&(g=g(u.length-1)),"function"==typeof y&&(y=y(u.length-1)),this.vel.x=g,this.vel.y=y;let m=["ani","collider","vel","x","y","w","h","d","diameter","dynamic","height","kinematic","speed","static","width"];for(let t of this.p.Sprite.propsAll){if(m.includes(t))continue;let e=u[t];void 0!==e&&("function"==typeof e&&p(e)&&(e=e(u.length-1)),this[t]="object"==typeof e?Object.assign({},e):e)}m=["add","animation","animations","autoCull","contains","GroupSprite","Group","idNum","length","mod","mouse","p","parent","Sprite","Subgroup","subgroups","velocity"];for(let t=0;t1?1:50,o??=s),"box"!=a&&"circle"!=a||(l=r(s-.08,o-.08,this.tileSize)),"box"==a)p=i.Box(l.x/2,l.y/2,r(t,e,this.tileSize),0);else if("circle"==a)p=i.Circle(r(t,e,this.tileSize),l.x/2);else if(n){let c,_,f=[{x:0,y:0}],g={x:0,y:0},y={x:0,y:0},m={x:0,y:0},w=Array.isArray(n[0]);function x(){g.xm.x&&(m.x=g.x),g.y>m.y&&(m.y=g.y)}if(w){this._vertexMode&&(c=n[0][0],_=n[0][1],this.body?(c=this.x-this._relativeOrigin.x,_=this.y-this._relativeOrigin.y,f.pop()):(this.x=c,this.y=_));for(let b=0;b0?1:-1;S=Math.abs(S);let C=0;for(let k=0;ki.Settings.maxPolygonVertices||"chain"==this._shape)&&(a="chain"),"polygon"==a?p=i.Polygon(f):"chain"==a&&(p=i.Chain(f,!1))}return this._shape||(this._shape=a),this._w=s,this._hw=.5*s,"circle"==this._shape?this._diameter=s:(this._h=o,this._hh=.5*o),p}removeColliders(){this._collides={},this._colliding={},this._collided={},this._removeFixtures(!1)}removeSensors(){this._hasOverlap={},this._overlaps={},this._overlapping={},this._overlapped={},this._removeFixtures(!0)}_removeFixtures(t){let e;for(let i=this.fixtureList;i;i=i.getNext())if(void 0===t||i.m_isSensor==t){let t=i.m_next;i.destroyProxies(this.p.world.m_broadPhase),e?e.m_next=t:this.body.m_fixtureList=t}else e=i}_offsetCenterBy(t,e){if(!t&&!e)return;if(this._offset._x+=t,this._offset._y+=e,!this.body)return;let i=r(t,e,this.tileSize);for(let t=this.body.m_fixtureList;t;t=t.m_next){let e=t.m_shape;if("circle"!=e.m_type){let t=e.m_vertices;for(let e of t)e.x+=i.x,e.y+=i.y}else e.m_p.x+=i.x,e.m_p.y+=i.y}}_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.watch&&(this.mod[6]=!0),this._autoDraw=t}get allowSleeping(){return this.body?.isSleepingAllowed()}set allowSleeping(t){this.watch&&(this.mod[7]=!0),this.body&&this.body.setSleepingAllowed(t)}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){this.watch&&(this.mod[8]=!0),this._autoUpdate=t}get bounciness(){if(this.fixture)return this.fixture.getRestitution()}set bounciness(t){this.watch&&(this.mod[9]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setRestitution(t)}get centerOfMass(){let t=this.body.getWorldCenter(),e=o(t.x,t.y,this.tileSize);return this.p.createVector(e.x,e.y)}get collider(){return this._collider}set collider(t){let e=(t=t.toLowerCase())[0];if("d"==e&&(t="dynamic"),"s"==e&&(t="static"),"k"==e&&(t="kinematic"),"n"==e&&(t="none"),t==this._collider)return;if(this.__collider=["d","s","k","n"].indexOf(e),void 0===this._collider)return void(this._collider=t);if("none"==t&&("chain"==this._shape||"polygon"==this._shape))throw new Error('Cannot set the collider type of a polygon or chain collider to "none". Try having the sprite overlap with other sprites instead.');this.joints.length&&(this.joints.removeAll(),console.warn("Changing the collider type of a sprite that has joints will remove all its joints.")),this.watch&&(this.mod[10]=!0);let i=this._collider;this._collider=t,void 0!==i&&this._reset()}_reset(){let t,e=this._cloneBodyProps();"chain"!=this._shape&&"polygon"!=this._shape||(t=this._getVertices(!0),this._vertexMode=!0),this.body&&(this.p.world.destroyBody(this.body),this.body=void 0),"none"!=this._collider&&(t?this.addCollider(0,0,t):this.addCollider(),this._hasSensors&&this.addDefaultSensors());for(let t in e)void 0!==e[t]&&(this[t]=e[t]);let i=this._offset._x,s=this._offset._y;this._offset._x=0,this._offset._y=0,this._offsetCenterBy(i,s)}_parseColor(t){if(t instanceof p5.Color)return t;if("object"!=typeof t)return"string"==typeof t&&1==t.length?this.p.colorPal(t):this.p.color(t);if(t.levels)return this.p.color(...t.levels);if(void 0!==t._r)return this.p.color(t._r,t._g,t._b,255*t._a);if(void 0!==t._h)return this.p.color(t._h,t._s,t._v,255*t._a);throw new Error("Invalid color")}get color(){return this._color}set color(t){this.watch&&(this.mod[11]=!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[31]=!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[32]=!0),this._strokeWeight=t}get textColor(){return this._textColor}set textColor(t){this.watch&&(this.mod[34]=!0),this._textColor=this._parseColor(t)}get bearing(){return this._bearing}set bearing(t){this.watch&&(this.mod[39]=!0),this._bearing=t}get debug(){return this._debug}set debug(t){this.watch&&(this.mod[12]=!0),this._debug=t}get density(){if(this.fixture)return this.fixture.getDensity()}set density(t){this.watch&&(this.mod[13]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setDensity(t)}_getDirectionAngle(t){t=t.toLowerCase().replaceAll(/[ _-]/g,"");let e={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}[t];return"radians"==this.p._angleMode&&(e=this.p.radians(e)),e}get direction(){return 0!==this.vel.x||0!==this.vel.y?this.p.atan2(this.vel.y,this.vel.x):void 0===this._direction?this.rotation:this._direction}set direction(t){this.watch&&(this.mod[14]=!0),"string"==typeof t&&(this._heading=t,t=this._getDirectionAngle(t)),this._direction=t;let e=this.speed;this.vel.x=this.p.cos(t)*e,this.vel.y=this.p.sin(t)*e}get drag(){return this.body?.getLinearDamping()}set drag(t){this.watch&&(this.mod[15]=!0),this.body&&this.body.setLinearDamping(t)}get draw(){return this._display}set draw(t){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[16]=!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._ani?.frameImage}set img(t){this.changeAni(t)}get image(){return this._ani?.frameImage}set image(t){this.changeAni(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[18]=!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[19]=!0),this._layer=t}get life(){return this._life}set life(t){this.watch&&(this.mod[20]=!0),this._life=t}get mass(){return this.body?.getMass()}set mass(t){if(!this.body)return;this.watch&&(this.mod[21]=!0);let e=this.massData;e.mass=t>0?t:1e-8,this.body.setMassData(e),delete this._massUndef}get massData(){const t={I:0,center:new i.Vec2(0,0),mass:0};return this.body.getMassData(t),t.center=o(t.center.x,t.center.y,this.tileSize),t}resetMass(){this.body&&(this.watch&&(this.mod[21]=!0),this.body.resetMassData(),delete this._massUndef)}get mirror(){return this._mirror}set mirror(t){this.watch&&(this.mod[22]=!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[23]=!0),this._offsetCenterBy(t.x-this._offset._x,t.y-this._offset._y))}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[24]=!0),this._pixelPerfect=t}get rotation(){if(!this.body)return this._angle||0;let t=this.body.getAngle();return"degrees"===this.p._angleMode?this.p.degrees(t):t}set rotation(t){this.body?("degrees"===this.p._angleMode&&(t=this.p.radians(t)),this.body.setAngle(t)):this._angle=t}get rotationDrag(){return this.body?.getAngularDamping()}set rotationDrag(t){this.body&&(this.watch&&(this.mod[26]=!0),this.body.setAngularDamping(t))}get rotationLock(){return this.body?.isFixedRotation()}set rotationLock(t){this.body&&(this.watch&&(this.mod[27]=!0),this.body.setFixedRotation(t))}get rotationSpeed(){return this.body?this.body.getAngularVelocity():this._rotationSpeed}set rotationSpeed(t){this.body?this.body.setAngularVelocity(t):this._rotationSpeed=t}get scale(){return this._scale}set scale(t){if(t<=0&&(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[28]=!0);let e={x:t.x/this._scale._x,y: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[30]=!0),this.body.setAwake(!t))}get speed(){return this.p.createVector(this.vel.x,this.vel.y).mag()}set speed(t){let e=this.direction;this.vel.x=this.p.cos(e)*t,this.vel.y=this.p.sin(e)*t}get static(){return this.body?.isStatic()}set static(t){this.collider=t?"static":"dynamic"}get removed(){return this._removed}set removed(t){t&&!this._removed&&(this.watch&&(this.mod[25]=!0),this._removed=!0,this._remove())}get vertices(){return this._getVertices()}_getVertices(t){let e=this.fixture;for(;e.m_next&&!e.m_isSensor;)e=e.m_next;let i=e.getShape(),r=[...i.m_vertices];"polygon"==i.m_type&&r.unshift(r.at(-1));let o=this.x,h=this.y;for(let e=0;e=1e3?this.p.p5play.sprites[r]:this.p.p5play.groups[r];let o=i[s][r]+1;if(this[s][r]=o,t instanceof this.p.Group&&(t[s][i._uid]=o),t&&0!=o){if(!(t instanceof this.p.Group)){e=[],1!=o&&-2!=o||e.push(a[s][0]),-1!=o&&e.push(a[s][1]),-1!=o&&-2!=o||e.push(a[s][2]);for(let s of e){let e=this.p.world._findContact(s,i,t,!0);e&&e(i,t,o)}}}else delete i[s][r],t instanceof this.p.Group&&delete t[s][i._uid]}this.removed&&0==Object.keys(this._collisions).length&&0==Object.keys(this._overlappers).length&&delete this.p.p5play.sprites[this._uid]}_draw(){if(void 0!==this.strokeWeight&&this.p.strokeWeight(this.strokeWeight),this._ani?.draw&&"colliders"!=this.debug&&this._ani.draw(this._offset._x,this._offset._y,0,this._scale._x,this._scale._y),!this._ani||this.debug||this.p.p5play.disableImages)if(this.debug&&"colliders"!=this.debug&&(this.p.noFill(),this.p.stroke(0,255,0),this.p.line(0,-2,0,2),this.p.line(-2,0,2,0)),3!=this.__collider){"chain"==this._shape?this.p.stroke(this.stroke||this.color):this._stroke&&this.p.stroke(this._stroke);for(let t=this.fixtureList;t;t=t.getNext())t.m_isSensor&&!this.debug||this._drawFixture(t)}else this.p.stroke(this._stroke||120),"box"==this._shape?this.p.rect(this._offset._x,this._offset._y,this.w*this.tileSize,this.h*this.tileSize):"circle"==this._shape&&this.p.circle(this._offset._x,this._offset._y,this.d*this.tileSize);void 0!==this.text&&(this.p.textAlign(this.p.CENTER,this.p.CENTER),this.p.fill(this.textColor),this.p.textSize(this.textSize*this.tileSize),this.p.text(this.text,0,0))}_display(){let t=.5*this.p.width-this.p.world.origin.x+this.x*this.tileSize,e=.5*this.p.height-this.p.world.origin.y+this.y*this.tileSize,i=Math.max(this._w,this._h);if("chain"!=this.shape&&this.p.camera.active&&(t+ithis.p.camera.bound.max.x||e+ithis.p.camera.bound.max.y))this._visible=null;else{this._visible=!0,this.p.p5play.spritesDrawn++,this._pixelPerfect?(t=this._w%2==0?Math.round(t):Math.round(t-.5)+.5,e=this._h%2==0?Math.round(e):Math.round(e-.5)+.5):(t=n(t),e=n(e));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.layer1?(r=Math.round(r),o=Math.round(o)):e%90==0&&(r=n(r),o=n(o)),this.moveTo(r,o,i)}moveTo(e,i,s){if("number"!=typeof e){let t=e;if(t==this.p.mouse&&!this.p.mouse.active)return;if(!t||void 0===t.x||void 0===t.y)throw"sprite.moveTo ERROR: destination not defined.";s=i,i=t.y,e=t.x}if(this._dest.x=this.x,this._dest.y=this.y,e==this.x?e=!1:(this._dest.x=e,e=!0),i==this.y?i=!1:(this._dest.y=i,i=!0),this._destIdx++,!e&&!i)return Promise.resolve(!0);if(this.speed&&(s??=this.speed),this.tileSize>1&&(s??=.1),s??=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 n=this.direction,a=n-.1,l=n+.1,p=s+.01,d=this._destIdx,u=Math.max(this.p.world.velocityThreshold,.25*p)/this.tileSize;return(async()=>{let s=p+p,r=p+p;do{if(d!=this._destIdx)return!1;await t.delay();let e=this.direction;if(e<=a||e>=l||Math.abs(this.vel.x)<=u&&Math.abs(this.vel.y)<=u)return!1;s=Math.abs(this.x-this._dest.x),r=Math.abs(this.y-this._dest.y)}while(e&&s>p||i&&r>p);return s2&&(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(t,e){if("object"==typeof t){let i=t;if(i==this.p.mouse&&!this.p.mouse.active)return 0;if(void 0===i.x||void 0===i.y)return console.error("sprite.angleTo ERROR: rotation destination not defined, object given with no x or y properties"),0;e=i.y,t=i.x}return this.p.atan2(e-this.y,t-this.x)}angleToFace(t,e,i){if("object"==typeof t&&(i=e,e=t.y,t=t.x),Math.abs(t-this.x)<.01&&Math.abs(e-this.y)<.01)return 0;let s=this.angleTo(t,e);i??=0,s+=i;let r=s-this.rotation%360,o=360-Math.abs(r);return o*=r<0?1:-1,Math.abs(r)2&&(i=o[0],s=o[1],e=o[2],r=o[3]),void 0!==i)t=this.angleToFace(i,s,r);else{if(t==this.rotation)return;t-=this.rotation}return this.rotate(t,e)}rotate(e,i){if(1==this.__collider)throw new v(0);if(isNaN(e))throw new v(1,[e]);if(0==e)return;let s=Math.abs(e);i??=1,i>s&&(i=s);let r=this.rotation+e,o=e>0;this.rotationSpeed=i*(o?1:-1);let h=Math.floor(s/i)-1;this._rotateIdx??=0,this._rotateIdx++;let n=this._rotateIdx;return(async()=>{if(h>1){let e=Math.abs(this.rotationSpeed)+.01;do{if(this._rotateIdx!=n)return!1;if(await t.delay(),o&&this.rotationSpeed<.01||!o&&this.rotationSpeed>-.01)return!1}while((o&&r>this.rotation||!o&&r.01&&(this.rotationSpeed=r-this.rotation,await t.delay())}else await t.delay();return this._rotateIdx==n&&(this.rotationSpeed=0,this.rotation=r,!0)})()}async changeAni(t){if(this.p.p5play.disableImages)return;if(arguments.length>1)t=[...arguments];else if(t instanceof this.p.SpriteAnimation){if(t==this._ani)return;t=[t]}else if(!Array.isArray(t)){if(t==this._ani?.name)return;t=[t]}let e,i;this._aniChangeCount++;for(let s=0;s1&&("!"==r.name[0]&&(r.name=r.name.slice(1),r.start=-1,r.end=0),"<"!=r.name[0]&&">"!=r.name[0]||(r.name=r.name.slice(1),r.flipX=!0),"^"==r.name[0]&&(r.name=r.name.slice(1),r.flipY=!0),"**"==r.name&&(e=!0,t=t.slice(0,-1)),";;"==r.name&&(i=!0,t=t.slice(0,-1)))}let s=this._aniChangeCount;do{for(let e=0;e1&&(i.start=0),await this._playSequencedAni(i)}}while(e&&s==this._aniChangeCount);1!=t.length&&i&&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(t){this._ani?._onChange&&this._ani._onChange(),this._ani?.onChange&&this._ani.onChange();let e=this.animations[t];if(!e)for(let i=this.groups.length-1;i>=0;i--){if(e=this.groups[i].animations[t],e){e=e.clone();break}}if(!e)throw this.p.noLoop(),new v("Sprite.changeAnimation",[t]);this._ani=e,this._ani.name=t,this.resetAnimationsOnChange&&(this._ani.frame=0)}remove(){this.removed=!0}_remove(){this.body&&this.p.world.destroyBody(this.body),this.body=null;for(let t of this.groups)t.remove(this);0==Object.keys(this._collisions).length&&0==Object.keys(this._overlappers).length&&delete this.p.p5play.sprites[this._uid]}toString(){return"s"+this.idNum}_ensureCollide(t,e){if(!t)throw new v("Sprite.collide",2);if(!(t instanceof this.p.Sprite||t instanceof this.p.Group))throw new v("Sprite.collide",0,[t]);if(e&&"function"!=typeof e)throw new v("Sprite.collide",1,[e]);if(!1!==this._hasOverlap[t._uid]&&(this._hasOverlap[t._uid]=!1),!1!==t._hasOverlap[this._uid]&&(t._hasOverlap[this._uid]=!1,t instanceof this.p.Group))for(let e of t)e._hasOverlap[this._uid]=!1}collide(t,e){return this.collides(t,e)}collides(t,e){return this._ensureCollide(t,e),this._collides[t._uid]=e||!0,1==this._collisions[t._uid]}colliding(t,e){this._ensureCollide(t,e),this._colliding[t._uid]=e||!0;let i=this._collisions[t._uid];return i>0?i:0}collided(t,e){return this._ensureCollide(t,e),this._collided[t._uid]=e||!0,-1==this._collisions[t._uid]}_removeContactsWith(t){if(t instanceof this.p.Group)for(let e of t)this._removeContactsWith(e);else this.__removeContactsWith(t)}__removeContactsWith(t){if(this.body)for(let e=this.body.getContactList();e;e=e.next){let i=e.contact;i.m_fixtureA.m_body.sprite._uid!=t._uid&&i.m_fixtureB.m_body.sprite._uid!=t._uid||this.p.world.destroyContact(i)}}_ensureOverlap(t,e){if(!t)throw new v("Sprite.overlap",2);if(!(t instanceof this.p.Sprite||t instanceof this.p.Group))throw new v("Sprite.overlap",0,[t]);if(e&&"function"!=typeof e)throw new v("Sprite.overlap",1,[e]);if(this._hasSensors||this.addDefaultSensors(),!t._hasSensors)if(t instanceof this.p.Sprite)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),1!=t._hasOverlap[this._uid]&&(t._removeContactsWith(this),t._hasOverlap[this._uid]=!0,t instanceof this.p.Group))for(let e of t)e._hasOverlap[this._uid]=!0}overlap(t,e){return this.overlaps(t,e)}overlaps(t,e){return this._ensureOverlap(t,e),this._overlaps[t._uid]=e||!0,1==this._overlappers[t._uid]}overlapping(t,e){this._ensureOverlap(t,e),this._overlapping[t._uid]=e||!0;let i=this._overlappers[t._uid];return i>0?i:0}overlapped(t,e){return this._ensureOverlap(t,e),this._overlapped[t._uid]=e||!0,-1==this._overlappers[t._uid]}_sortFixtures(){let t=null,e=null;for(let i=this.fixtureList;i;i=i.getNext())i.m_isSensor?e?e.m_next=i:e=i:t?t.m_next=i:t=i;e&&(e.m_next=null),t&&(t.m_next=e),this.body.m_fixtureList=t||e}addDefaultSensors(){let t;if(this.body){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}},this.Sprite.propTypes={x:"Float64",y:"Float64",vel:"Vec2",rotation:"number",rotationSpeed:"number",ani:"string",autoDraw:"boolean",allowSleeping:"boolean",autoUpdate:"boolean",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",tile:"string",tileSize:"number",visible:"boolean",w:"number",bearing:"number"},this.Sprite.props=Object.keys(this.Sprite.propTypes),this.Sprite.propsAll=this.Sprite.props.concat(["d","diameter","dynamic","fill","height","heading","kinematic","resetAnimationsOnChange","speed","static","width"]),this.Sprite.colliderTypes=["d","s","k","n"],this.Sprite.shapeTypes=["box","circle","chain","polygon"],this.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=async function(){this._prevPos.x=this.x,this._prevPos.y=this.y,await s.call(this,...arguments)},i},this.SpriteAnimation=class extends Array{constructor(){super(),this.p=t;let e,i=[...arguments];if(this.name="default",(i[0]instanceof this.p.Sprite||i[0]instanceof this.p.Group)&&(e=i[0],i=i.slice(1),this._addedToSpriteOrGroup=!0),e??=this.p.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,this.looping??=!0,this.endOnFirstFrame=!1,this.frameChanged=!1,this.onComplete=this.onChange=null,this._onComplete=this._onChange=null,this.rotation=e.anis.rotation||0,this._scale=new l,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[i.length-1]||i[i.length-1]instanceof p5.Image)for(let s=0;s=3)throw new v("SpriteAnimation",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,n();else{let a;a="string"==typeof o?o:o.url,this.spriteSheet=this.p.loadImage(a,(()=>{n()}))}function n(){if(Array.isArray(r)||Array.isArray(r.frames)){if("number"!=typeof r[0]){let t=r;if(Array.isArray(r.frames)){t=r.frames,delete r.frames;for(let e=0;e=h.spriteSheet.width&&(u=0,c+=i,c>=h.spriteSheet.height&&(c=0))}}else{let p,d,u=i[0];if(isNaN(i[1])?p=i[1]:d=Number(i[1]),".png"!=u.slice(-4)||p&&".png"!=p.slice(-4))throw new v("SpriteAnimation",0,[u]);let c=0,_=0;for(let y=u.length-5;y>=0&&!isNaN(u.charAt(y));y--)c++;if(p)for(let m=p.length-5;m>=0&&!isNaN(p.charAt(m));m--)_++;let f,g=u.slice(0,-4-c);if(p&&(f=p.slice(0,-4-_)),p&&g!=f)this.push(this.p.loadImage(u)),this.push(this.p.loadImage(p));else{let w,x=parseInt(u.slice(-4-c,-4),10);if(d??=parseInt(p.slice(-4-_,-4),10),dthis.frame&&-1!==this.targetFrame?this.frame++:this.targetFrame=this.lastFrame?this.frame=0:this.frame++:this.frame{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.frame0?this.frame=this.frame-1:this.looping&&(this.frame=this.length-1),this.targetFrame=-1,this.playing=!1}goToFrame(t){if(!(t<0||t>=this.length))return this.targetFrame=t,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 t=this[this.frame];if(t instanceof p5.Image)return t;let{x:e,y:i,w:s,h:r}=t,o=createGraphics(s,r);return o.image(this.spriteSheet,this.offset.x,this.offset.y,s,r,e,i,s,r),o}get w(){return this.width}get width(){return this[this.frame]instanceof p5.Image?this[this.frame].width:this[this.frame]?this[this.frame].w:1}get h(){return this.height}get height(){return this[this.frame]instanceof p5.Image?this[this.frame].height:this[this.frame]?this[this.frame].h:1}get frames(){let t=[];for(let e=0;ee.#t[t],set(i){e.#t[t]=i;for(let s in e){let r=e[s];r instanceof SpriteAnimation&&(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 SpriteAnimation&&(o[t][i]=s)}}})}}},this.Group=class extends Array{constructor(...e){let i;if(e[0]instanceof t.Group&&(i=e[0],e=e.slice(1)),super(...e),this.p=t,"number"==typeof e[0])return;for(let t of this)if(!(t instanceof this.p.Sprite))throw new Error("A group can only contain sprites");if(this.idNum=this.p.p5play.groupsCreated,this._uid=this.idNum,this.p.p5play.groups[this._uid]=this,this.p.p5play.groupsCreated++,this.p.allSprites||(this._isAllSpritesGroup=!0),this.subgroups=[],i instanceof this.p.Group){i.subgroups.push(this);let t=i;do{t=this.p.p5play.groups[t.parent],t.subgroups.push(this)}while(!t._isAllSpritesGroup);this.parent=i._uid}else this._isAllSpritesGroup||(this.p.allSprites.subgroups.push(this),this.parent=0);this.animations=new this.p.SpriteAnimations,this._collides={},this._colliding={},this._collided={},this._hasOverlap={},this._overlaps={},this._overlapping={},this._overlapped={},this._collisions={},this._overlappers={};let s=this;this.Sprite=class extends this.p.Sprite{constructor(){super(s,...arguments)}},this.GroupSprite=this.Sprite,this.Group=class extends this.p.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};let r=[...this.p.Sprite.propsAll,"spriteSheet"];for(let t of r)"ani"!=t&&"velocity"!=t&&Object.defineProperty(this,t,{get(){let e=s["_"+t],i=s.length-1;if(void 0===e&&!s._isAllSpritesGroup){let r=this.p.p5play.groups[s.parent];r&&(e=r[t],i=r.length-1)}return e},set(e){s["_"+t]=e;for(let i=0;it&&(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._ani.frameImage}set img(t){this.ani=t}get image(){return this._ani.frameImage}set image(t){this.ani=t}set amount(t){let e=t-this.length,i=e>0;e=Math.abs(e);for(let t=0;t0?i:0}collided(t,e){return this._ensureCollide(t,e),this._collided[t._uid]=e||!0,-1==this._collisions[t._uid]}_removeContactsWith(t){for(let e of this)e._removeContactsWith(t)}_ensureOverlap(t,e){if(!t)throw new v("Group.overlap",2);if(!(t instanceof this.p.Sprite||t instanceof this.p.Group))throw new v("Group.overlap",0,[t]);if(e&&"function"!=typeof e)throw new v("Group.overlap",1,[e]);if(!this._hasSensors){for(let t of this)t._hasSensors||t.addDefaultSensors();this._hasSensors=!0}if(!t._hasSensors)if(t instanceof this.p.Sprite)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)e._hasOverlap[t._uid]=!0}if(1!=t._hasOverlap[this._uid]&&(t._removeContactsWith(this),t._hasOverlap[this._uid]=!0,t instanceof this.p.Group))for(let e of t)e._hasOverlap[this._uid]=!0}overlap(t,e){return this.overlaps(t,e)}overlaps(t,e){return this._ensureOverlap(t,e),this._overlaps[t._uid]=e||!0,1==this._overlappers[t._uid]}overlapping(t,e){this._ensureOverlap(t,e),this._overlapping[t._uid]=e||!0;let i=this._overlappers[t._uid];return i>0?i:0}overlapped(t,e){return this._ensureOverlap(t,e),this._overlapped[t._uid]=e||!0,-1==this._overlappers[t._uid]}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(t,e,i){if("number"!=typeof t){let s=t;if(s==this.p.mouse&&!this.p.mouse.active)return;i=e,e=s.y,t=s.x}let s=this._resetCentroid(),r=[];for(let o of this){let h={x:o.x-s.x+t,y:o.y-s.y+e};r.push(o.moveTo(h.x,h.y,i))}return Promise.all(r)}moveTowards(t,e,i){if("number"!=typeof t){let s=t;if(s==this.p.mouse&&!this.p.mouse.active)return;i=e,e=s.y,t=s.x}if(void 0!==t||void 0!==e){this._resetCentroid();for(let s of this){void 0===s.distCentroid&&this._resetDistancesFromCentroid();let r={x:s.distCentroid.x+t,y:s.distCentroid.y+e};s.moveTowards(r.x,r.y,i)}}}moveAway(t,e,i){if("number"!=typeof t){let s=t;if(s==this.p.mouse&&!this.p.mouse.active)return;i=e,e=s.y,t=s.x}if(void 0!==t||void 0!==e){this._resetCentroid();for(let s of this){void 0===s.distCentroid&&this._resetDistancesFromCentroid();let r={x:s.distCentroid.x+t,y:s.distCentroid.y+e};s.moveAway(r.x,r.y,i)}}}push(...t){for(let e of t){if(!(e instanceof this.p.Sprite))throw new Error("you can only add sprites to a group, no "+typeof e+"s");for(let t in this._hasOverlap){let i=this._hasOverlap[t];i&&!e._hasSensors&&e.addDefaultSensors(),e._hasOverlap[t]=i}super.push(e),this.parent&&this.p.p5play.groups[this.parent].push(e),e.groups.push(this)}return this.length}size(){return this.length}toString(){return"g"+this.idNum}cull(t,e,i,s,r){if(void 0===i){r=e,t=e=i=s=t}if(isNaN(t)||isNaN(e)||isNaN(i)||isNaN(s))throw new TypeError("The culling boundary must be defined with numbers");if(r&&"function"!=typeof r)throw new TypeError("The callback to group.cull must be a function");let o=this.p.camera.x-this.p.world.hw/this.p.camera.zoom,h=this.p.camera.y-this.p.world.hh/this.p.camera.zoom,n=-i+o,a=-t+h,l=this.p.width+s+o,p=this.p.height+e+h,d=0;for(let t=0;tl||e.y>p)&&(d++,r?r(e,d):e.remove(),e.removed&&t--))}return d}remove(t){if(void 0===t){for(;this.length>0;)this[0].remove();return}let e;if(e="number"==typeof t?t>=0?t:this.length+t:this.indexOf(t),-1!=e){let t=this[e];if(!t.removed){let e=t.groups.findIndex((t=>t._uid==this._uid));t.groups.splice(e,1)}return this.splice(e,1),t}throw new Error("Sprite not found in group")}removeAll(){this.remove()}draw(){let t=[...this];t.sort(((t,e)=>t._layer-e._layer));for(let e=0;e(t.getShape().testPoint(t.getBody().getTransform(),h)&&a.push(t),!0))),r??=this.p.allSprites;let l=[];if(a.length>0)for(let t of r)t.body&&a.includes(t.body.m_fixtureList)&&t._cameraActiveWhenDrawn==o&&l.push(t);return l}getSpriteAt(t,e,i){let s=this.getSpritesAt(t,e,i);return s.sort(((t,e)=>-1*(t._layer-e._layer))),s[0]}_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)&&(t[s][e._uid]=0,e[s][t._uid]=0);for(let t of e.groups){(!i[s][t._uid]||i[s][t._uid]<0)&&(t[s][i._uid]=0,i[s][t._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:-3,i[s][e._uid]=0!=i[s][e._uid]?-2:-3;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:-3,e[s][t._uid]=0!=e[s][t._uid]?-2:-3)}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:-3,i[s][t._uid]=0!=i[s][t._uid]?-2:-3;for(let e of i.groups)t[s][e._uid]=0!=t[s][e._uid]?-2:3,e[s][t._uid]=0!=e[s][t._uid]?-2:3}}}_findContact(t,e,i,s){let r=e[t][i._uid];if(r&&(!s||!0!==r))return r;let o=i instanceof this.p.Sprite;if(o)for(let o of i.groups)if(r=e[t][o._uid],r&&(!s||!0!==r))return r;if(e instanceof this.p.Sprite)for(let h of e.groups){if(r=h[t][i._uid],r&&(!s||!0!==r))return r;if(o)for(let o of i.groups)if(r=h[t][o._uid],r&&(!s||!0!==r)&&(h._uid!=o._uid||e._uid{for(let t=0;t0&&(t=t<.1?this.p.map(t,0,.1,30,4):t<.5?this.p.map(t,.1,.5,4,2.5):t<.8?this.p.map(t,.5,.8,2.5,1):t<.9?this.p.map(t,.8,.9,1,.5):this.p.map(t,.9,1,.5,.2)),this._springiness=t,"wheel"==this.type?this._j.setSpringFrequencyHz(t):this._j.setFrequency(t)}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}remove(){this._removed||(this.spriteA.joints.splice(this.spriteA.joints.indexOf(this),1),this.spriteB.joints.splice(this.spriteB.joints.indexOf(this),1),this.p.world.destroyJoint(this._j),this._removed=!0)}},this.GlueJoint=class extends this.Joint{constructor(t,e){super(...arguments,"glue")}},this.DistanceJoint=class extends this.Joint{constructor(t,e){super(...arguments,"distance");let s=i.DistanceJoint({},t.body,e.body,t.body.getWorldCenter(),e.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=o(t.x,t.y,this.spriteA.tileSize)),(this.offsetB.x||this.offsetB.y)&&(e=this.spriteB.body.getWorldPoint(this._j.m_localAnchorB),e=o(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 this.Joint{constructor(t,e){super(...arguments,"wheel");let s=i.WheelJoint({maxMotorTorque:1e3,frequencyHz:4,dampingRatio:.7},t.body,e.body,e.body.getWorldCenter(),new i.Vec2(0,1));this._createJoint(s),this._angle="degrees"==this.p._angleMode?90:1.5707963267948966}_display(){let t,e,i=this.spriteA.x,s=this.spriteA.y;if(this.offsetB.x||this.offsetB.y){let i=this.spriteB.body.getWorldPoint(this._j.m_localAnchorB);i=o(i.x,i.y,this.spriteB.tileSize),t=i.x,e=i.y}else t=this.spriteB.x,e=this.spriteB.y;let r=this.p.tan(this.spriteA.rotation),h=this.p.tan(this._angle+this.spriteA.rotation),n=(e-s+r*i-h*t)/(r-h),a=r*(n-i)+s;this._draw(n,a,t,e),this.visible=null}get angle(){return this._angle}set angle(t){t!=this._angle&&(this._angle=t,this._j.m_localXAxisA=new i.Vec2(this.p.cos(t),this.p.sin(t)),this._j.m_localXAxisA.normalize(),this._j.m_localYAxisA=i.Vec2.crossNumVec2(1,this._j.m_localXAxisA))}},this.HingeJoint=class extends this.Joint{constructor(t,e){super(...arguments,"hinge");let s=i.RevoluteJoint({},t.body,e.body,t.body.getWorldCenter());this._createJoint(s)}_display(){const t=this.offsetA.x,e=this.offsetA.y,i=this.spriteA.rotation,s=t*this.p.cos(i)-e*this.p.sin(i),r=t*this.p.sin(i)+e*this.p.cos(i);this._draw(this.spriteA.x+s,this.spriteA.y+r),this.visible=null}get range(){return this.upperLimit-this.lowerLimit}set range(t){t/=2,this.upperLimit=t,this.lowerLimit=-t}get lowerLimit(){let t=this._j.getLowerLimit();return"radians"==this.p._angleMode?t:this.p.degrees(t)}set lowerLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),this.spriteA.body.setAwake(!0),this.spriteB.body.setAwake(!0),"degrees"==this.p._angleMode&&(t=this.p.radians(t)),this._j.m_lowerAngle=t}get upperLimit(){let t=this._j.getUpperLimit();return"radians"==this.p._angleMode?t:this.p.degrees(t)}set upperLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),this.spriteA.body.setAwake(!0),this.spriteB.body.setAwake(!0),"degrees"==this.p._angleMode&&(t=this.p.radians(t)),this._j.m_upperAngle=t}get angle(){let e=this._j.getJointAngle();return"radians"==this.p._angleMode?e:t.radians(e)}},this.RevoluteJoint=this.HingeJoint,this.SliderJoint=class extends this.Joint{constructor(t,e){super(...arguments,"slider");let s=i.PrismaticJoint({lowerTranslation:-1,upperTranslation:1,enableLimit:!0,maxMotorForce:50,motorSpeed:0,enableMotor:!0},t.body,e.body,t.body.getWorldCenter(),new i.Vec2(1,0));this._createJoint(s),this._angle=0}get angle(){return this._angle}set angle(t){t!=this._angle&&(this._angle=t,this._j.m_localXAxisA=new i.Vec2(this.p.cos(t),this.p.sin(t)),this._j.m_localXAxisA.normalize(),this._j.m_localYAxisA=i.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*s}set lowerLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),t=t*this.spriteA.tileSize/s,this._j.setLimits(t,this._j.getUpperLimit())}get upperLimit(){return this._j.getUpperLimit()/this.spriteA.tileSize*s}set upperLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),t=t*this.spriteA.tileSize/s,this._j.setLimits(this._j.getLowerLimit(),t)}},this.PrismaticJoint=this.SliderJoint,this.RopeJoint=class extends this.Joint{constructor(t,e){super(...arguments,"rope");let s=i.RopeJoint({maxLength:1},t.body,e.body,t.body.getWorldCenter());this._createJoint(s),this._j.m_localAnchorB.x=0,this._j.m_localAnchorB.y=0}get maxLength(){return t=this._j.getMaxLength(),e=this.spriteA.tileSize,t/e*s;var t,e}set maxLength(t){var e,i;this._j.setMaxLength((e=t,i=this.spriteA.tileSize,e*i/s))}};class l{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(){let t=new Float32Array(1),e=new Int32Array(t.buffer)}();function p(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 d(t,e){return"triangle"==e?t=[t,-120,3]:"square"==e?t=[t,-90,4]:"pentagon"==e?t=[t,-72,5]:"hexagon"==e?t=[t,-60,6]:"septagon"==e?t=[t,-51.4285714286,7]:"octagon"==e?t=[t,-45,8]:"enneagon"==e?t=[t,-40,9]:"decagon"==e?t=[t,-36,10]:"hendecagon"==e?t=[t,-32.7272727273,11]:"dodecagon"==e&&(t=[t,-30,12]),t}this.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;let s;return"number"==typeof i&&(i=t.p5play.palettes[i]),i??=t.p5play.palettes[0],i&&(s=i[e]),""===s||"."===e||" "===e?t.color(0,0,0,0):t.color(s||e)},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,n=t.createImage(o*i,h*i);n.loadPixels();for(let t=0;tnew Promise(t?e=>{setTimeout(e,t)}:requestAnimationFrame),this.sleep=t=>this.delay(t),this.play=t=>{if(!t.play)throw new Error("Tried to play your input but it wasn't a sound object: "+t);return new Promise(((e,i)=>{t.play(),t.onended((()=>e()))}))},this.p5play.playIntro=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.src="https://p5play.org/v3/made_with_p5play.png",i.style="position: absolute; top: 50%; left: 50%; width: 40vh; height: 20vh; margin-left: -20vh; margin-top: -10vh; z-index: 1000; opacity: 0; transition: opacity 0.1s ease-in-out;",document.body.append(e),e.append(i),await t.delay(100),i.style.opacity="1",i.style.transition="scale 1.4s, opacity 0.4s ease-in-out",i.style.scale="1.1",await t.delay(1100),i.style.opacity="0",await t.delay(300),e.style.display="none",e.remove(),document.getElementById("p5play-intro")?.remove(),t._decrementPreload()};{let t=location.hostname;switch(t){case"":case"127.0.0.1":case"localhost":case"p5play.org":case"editor.p5js.org":case"codepen.io":case"codera.app":case"cdpn.io":case"glitch.com":case"replit.com":case"stackblitz.com":case"jsfiddle.net":case"aijs-912fe.web.app":break;default:if(/^[\d\.]+$/.test(t)||t.endsWith("stackblitz.io")||t.endsWith("glitch.me")||t.endsWith("repl.co")||t.endsWith("codehs.com")||t.endsWith("openprocessing.org")||location.origin.endsWith("preview.p5js.org"))break;this.p5play.playIntro()}}let u=p5.disableFriendlyErrors;p5.disableFriendlyErrors=!0,this.canvas=this.canvas;const c=this.createCanvas;this.createCanvas=function(){let e,i,s,r,o=[...arguments],h=!1,n=!1;if("string"==typeof o[0]&&(o[0].includes(":")?s=o[0].split(":"):(o[2]=o[0],o[0]=void 0),"fullscreen"==o[1]&&(h=!0)),o[0]?"number"==typeof o[0]&&"number"!=typeof o[1]&&(o[2]=o[1],o[1]=o[0]):(o[0]=window.innerWidth,o[1]=window.innerHeight,h=!0),"string"==typeof o[2]){let t=o[2].toLowerCase();"p2d"!=t&&"webgl"!=t&&(t=t.split(" "),o.pop()),"pixelated"==t[0]&&(n=!0,t[1]?r=Number(t[1].slice(1)):h=!0,s=[o[0],o[1]]),"fullscreen"==t[0]&&(h=!0)}if(s){let t=Number(s[0]),h=Number(s[1]);r?(e=t*r,i=h*r):(e=window.innerWidth,i=window.innerWidth*(h/t),i>window.innerHeight&&(e=window.innerHeight*(t/h),i=window.innerHeight)),e=Math.round(e),i=Math.round(i),n||(o[0]=e,o[1]=i)}let a=c.call(t,...o);this.canvas.tabIndex=0,this.canvas.w=o[0],this.canvas.h=o[1],this.canvas.addEventListener("keydown",(function(t){" "!=t.key&&"/"!=t.key&&"ArrowUp"!=t.key&&"ArrowDown"!=t.key&&"ArrowLeft"!=t.key&&"ArrowRight"!=t.key||t.preventDefault()})),this.canvas.addEventListener("mouseover",(()=>{this.mouse.isOnCanvas=!0,this.mouse.active=!0})),this.canvas.addEventListener("mouseleave",(()=>{this.mouse.isOnCanvas=!1})),this.canvas.addEventListener("touchstart",(t=>t.preventDefault())),this.canvas.addEventListener("contextmenu",(t=>t.preventDefault())),this.canvas.resize=this.resizeCanvas,this.world.resize(),this.camera.x=this.world.hw,this.camera.y=this.world.hh,u||(p5.disableFriendlyErrors=!1);let l="\n.p5Canvas, .q5Canvas {\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}\nmain {\n\toverscroll-behavior: none;\n}";h&&(l="html,\nbody,\n"+l,l+="\nhtml, body {\n\tmargin: 0;\n\tpadding: 0;\n\toverflow: hidden;\n\theight: 100%;\n}\nmain {\n\tmargin: auto;\n\tdisplay: flex;\n\tflex-wrap: wrap;\n\talign-content: center;\n\tjustify-content: center;\n\theight: 100%;\n}"),n&&(l+=`\n#${this.canvas.id} {\n\timage-rendering: pixelated;\n\twidth: ${e}px!important;\n\theight: ${i}px!important;\n}`);let p=document.createElement("style");p.innerHTML=l,document.head.appendChild(p),n&&(t.pixelDensity(1),t.noSmooth());let d=navigator.userAgent.indexOf("iPhone OS");if(d>-1){let e=navigator.userAgent.substring(d+10,d+12);this.p5play.version=e,e<16&&t.pixelDensity(1),this.p5play.os.platform="iOS",this.p5play.os.version=e}else void 0!==navigator.userAgentData&&(this.p5play.os.platform=navigator.userAgentData.platform);return a},this.Canvas=class{constructor(t,e,i){}get w(){}get width(){}get h(){}get height(){}resize(){}},this.Canvas=function(){return t.createCanvas(...arguments)};const _=this.resizeCanvas;this.resizeCanvas=(t,e)=>{_.call(this,t,e),this.world.resize(),this.camera._pos.x=this.world.hw,this.camera._pos.y=this.world.hh};const f=this.background;this.background=function(){let t,e=arguments;1==e.length&&("string"==typeof e[0]||e[0]instanceof p5.Color)&&(t=this.colorPal(e[0])),void 0!==t?f.call(this,t):f.call(this,...e)};const g=this.fill;this.fill=function(){let t,e=arguments;1==e.length&&(t=this.colorPal(e[0])),void 0!==t?g.call(this,t):g.call(this,...e)};const y=this.stroke;this.stroke=function(){let t,e=arguments;1==e.length&&(t=this.colorPal(e[0])),void 0!==t?y.call(this,t):y.call(this,...e)},this.p5play.images={onLoad:t=>{}},this.p5play.disableImages=!1;const m=this.loadImage;this.loadImage=this.loadImg=function(){if(this.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 1==r.width&&1==r.height||!r.pixels.length?e?(r.cbs.push(e),r.calls++):t._decrementPreload():(e&&e(),t._decrementPreload()),r;return r=m.call(t,s,(e=>{e.w=e.width,e.h=e.height;for(let t of e.cbs)t(e);for(let i=1;ii[e])),o+=h,p5._friendlyError(o,t)}}this.allSprites=new this.Group,this.world=new this.World,this.camera=new this.Camera,this.InputDevice=class{constructor(){this.holdThreshold=12}init(t){for(let e of t)this[e]=0}ac(t){return t}presses(t){return t??=this.default,void 0===this[t]&&(t=this.ac(t)),1==this[t]||-2==this[t]}pressing(t){return t??=this.default,void 0===this[t]&&(t=this.ac(t)),-2==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)),-3==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 this.InputDevice{constructor(){super();let t=this;this._position={get x(){return t.x},set x(e){t.x=e},get y(){return t.y},set y(e){t.y=e}};this.init(["x","y","left","center","right"]),this.default="left",this.drag={left:0,center:0,right:0},this.isOnCanvas=!1,this.active=!1,this.x,this.y,this._visible=!0,this._cursor="default"}get pos(){return this._position}get position(){return this._position}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"}ac(t){return t=t.slice(0,4)?"left":"right"==t.slice(0,5)?"right":"middle"==t.slice(0,6)?"center":t.toLowerCase()}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,-1==this.drag[t]}},this.mouse=new this._Mouse,this._SpriteMouse=class extends this._Mouse{constructor(){super(),this.hover=0}hovers(){return 1==this.hover}hovering(){return this.hover>0?this.hover:0}hovered(){return-1==this.hover}};const b=function(t){if(this.mouse[t]++,this.mouse.active=!0,this.world.mouseSprites.length){let e=this.world.mouseSprite;e&&(e.mouse[t]=0,e.mouse.drag[t]=0),e=this.world.mouseSprites[0],e.mouse[t]=1,this.world.mouseSprite=e}},S=t._onmousedown;t._onmousedown=function(t){let e="left";1===t.button?e="center":2===t.button&&(e="right"),b.call(this,e),S.call(this,t)};const A=t._ontouchstart;t._ontouchstart=function(t){b.call(this,"left"),A.call(this,t)};const C=function(t){let e=this.mouse;if(e[t]>0&&e.drag[t]<=0){e.drag[t]=1,e._isDragging=!0;let i=this.world.mouseSprite?.mouse;i&&(i.drag[t]=1,i._isDragging=!0)}},k=t._onmousemove;t._onmousemove=function(t){let e="left";1===t.button?e="center":2===t.button&&(e="right"),C.call(this,e),k.call(this,t)};const z=function(t){let e=this.mouse;e[t]>=e.holdThreshold?e[t]=-3:e[t]>1?e[t]=-1:e[t]=-2;let i=this.world.mouseSprite?.mouse;i&&(i.hover>1?(i[t]>=this.mouse.holdThreshold?i[t]=-3:i[t]>1?i[t]=-1:i[t]=-2,i.drag[t]>0&&(i.drag[t]=i[t])):(i[t]=0,i.drag[t]=0))},j=t._onmouseup;t._onmouseup=function(t){let e="left";1===t.button?e="center":2===t.button&&(e="right"),z.call(this,e),j.call(this,t)};const M=t._ontouchend;if(t._ontouchend=function(t){z.call(this,"left"),M.call(this,t)},delete this._Mouse,this._KeyBoard=class extends this.InputDevice{constructor(){super(),this.default=" "}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," ")}return t.toLowerCase()}_pre(t){(!this[t]||this[t]<0)&&(this[t]=1)}_rel(t){this[t]>=this.holdThreshold?this[t]=-3:this[t]>1?this[t]=-1:this[t]=-2}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}get arrowup(){return this.arrowUp}get arrowdown(){return this.arrowDown}get arrowleft(){return this.arrowLeft}get arrowright(){return this.arrowRight}get capslock(){return this.capsLock}},this.kb=new this._KeyBoard,delete this._KeyBoard,this.keyboard=this.kb,navigator.keyboard){const t=navigator.keyboard;window==window.top?t.getLayoutMap().then((t=>{"w"!=t.get("KeyW")&&(this.p5play.standardizeKeyboard=!0)})):this.p5play.standardizeKeyboard=!0}else this.p5play.standardizeKeyboard=!0;function T(t){let e=t.code;return 4==e.length&&"Key"==e.slice(0,3)?e[3].toLowerCase():t.key}let L={arrowUp:"up",arrowDown:"down",arrowLeft:"left",arrowRight:"right"};{let t=L;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"}const D=t._onkeydown;t._onkeydown=function(t){let e=t.key;if(this.p5play.standardizeKeyboard&&(e=T(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=L[e];i&&this.kb._pre(i),D.call(this,t)};const P=t._onkeyup;t._onkeyup=function(t){let e=t.key;if(this.p5play.standardizeKeyboard&&(e=T(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=L[e];if(i&&this.kb._rel(i),t.shiftKey){let t=e.toLowerCase();this.kb[t]>0&&this.kb._rel(t)}P.call(this,t)},this._Contro=class extends this.InputDevice{constructor(t){super();this.init(["a","b","x","y","l","r","lt","rt","select","start","up","down","left","right","leftTrigger","rightTrigger"]),this.leftStick={x:0,y:0,btn:0},this.rightStick={x:0,y:0,btn:0},this._btns={a:0,b:1,x:2,y:3,l:4,r:5,lt:6,rt:7,select:8,start:9,leftStickButton:10,rightStickButton:11,up:12,down:13,left:14,right:15},this._axes={leftStick:{x:0,y:1},rightStick:{x:2,y:3},leftTrigger:4,rightTrigger:5},t.id.includes("GuliKit")&&(this._btns.a=1,this._btns.b=0,this._btns.x=3,this._btns.y=2),e(t),this.gamepad=t,this.id=t.id}ac(t){return t.toLowerCase()}_update(){if(this.gamepad=navigator.getGamepads()[this.gamepad.index],!this.gamepad)return;let t=this.gamepad;for(let e in this._btns){let i=this._btns[e];t.buttons[i].pressed?this[e]++:this[e]=this[e]>0?-1:0}return this.leftStick.x=t.axes[this._axes.leftStick.x],this.leftStick.y=t.axes[this._axes.leftStick.y],this.rightStick.x=t.axes[this._axes.rightStick.x],this.rightStick.y=t.axes[this._axes.rightStick.y],void 0!==t.axes[this._axes.leftTrigger]?(this.leftTrigger=t.axes[this._axes.leftTrigger],this.rightTrigger=t.axes[this._axes.rightTrigger]):(this.leftTrigger=t.buttons[this._btns.lt].value,this.rightTrigger=t.buttons[this._btns.rt].value),!0}},this._Contros=class extends Array{constructor(){super();let t=this;window.addEventListener("gamepadconnected",(e=>{t._addContro(e.gamepad)})),window.addEventListener("gamepaddisconnected",(e=>{t._removeContro(e.gamepad)})),this.default="a";let e=["presses","pressing","pressed","holds","holding","held","released"];for(let t of e)this[t]=e=>{if(this[0])return this[0][t](e)};let i=["a","b","x","y","l","r","lt","rt","select","start","leftStickButton","rightStickButton","up","down","left","right"];for(let e of i)Object.defineProperty(this,e,{get:()=>t[0]?t[0][e]:0});let s=["leftStick","rightStick"];for(let e of s){this[e]={};for(let i of["x","y"])Object.defineProperty(this[e],i,{get:()=>t[0]?t[0][e][i]:0})}if(!navigator?.getGamepads)return;let r=navigator.getGamepads();for(let t of r)t&&this._addContro(t)}_addContro(i){i&&(e("controller "+this.length+" connected: "+i.id),this.push(new t._Contro(i)))}_removeContro(t){if(t){e("controller "+this.length+" disconnected: "+t.id);for(let e=0;ethis.p5play._fps,this.p5play._fpsArr=[60],this.renderStats=(t,e)=>{let i=this.p5play._renderStats;void 0===i.show&&(1==this.allSprites.tileSize||this.allSprites.tileSize>16?i.fontSize=16:i.fontSize=10,i.gap=1.25*i.fontSize,console.warn("renderStats() uses inaccurate FPS approximations. Even if your game runs at a solid 60hz display rate, the fps calculations shown may be lower. The only way to get accurate results is to use your web browser's performance testing tools.")),i.x=t||10,i.y=e||20,i.show=!0}})),p5.prototype.registerMethod("pre",(function(){this.p5play._fps&&(this.p5play._preDrawFrameTime=performance.now()),this.p5play.spritesDrawn=0,this.mouse.x=(this.mouseX-this.world.hw)/this.camera.zoom+this.camera.x,this.mouse.y=(this.mouseY-this.world.hh)/this.camera.zoom+this.camera.y,this.camera.mouse.x=this.mouseX,this.camera.mouse.y=this.mouseY,this.contro._update()})),p5.prototype.registerMethod("post",(function(){this.p5play._inPostDraw=!0,this.allSprites.autoCull&&this.allSprites.cull(1e4),this.allSprites._autoDraw&&(this.camera.on(),this.allSprites.draw(),this.camera.off()),this.allSprites._autoDraw??=!0;let t=this.p5play._renderStats;if(t.show){if(1==this.frameCount||this.frameCount%60==0){let t,e=this.p5play._fpsArr.reduce(((t,e)=>t+e));e=Math.round(e/this.p5play._fpsArr.length),this.p5play._fpsAvg=e,this.p5play._fpsMin=Math.min(...this.p5play._fpsArr),this.p5play._fpsMax=Math.max(...this.p5play._fpsArr),this.p5play._fpsArr=[],t=e>55?this.color(30,255,30):e>25?this.color(255,100,30):this.color(255,30,30),this.p5play._statsColor=t}this.p5play._fpsArr.push(this.getFPS()),this.push(),this.fill(0,0,0,128),this.rect(t.x-5,t.y-t.fontSize,8.5*t.fontSize,4*t.gap+5),this.fill(this.p5play._statsColor),this.textSize(t.fontSize),this.textFont("monospace");let e=t.x,i=t.y;this.text("sprites: "+this.p5play.spritesDrawn,e,i),this.text("fps avg: "+this.p5play._fpsAvg,e,i+t.gap),this.text("fps min: "+this.p5play._fpsMin,e,i+2*t.gap),this.text("fps max: "+this.p5play._fpsMax,e,i+3*t.gap),this.pop(),t.show=!1}this.world.autoStep&&this.world.step(),this.world.autoStep??=!0,this.allSprites._autoUpdate&&this.allSprites.update(),this.allSprites._autoUpdate??=!0;for(let t of this.allSprites)t.autoDraw??=!0,t.autoUpdate??=!0;for(let t in this.kb)"holdThreshold"!=t&&(this.kb[t]<0?this.kb[t]=0:this.kb[t]>0&&this.kb[t]++);let e=this.mouse,i=this.world.mouseSprite?.mouse;for(let t of["left","center","right"])e[t]<0?e[t]=0:e[t]>0&&e[t]++,i&&(i[t]=e[t]);if(this.world.mouseTracking){let t=this.world.getSpritesAt(e.x,e.y);t.sort(((t,e)=>-1*(t._layer-e._layer)));let s=this.world.getSpritesAt(this.camera.mouse.x,this.camera.mouse.y,this.allSprites,!1);s.sort(((t,e)=>-1*(t._layer-e._layer))),t=t.concat(s);for(let e=0;e0?i.mouse.hover=-1:i.mouse.hover<0&&(i.mouse.hover=0):i.mouse.hover++}let r=this.world.mouseSprite;if(e.left<=0&&e.center<=0&&e.right<=0)r=null,this.world.mouseSprite=null;else for(let t of["left","center","right"])e.drag[t]<0?e.drag[t]=0:e.drag[t]>0&&e.drag[t]++,i&&(i.drag[t]=e.drag[t],i.x=r.x-e.x,i.y=r.y-e.y);for(let e of this.world.mouseSprites)if(!(i?._isDragging&&e==r||t.includes(e))){let t=e.mouse;t.hover=-1,t.left=t.center=t.right=0}this.world.mouseSprites=t}this.camera.off(),this.p5play._fps&&(this.p5play._postDrawFrameTime=performance.now(),this.p5play._fps=Math.round(1e3/(this.p5play._postDrawFrameTime-this.p5play._preDrawFrameTime))||1),this.p5play._inPostDraw=!1})); +p5.prototype.registerMethod("init",(function(){if(void 0===window.planck)throw"planck.js must be loaded before p5play";const t=this,e=console.log;this.log=console.log;const i=planck,s=60;if(this.p5play??={},this.p5play.os??={},this.p5play.context??="web",this.p5play.standardizeKeyboard??=!1,this.p5play.sprites={},this.p5play.groups={},this.p5play.groupsCreated=0,this.p5play.spritesCreated=0,this.p5play.spritesDrawn=0,this.p5play._renderStats={},this.p5play.disableImages=!1,void 0===window._p5play_gtagged&&"undefined"==typeof process){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_12")}}this.angleMode("degrees");const r=(t,e,r)=>new i.Vec2(t*r/s,e*r/s),o=(t,e,r)=>new i.Vec2(t/r*s,e/r*s),h=t=>Math.abs(t)<=i.Settings.linearSlop,n=t=>Math.abs(t-Math.round(t))<=i.Settings.linearSlop?Math.round(t):t,a={_collisions:["_collides","_colliding","_collided"],_overlappers:["_overlaps","_overlapping","_overlapped"]};this.Sprite=class{constructor(e,r,o,h,a){this.p=t,this.idNum,this.watch,this.mod=[];let u,c,_=[...arguments];if(void 0!==_[0]&&_[0]instanceof this.p.Group&&(u=_[0],_=_.slice(1)),_.length||(this._noArgs=!0),void 0!==_[0]&&isNaN(_[0])&&("string"==typeof _[0]||_[0]instanceof this.p.SpriteAnimation||_[0]instanceof p5.Image)&&(c=_[0],_=_.slice(1)),1==_.length&&"number"==typeof _[0])throw new v("Sprite",0,[_[0]]);if(e=_[0],r=_[1],o=_[2],h=_[3],a=_[4],this._originMode="center",Array.isArray(e)&&(e=void 0,r=void 0,o=_[0],h=_[1],a=_[2]),Array.isArray(o)||"string"==typeof h){if(isNaN(o)||(o=Number(o)),"number"!=typeof o&&Array.isArray(o[0])&&(this._originMode="start"),void 0!==h){if(Array.isArray(h))throw new v("Sprite",1,[`[[${o}], [${h}]]`]);!function(t){let e=t.slice(0,2);return"d"==t||"s"==t||"k"==t||"n"==t||"dy"==e||"st"==e||"ki"==e||"no"==e}(h)?o=d(o,h):a=h,h=void 0}}else isNaN(o)&&(a=o,o=void 0);this.idNum=this.p.p5play.spritesCreated,this._uid=1e3+this.idNum,this.p.p5play.sprites[this._uid]=this,this.p.p5play.spritesCreated++,this.groups=[],this.animations=new this.p.SpriteAnimations,this.joints=[],this.joints.removeAll=()=>{for(let t of this.joints)t.remove()},this._removed=!1,this._life=2147483647,this._visible=!0,this._pixelPerfect=!1,this._aniChangeCount=0,this._collides={},this._colliding={},this._collided={},this._hasOverlap={},this._overlaps={},this._overlapping={},this._overlapped={},this._collisions={},this._overlappers={},u??=this.p.allSprites,u.dynamic&&(a??="dynamic"),u.kinematic&&(a??="kinematic"),u.static&&(a??="static"),a??=u.collider,this._shape=u.shape,this.tileSize=u.tileSize||1;let f=this;if(this._position={x:0,y:0},this._pos=t.createVector.call(t),Object.defineProperty(this._pos,"x",{get(){if(!f.body)return f._position.x;let t=f.body.getPosition().x/f.tileSize*s;return n(t)},set(t){if(f.body){let e=new i.Vec2(t*f.tileSize/s,f.body.getPosition().y);f.body.setPosition(e)}f._position.x=t}}),Object.defineProperty(this._pos,"y",{get(){if(!f.body)return f._position.y;let t=f.body.getPosition().y/f.tileSize*s;return n(t)},set(t){if(f.body){let e=new i.Vec2(f.body.getPosition().x,t*f.tileSize/s);f.body.setPosition(e)}f._position.y=t}}),this._velocity={x:0,y:0},this._vel=t.createVector.call(t),Object.defineProperties(this._vel,{x:{get(){let t;return t=f.body?f.body.getLinearVelocity().x:f._velocity.x,n(t/f.tileSize)},set(t){t*=f.tileSize,f.body?f.body.setLinearVelocity(new i.Vec2(t,f.body.getLinearVelocity().y)):f._velocity.x=t}},y:{get(){let t;return t=f.body?f.body.getLinearVelocity().y:f._velocity.y,n(t/f.tileSize)},set(t){t*=f.tileSize,f.body?f.body.setLinearVelocity(new i.Vec2(f.body.getLinearVelocity().x,t)):f._velocity.y=t}}}),this._mirror={_x:1,_y:1,get x(){return this._x<0},set x(t){f.watch&&(f.mod[22]=!0),this._x=t?-1:1},get y(){return this._y<0},set y(t){f.watch&&(f.mod[22]=!0),this._y=t?-1:1}},this._heading="right",this._layer=u._layer,this._layer??=this.p.allSprites._getTopLayer()+1,a??=u.collider,a&&"string"==typeof a||(a="dynamic"),this.collider=a,e??=u.x,void 0===e&&(e=this.p.width/this.p.allSprites.tileSize/2,this._vertexMode=!0),r??=u.y,void 0===r&&(r=this.p.height/this.p.allSprites.tileSize/2),null==o&&(o=u.w||u.width||u.d||u.diameter,h??=u.h||u.height),"function"==typeof e&&(e=e(u.length)),"function"==typeof r&&(r=r(u.length)),"function"==typeof o&&(o=o(u.length)),"function"==typeof h&&(h=h(u.length)),this.x=e,this.y=r,!u._isAllSpritesGroup&&!c)for(let t in u.animations){c=t;break}for(let t=u;t;t=this.p.p5play.groups[t.parent])this.groups.push(t);if(this.groups.reverse(),c){c instanceof p5.Image?this.addAni(c):"string"==typeof c?this._changeAni(c):this._ani=c.clone();let t=this.tileSize;o||1==this._ani.w&&1==this._ani.h||(o=this._ani.w/t,h||"circle"==this.shape||(h=this._ani.h/t))}if(this.groups=[],this.mouse=new this.p._SpriteMouse,"none"!=this.collider)this._vertexMode?this.addCollider(o,h):this.addCollider(0,0,o,h);else{if(this.w=o||(this.tileSize>1?1:50),this.h=h||this.w,Array.isArray(o))throw new Error('Cannot set the collider type of a sprite with a polygon or chain shape to "none". Try having the sprite overlap with other sprites instead.');this._shape=void 0!==o&&void 0===h?"circle":"box"}u._isAllSpritesGroup||this.p.allSprites.push(this),u.push(this),this._scale=new l,Object.defineProperty(this._scale,"x",{get(){return this._x},set(t){if(t==this._x)return;f.watch&&(f.mod[28]=!0);let e=t/this._x;f._w*=e,f._hw*=e,f._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;f.watch&&(f.mod[28]=!0);let e=t/this._y;f._h&&(this._h*=e,this._hh*=e),f._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&&(f.watch&&(f.mod[23]=!0),f._offsetCenterBy(t-this._x,0))},get y(){return this._y},set y(t){t!=this._y&&(f.watch&&(f.mod[23]=!0),f._offsetCenterBy(0,t-this._y))}},this._angle=0,this._rotationSpeed=0,this._bearing=0,this.prevPos={x:e,y:r},this.prevRotation=0,this._dest={x:e,y:r},this._destIdx=0,this.drag=0,this.debug=!1,this._shift={};let g=u.vel.x||0,y=u.vel.y||0;"function"==typeof g&&(g=g(u.length-1)),"function"==typeof y&&(y=y(u.length-1)),this.vel.x=g,this.vel.y=y;let m=["ani","collider","vel","x","y","w","h","d","diameter","dynamic","height","kinematic","speed","static","width"];for(let t of this.p.Sprite.propsAll){if(m.includes(t))continue;let e=u[t];void 0!==e&&("function"==typeof e&&p(e)&&(e=e(u.length-1)),this[t]="object"==typeof e?Object.assign({},e):e)}m=["add","animation","animations","autoCull","contains","GroupSprite","Group","idNum","length","mod","mouse","p","parent","Sprite","Subgroup","subgroups","velocity"];for(let t=0;t1?1:50,o??=s),"box"!=a&&"circle"!=a||(l=r(s-.08,o-.08,this.tileSize)),"box"==a)p=i.Box(l.x/2,l.y/2,r(t,e,this.tileSize),0);else if("circle"==a)p=i.Circle(r(t,e,this.tileSize),l.x/2);else if(n){let c,_,f=[{x:0,y:0}],g={x:0,y:0},y={x:0,y:0},m={x:0,y:0},w=Array.isArray(n[0]);function x(){g.xm.x&&(m.x=g.x),g.y>m.y&&(m.y=g.y)}if(w){this._vertexMode&&(c=n[0][0],_=n[0][1],this.body?(c=this.x-this._relativeOrigin.x,_=this.y-this._relativeOrigin.y,f.pop()):(this.x=c,this.y=_));for(let b=0;b0?1:-1;S=Math.abs(S);let C=0;for(let k=0;ki.Settings.maxPolygonVertices||"chain"==this._shape)&&(a="chain"),"polygon"==a?p=i.Polygon(f):"chain"==a&&(p=i.Chain(f,!1))}return this._shape||(this._shape=a),this._w=s,this._hw=.5*s,"circle"==this._shape?this._diameter=s:(this._h=o,this._hh=.5*o),p}removeColliders(){this._collides={},this._colliding={},this._collided={},this._removeFixtures(!1)}removeSensors(){this._hasOverlap={},this._overlaps={},this._overlapping={},this._overlapped={},this._removeFixtures(!0)}_removeFixtures(t){let e;for(let i=this.fixtureList;i;i=i.getNext())if(void 0===t||i.m_isSensor==t){let t=i.m_next;i.destroyProxies(this.p.world.m_broadPhase),e?e.m_next=t:this.body.m_fixtureList=t}else e=i}_offsetCenterBy(t,e){if(!t&&!e)return;if(this._offset._x+=t,this._offset._y+=e,!this.body)return;let i=r(t,e,this.tileSize);for(let t=this.body.m_fixtureList;t;t=t.m_next){let e=t.m_shape;if("circle"!=e.m_type){let t=e.m_vertices;for(let e of t)e.x+=i.x,e.y+=i.y}else e.m_p.x+=i.x,e.m_p.y+=i.y}}_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.watch&&(this.mod[6]=!0),this._autoDraw=t}get allowSleeping(){return this.body?.isSleepingAllowed()}set allowSleeping(t){this.watch&&(this.mod[7]=!0),this.body&&this.body.setSleepingAllowed(t)}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){this.watch&&(this.mod[8]=!0),this._autoUpdate=t}get bounciness(){if(this.fixture)return this.fixture.getRestitution()}set bounciness(t){this.watch&&(this.mod[9]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setRestitution(t)}get centerOfMass(){let t=this.body.getWorldCenter(),e=o(t.x,t.y,this.tileSize);return this.p.createVector(e.x,e.y)}get collider(){return this._collider}set collider(t){let e=(t=t.toLowerCase())[0];if("d"==e&&(t="dynamic"),"s"==e&&(t="static"),"k"==e&&(t="kinematic"),"n"==e&&(t="none"),t==this._collider)return;if(this.__collider=["d","s","k","n"].indexOf(e),void 0===this._collider)return void(this._collider=t);if("none"==t&&("chain"==this._shape||"polygon"==this._shape))throw new Error('Cannot set the collider type of a polygon or chain collider to "none". Try having the sprite overlap with other sprites instead.');this.joints.length&&(this.joints.removeAll(),console.warn("Changing the collider type of a sprite that has joints will remove all its joints.")),this.watch&&(this.mod[10]=!0);let i=this._collider;this._collider=t,void 0!==i&&this._reset()}_reset(){let t,e=this._cloneBodyProps();"chain"!=this._shape&&"polygon"!=this._shape||(t=this._getVertices(!0),this._vertexMode=!0),this.body&&(this.p.world.destroyBody(this.body),this.body=void 0),"none"!=this._collider&&(t?this.addCollider(0,0,t):this.addCollider(),this._hasSensors&&this.addDefaultSensors());for(let t in e)void 0!==e[t]&&(this[t]=e[t]);let i=this._offset._x,s=this._offset._y;this._offset._x=0,this._offset._y=0,this._offsetCenterBy(i,s)}_parseColor(t){if(t instanceof p5.Color)return t;if("object"!=typeof t)return"string"==typeof t&&1==t.length?this.p.colorPal(t):this.p.color(t);if(t.levels)return this.p.color(...t.levels);if(void 0!==t._r)return this.p.color(t._r,t._g,t._b,255*t._a);if(void 0!==t._h)return this.p.color(t._h,t._s,t._v,255*t._a);throw new Error("Invalid color")}get color(){return this._color}set color(t){this.watch&&(this.mod[11]=!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[31]=!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[32]=!0),this._strokeWeight=t}get textColor(){return this._textColor}set textColor(t){this.watch&&(this.mod[34]=!0),this._textColor=this._parseColor(t)}get bearing(){return this._bearing}set bearing(t){this.watch&&(this.mod[39]=!0),this._bearing=t}get debug(){return this._debug}set debug(t){this.watch&&(this.mod[12]=!0),this._debug=t}get density(){if(this.fixture)return this.fixture.getDensity()}set density(t){this.watch&&(this.mod[13]=!0);for(let e=this.fixtureList;e;e=e.getNext())e.setDensity(t)}_getDirectionAngle(t){t=t.toLowerCase().replaceAll(/[ _-]/g,"");let e={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}[t];return"radians"==this.p._angleMode&&(e=this.p.radians(e)),e}get direction(){return 0!==this.vel.x||0!==this.vel.y?this.p.atan2(this.vel.y,this.vel.x):void 0===this._direction?this.rotation:this._direction}set direction(t){this.watch&&(this.mod[14]=!0),"string"==typeof t&&(this._heading=t,t=this._getDirectionAngle(t)),this._direction=t;let e=this.speed;this.vel.x=this.p.cos(t)*e,this.vel.y=this.p.sin(t)*e}get drag(){return this.body?.getLinearDamping()}set drag(t){this.watch&&(this.mod[15]=!0),this.body&&this.body.setLinearDamping(t)}get draw(){return this._display}set draw(t){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[16]=!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._ani?.frameImage}set img(t){this.changeAni(t)}get image(){return this._ani?.frameImage}set image(t){this.changeAni(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[18]=!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[19]=!0),this._layer=t}get life(){return this._life}set life(t){this.watch&&(this.mod[20]=!0),this._life=t}get mass(){return this.body?.getMass()}set mass(t){if(!this.body)return;this.watch&&(this.mod[21]=!0);let e=this.massData;e.mass=t>0?t:1e-8,this.body.setMassData(e),delete this._massUndef}get massData(){const t={I:0,center:new i.Vec2(0,0),mass:0};return this.body.getMassData(t),t.center=o(t.center.x,t.center.y,this.tileSize),t}resetMass(){this.body&&(this.watch&&(this.mod[21]=!0),this.body.resetMassData(),delete this._massUndef)}get mirror(){return this._mirror}set mirror(t){this.watch&&(this.mod[22]=!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[23]=!0),this._offsetCenterBy(t.x-this._offset._x,t.y-this._offset._y))}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[24]=!0),this._pixelPerfect=t}get rotation(){if(!this.body)return this._angle||0;let t=this.body.getAngle();return"degrees"===this.p._angleMode?this.p.degrees(t):t}set rotation(t){this.body?("degrees"===this.p._angleMode&&(t=this.p.radians(t)),this.body.setAngle(t)):this._angle=t}get rotationDrag(){return this.body?.getAngularDamping()}set rotationDrag(t){this.body&&(this.watch&&(this.mod[26]=!0),this.body.setAngularDamping(t))}get rotationLock(){return this.body?.isFixedRotation()}set rotationLock(t){this.body&&(this.watch&&(this.mod[27]=!0),this.body.setFixedRotation(t))}get rotationSpeed(){return this.body?this.body.getAngularVelocity():this._rotationSpeed}set rotationSpeed(t){this.body?this.body.setAngularVelocity(t):this._rotationSpeed=t}get scale(){return this._scale}set scale(t){if(t<=0&&(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[28]=!0);let e={x:t.x/this._scale._x,y: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[30]=!0),this.body.setAwake(!t))}get speed(){return this.p.createVector(this.vel.x,this.vel.y).mag()}set speed(t){let e=this.direction;this.vel.x=this.p.cos(e)*t,this.vel.y=this.p.sin(e)*t}get static(){return this.body?.isStatic()}set static(t){this.collider=t?"static":"dynamic"}get removed(){return this._removed}set removed(t){t&&!this._removed&&(this.watch&&(this.mod[25]=!0),this._removed=!0,this._remove())}get vertices(){return this._getVertices()}_getVertices(t){let e=this.fixture;for(;e.m_next&&!e.m_isSensor;)e=e.m_next;let i=e.getShape(),r=[...i.m_vertices];"polygon"==i.m_type&&r.unshift(r.at(-1));let o=this.x,h=this.y;for(let e=0;e=1e3?this.p.p5play.sprites[r]:this.p.p5play.groups[r];let o=i[s][r]+1;if(this[s][r]=o,t instanceof this.p.Group&&(t[s][i._uid]=o),t&&0!=o){if(!(t instanceof this.p.Group)){e=[],1!=o&&-2!=o||e.push(a[s][0]),-1!=o&&e.push(a[s][1]),-1!=o&&-2!=o||e.push(a[s][2]);for(let s of e){let e=this.p.world._findContact(s,i,t,!0);e&&e(i,t,o)}}}else delete i[s][r],t instanceof this.p.Group&&delete t[s][i._uid]}this.removed&&0==Object.keys(this._collisions).length&&0==Object.keys(this._overlappers).length&&delete this.p.p5play.sprites[this._uid]}_draw(){if(void 0!==this.strokeWeight&&this.p.strokeWeight(this.strokeWeight),this._ani?.draw&&"colliders"!=this.debug&&this._ani.draw(this._offset._x,this._offset._y,0,this._scale._x,this._scale._y),!this._ani||this.debug||this.p.p5play.disableImages)if(this.debug&&"colliders"!=this.debug&&(this.p.noFill(),this.p.stroke(0,255,0),this.p.line(0,-2,0,2),this.p.line(-2,0,2,0)),3!=this.__collider){"chain"==this._shape?this.p.stroke(this.stroke||this.color):this._stroke&&this.p.stroke(this._stroke);for(let t=this.fixtureList;t;t=t.getNext())t.m_isSensor&&!this.debug||this._drawFixture(t)}else this.p.stroke(this._stroke||120),"box"==this._shape?this.p.rect(this._offset._x,this._offset._y,this.w*this.tileSize,this.h*this.tileSize):"circle"==this._shape&&this.p.circle(this._offset._x,this._offset._y,this.d*this.tileSize);void 0!==this.text&&(this.p.textAlign(this.p.CENTER,this.p.CENTER),this.p.fill(this.textColor),this.p.textSize(this.textSize*this.tileSize),this.p.text(this.text,0,0))}_display(){let t=.5*this.p.width-this.p.world.origin.x+this.x*this.tileSize,e=.5*this.p.height-this.p.world.origin.y+this.y*this.tileSize,i=Math.max(this._w,this._h);if("chain"!=this.shape&&this.p.camera.active&&(t+ithis.p.camera.bound.max.x||e+ithis.p.camera.bound.max.y))this._visible=null;else{this._visible=!0,this.p.p5play.spritesDrawn++,this._pixelPerfect?(t=this._w%2==0?Math.round(t):Math.round(t-.5)+.5,e=this._h%2==0?Math.round(e):Math.round(e-.5)+.5):(t=n(t),e=n(e));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.layer1?(r=Math.round(r),o=Math.round(o)):e%90==0&&(r=n(r),o=n(o)),this.moveTo(r,o,i)}moveTo(e,i,s){if("number"!=typeof e){let t=e;if(t==this.p.mouse&&!this.p.mouse.active)return;if(!t||void 0===t.x||void 0===t.y)throw"sprite.moveTo ERROR: destination not defined.";s=i,i=t.y,e=t.x}if(this._dest.x=this.x,this._dest.y=this.y,e==this.x?e=!1:(this._dest.x=e,e=!0),i==this.y?i=!1:(this._dest.y=i,i=!0),this._destIdx++,!e&&!i)return Promise.resolve(!0);if(this.speed&&(s??=this.speed),this.tileSize>1&&(s??=.1),s??=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 n=this.direction,a=n-.1,l=n+.1,p=s+.01,d=this._destIdx,u=Math.max(this.p.world.velocityThreshold,.25*p)/this.tileSize;return(async()=>{let s=p+p,r=p+p;do{if(d!=this._destIdx)return!1;await t.delay();let e=this.direction;if(e<=a||e>=l||Math.abs(this.vel.x)<=u&&Math.abs(this.vel.y)<=u)return!1;s=Math.abs(this.x-this._dest.x),r=Math.abs(this.y-this._dest.y)}while(e&&s>p||i&&r>p);return s2&&(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(t,e){if("object"==typeof t){let i=t;if(i==this.p.mouse&&!this.p.mouse.active)return 0;if(void 0===i.x||void 0===i.y)return console.error("sprite.angleTo ERROR: rotation destination not defined, object given with no x or y properties"),0;e=i.y,t=i.x}return this.p.atan2(e-this.y,t-this.x)}angleToFace(t,e,i){if("object"==typeof t&&(i=e,e=t.y,t=t.x),Math.abs(t-this.x)<.01&&Math.abs(e-this.y)<.01)return 0;let s=this.angleTo(t,e);i??=0,s+=i;let r=s-this.rotation%360,o=360-Math.abs(r);return o*=r<0?1:-1,Math.abs(r)2&&(i=o[0],s=o[1],e=o[2],r=o[3]),void 0!==i)t=this.angleToFace(i,s,r);else{if(t==this.rotation)return;t-=this.rotation}return this.rotate(t,e)}rotate(e,i){if(1==this.__collider)throw new v(0);if(isNaN(e))throw new v(1,[e]);if(0==e)return;let s=Math.abs(e);i??=1,i>s&&(i=s);let r=this.rotation+e,o=e>0;this.rotationSpeed=i*(o?1:-1);let h=Math.floor(s/i)-1;this._rotateIdx??=0,this._rotateIdx++;let n=this._rotateIdx;return(async()=>{if(h>1){let e=Math.abs(this.rotationSpeed)+.01;do{if(this._rotateIdx!=n)return!1;if(await t.delay(),o&&this.rotationSpeed<.01||!o&&this.rotationSpeed>-.01)return!1}while((o&&r>this.rotation||!o&&r.01&&(this.rotationSpeed=r-this.rotation,await t.delay())}else await t.delay();return this._rotateIdx==n&&(this.rotationSpeed=0,this.rotation=r,!0)})()}async changeAni(t){if(this.p.p5play.disableImages)return;if(arguments.length>1)t=[...arguments];else if(t instanceof this.p.SpriteAnimation){if(t==this._ani)return;t=[t]}else if(!Array.isArray(t)){if(t==this._ani?.name)return;t=[t]}let e,i;this._aniChangeCount++;for(let s=0;s1&&("!"==r.name[0]&&(r.name=r.name.slice(1),r.start=-1,r.end=0),"<"!=r.name[0]&&">"!=r.name[0]||(r.name=r.name.slice(1),r.flipX=!0),"^"==r.name[0]&&(r.name=r.name.slice(1),r.flipY=!0),"**"==r.name&&(e=!0,t=t.slice(0,-1)),";;"==r.name&&(i=!0,t=t.slice(0,-1)))}let s=this._aniChangeCount;do{for(let e=0;e1&&(i.start=0),await this._playSequencedAni(i)}}while(e&&s==this._aniChangeCount);1!=t.length&&i&&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(t){this._ani?._onChange&&this._ani._onChange(),this._ani?.onChange&&this._ani.onChange();let e=this.animations[t];if(!e)for(let i=this.groups.length-1;i>=0;i--){if(e=this.groups[i].animations[t],e){e=e.clone();break}}if(!e)throw this.p.noLoop(),new v("Sprite.changeAnimation",[t]);this._ani=e,this._ani.name=t,this.resetAnimationsOnChange&&(this._ani.frame=0)}remove(){this.removed=!0}_remove(){this.body&&this.p.world.destroyBody(this.body),this.body=null;for(let t of this.groups)t.remove(this);0==Object.keys(this._collisions).length&&0==Object.keys(this._overlappers).length&&delete this.p.p5play.sprites[this._uid]}toString(){return"s"+this.idNum}_ensureCollide(t,e){if(!t)throw new v("Sprite.collide",2);if(!(t instanceof this.p.Sprite||t instanceof this.p.Group))throw new v("Sprite.collide",0,[t]);if(e&&"function"!=typeof e)throw new v("Sprite.collide",1,[e]);if(!1!==this._hasOverlap[t._uid]&&(this._hasOverlap[t._uid]=!1),!1!==t._hasOverlap[this._uid]&&(t._hasOverlap[this._uid]=!1,t instanceof this.p.Group))for(let e of t)e._hasOverlap[this._uid]=!1}collide(t,e){return this.collides(t,e)}collides(t,e){return this._ensureCollide(t,e),this._collides[t._uid]=e||!0,1==this._collisions[t._uid]}colliding(t,e){this._ensureCollide(t,e),this._colliding[t._uid]=e||!0;let i=this._collisions[t._uid];return i>0?i:0}collided(t,e){return this._ensureCollide(t,e),this._collided[t._uid]=e||!0,-1==this._collisions[t._uid]}_removeContactsWith(t){if(t instanceof this.p.Group)for(let e of t)this._removeContactsWith(e);else this.__removeContactsWith(t)}__removeContactsWith(t){if(this.body)for(let e=this.body.getContactList();e;e=e.next){let i=e.contact;i.m_fixtureA.m_body.sprite._uid!=t._uid&&i.m_fixtureB.m_body.sprite._uid!=t._uid||this.p.world.destroyContact(i)}}_ensureOverlap(t,e){if(!t)throw new v("Sprite.overlap",2);if(!(t instanceof this.p.Sprite||t instanceof this.p.Group))throw new v("Sprite.overlap",0,[t]);if(e&&"function"!=typeof e)throw new v("Sprite.overlap",1,[e]);if(this._hasSensors||this.addDefaultSensors(),!t._hasSensors)if(t instanceof this.p.Sprite)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),1!=t._hasOverlap[this._uid]&&(t._removeContactsWith(this),t._hasOverlap[this._uid]=!0,t instanceof this.p.Group))for(let e of t)e._hasOverlap[this._uid]=!0}overlap(t,e){return this.overlaps(t,e)}overlaps(t,e){return this._ensureOverlap(t,e),this._overlaps[t._uid]=e||!0,1==this._overlappers[t._uid]}overlapping(t,e){this._ensureOverlap(t,e),this._overlapping[t._uid]=e||!0;let i=this._overlappers[t._uid];return i>0?i:0}overlapped(t,e){return this._ensureOverlap(t,e),this._overlapped[t._uid]=e||!0,-1==this._overlappers[t._uid]}_sortFixtures(){let t=null,e=null;for(let i=this.fixtureList;i;i=i.getNext())i.m_isSensor?e?e.m_next=i:e=i:t?t.m_next=i:t=i;e&&(e.m_next=null),t&&(t.m_next=e),this.body.m_fixtureList=t||e}addDefaultSensors(){let t;if(this.body){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}},this.Sprite.propTypes={x:"Float64",y:"Float64",vel:"Vec2",rotation:"number",rotationSpeed:"number",ani:"string",autoDraw:"boolean",allowSleeping:"boolean",autoUpdate:"boolean",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",tile:"string",tileSize:"number",visible:"boolean",w:"number",bearing:"number"},this.Sprite.props=Object.keys(this.Sprite.propTypes),this.Sprite.propsAll=this.Sprite.props.concat(["d","diameter","dynamic","fill","height","heading","kinematic","resetAnimationsOnChange","speed","static","width"]),this.Sprite.colliderTypes=["d","s","k","n"],this.Sprite.shapeTypes=["box","circle","chain","polygon"],this.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=async function(){this._prevPos.x=this.x,this._prevPos.y=this.y,await s.call(this,...arguments)},i},this.SpriteAnimation=class extends Array{constructor(){super(),this.p=t;let e,i=[...arguments];if(this.name="default",(i[0]instanceof this.p.Sprite||i[0]instanceof this.p.Group)&&(e=i[0],i=i.slice(1),this._addedToSpriteOrGroup=!0),e??=this.p.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,this.looping??=!0,this.endOnFirstFrame=!1,this.frameChanged=!1,this.onComplete=this.onChange=null,this._onComplete=this._onChange=null,this.rotation=e.anis.rotation||0,this._scale=new l,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[i.length-1]||i[i.length-1]instanceof p5.Image)for(let s=0;s=3)throw new v("SpriteAnimation",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,n();else{let a;a="string"==typeof o?o:o.url,this.spriteSheet=this.p.loadImage(a,(()=>{n()}))}function n(){if(Array.isArray(r)||Array.isArray(r.frames)){if("number"!=typeof r[0]){let t=r;if(Array.isArray(r.frames)){t=r.frames,delete r.frames;for(let e=0;e=h.spriteSheet.width&&(u=0,c+=i,c>=h.spriteSheet.height&&(c=0))}}else{let p,d,u=i[0];if(isNaN(i[1])?p=i[1]:d=Number(i[1]),".png"!=u.slice(-4)||p&&".png"!=p.slice(-4))throw new v("SpriteAnimation",0,[u]);let c=0,_=0;for(let y=u.length-5;y>=0&&!isNaN(u.charAt(y));y--)c++;if(p)for(let m=p.length-5;m>=0&&!isNaN(p.charAt(m));m--)_++;let f,g=u.slice(0,-4-c);if(p&&(f=p.slice(0,-4-_)),p&&g!=f)this.push(this.p.loadImage(u)),this.push(this.p.loadImage(p));else{let w,x=parseInt(u.slice(-4-c,-4),10);if(d??=parseInt(p.slice(-4-_,-4),10),dthis.frame&&-1!==this.targetFrame?this.frame++:this.targetFrame=this.lastFrame?this.frame=0:this.frame++:this.frame{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.frame0?this.frame=this.frame-1:this.looping&&(this.frame=this.length-1),this.targetFrame=-1,this.playing=!1}goToFrame(t){if(!(t<0||t>=this.length))return this.targetFrame=t,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 t=this[this.frame];if(t instanceof p5.Image)return t;let{x:e,y:i,w:s,h:r}=t,o=createGraphics(s,r);return o.image(this.spriteSheet,this.offset.x,this.offset.y,s,r,e,i,s,r),o}get w(){return this.width}get width(){return this[this.frame]instanceof p5.Image?this[this.frame].width:this[this.frame]?this[this.frame].w:1}get h(){return this.height}get height(){return this[this.frame]instanceof p5.Image?this[this.frame].height:this[this.frame]?this[this.frame].h:1}get frames(){let t=[];for(let e=0;ee.#t[t],set(i){e.#t[t]=i;for(let s in e){let r=e[s];r instanceof SpriteAnimation&&(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 SpriteAnimation&&(o[t][i]=s)}}})}}},this.Group=class extends Array{constructor(...e){let i;if(e[0]instanceof t.Group&&(i=e[0],e=e.slice(1)),super(...e),this.p=t,"number"==typeof e[0])return;for(let t of this)if(!(t instanceof this.p.Sprite))throw new Error("A group can only contain sprites");if(this.idNum=this.p.p5play.groupsCreated,this._uid=this.idNum,this.p.p5play.groups[this._uid]=this,this.p.p5play.groupsCreated++,this.p.allSprites||(this._isAllSpritesGroup=!0),this.subgroups=[],i instanceof this.p.Group){i.subgroups.push(this);let t=i;do{t=this.p.p5play.groups[t.parent],t.subgroups.push(this)}while(!t._isAllSpritesGroup);this.parent=i._uid}else this._isAllSpritesGroup||(this.p.allSprites.subgroups.push(this),this.parent=0);this.animations=new this.p.SpriteAnimations,this._collides={},this._colliding={},this._collided={},this._hasOverlap={},this._overlaps={},this._overlapping={},this._overlapped={},this._collisions={},this._overlappers={};let s=this;this.Sprite=class extends this.p.Sprite{constructor(){super(s,...arguments)}},this.GroupSprite=this.Sprite,this.Group=class extends this.p.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};let r=[...this.p.Sprite.propsAll,"spriteSheet"];for(let t of r)"ani"!=t&&"velocity"!=t&&Object.defineProperty(this,t,{get(){let e=s["_"+t],i=s.length-1;if(void 0===e&&!s._isAllSpritesGroup){let r=this.p.p5play.groups[s.parent];r&&(e=r[t],i=r.length-1)}return e},set(e){s["_"+t]=e;for(let i=0;it&&(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._ani.frameImage}set img(t){this.ani=t}get image(){return this._ani.frameImage}set image(t){this.ani=t}set amount(t){let e=t-this.length,i=e>0;e=Math.abs(e);for(let t=0;t0?i:0}collided(t,e){return this._ensureCollide(t,e),this._collided[t._uid]=e||!0,-1==this._collisions[t._uid]}_removeContactsWith(t){for(let e of this)e._removeContactsWith(t)}_ensureOverlap(t,e){if(!t)throw new v("Group.overlap",2);if(!(t instanceof this.p.Sprite||t instanceof this.p.Group))throw new v("Group.overlap",0,[t]);if(e&&"function"!=typeof e)throw new v("Group.overlap",1,[e]);if(!this._hasSensors){for(let t of this)t._hasSensors||t.addDefaultSensors();this._hasSensors=!0}if(!t._hasSensors)if(t instanceof this.p.Sprite)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)e._hasOverlap[t._uid]=!0}if(1!=t._hasOverlap[this._uid]&&(t._removeContactsWith(this),t._hasOverlap[this._uid]=!0,t instanceof this.p.Group))for(let e of t)e._hasOverlap[this._uid]=!0}overlap(t,e){return this.overlaps(t,e)}overlaps(t,e){return this._ensureOverlap(t,e),this._overlaps[t._uid]=e||!0,1==this._overlappers[t._uid]}overlapping(t,e){this._ensureOverlap(t,e),this._overlapping[t._uid]=e||!0;let i=this._overlappers[t._uid];return i>0?i:0}overlapped(t,e){return this._ensureOverlap(t,e),this._overlapped[t._uid]=e||!0,-1==this._overlappers[t._uid]}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(t,e,i){if("number"!=typeof t){let s=t;if(s==this.p.mouse&&!this.p.mouse.active)return;i=e,e=s.y,t=s.x}let s=this._resetCentroid(),r=[];for(let o of this){let h={x:o.x-s.x+t,y:o.y-s.y+e};r.push(o.moveTo(h.x,h.y,i))}return Promise.all(r)}moveTowards(t,e,i){if("number"!=typeof t){let s=t;if(s==this.p.mouse&&!this.p.mouse.active)return;i=e,e=s.y,t=s.x}if(void 0!==t||void 0!==e){this._resetCentroid();for(let s of this){void 0===s.distCentroid&&this._resetDistancesFromCentroid();let r={x:s.distCentroid.x+t,y:s.distCentroid.y+e};s.moveTowards(r.x,r.y,i)}}}moveAway(t,e,i){if("number"!=typeof t){let s=t;if(s==this.p.mouse&&!this.p.mouse.active)return;i=e,e=s.y,t=s.x}if(void 0!==t||void 0!==e){this._resetCentroid();for(let s of this){void 0===s.distCentroid&&this._resetDistancesFromCentroid();let r={x:s.distCentroid.x+t,y:s.distCentroid.y+e};s.moveAway(r.x,r.y,i)}}}push(...t){for(let e of t){if(!(e instanceof this.p.Sprite))throw new Error("you can only add sprites to a group, no "+typeof e+"s");for(let t in this._hasOverlap){let i=this._hasOverlap[t];i&&!e._hasSensors&&e.addDefaultSensors(),e._hasOverlap[t]=i}super.push(e),this.parent&&this.p.p5play.groups[this.parent].push(e),e.groups.push(this)}return this.length}size(){return this.length}toString(){return"g"+this.idNum}cull(t,e,i,s,r){if(void 0===i){r=e,t=e=i=s=t}if(isNaN(t)||isNaN(e)||isNaN(i)||isNaN(s))throw new TypeError("The culling boundary must be defined with numbers");if(r&&"function"!=typeof r)throw new TypeError("The callback to group.cull must be a function");let o=this.p.camera.x-this.p.world.hw/this.p.camera.zoom,h=this.p.camera.y-this.p.world.hh/this.p.camera.zoom,n=-i+o,a=-t+h,l=this.p.width+s+o,p=this.p.height+e+h,d=0;for(let t=0;tl||e.y>p)&&(d++,r?r(e,d):e.remove(),e.removed&&t--))}return d}remove(t){if(void 0===t){for(;this.length>0;)this[0].remove();return}let e;if(e="number"==typeof t?t>=0?t:this.length+t:this.indexOf(t),-1!=e){let t=this[e];if(!t.removed){let e=t.groups.findIndex((t=>t._uid==this._uid));t.groups.splice(e,1)}return this.splice(e,1),t}throw new Error("Sprite not found in group")}removeAll(){this.remove()}draw(){let t=[...this];t.sort(((t,e)=>t._layer-e._layer));for(let e=0;e(t.getShape().testPoint(t.getBody().getTransform(),h)&&a.push(t),!0))),r??=this.p.allSprites;let l=[];if(a.length>0)for(let t of r)t.body&&a.includes(t.body.m_fixtureList)&&t._cameraActiveWhenDrawn==o&&l.push(t);return l}getSpriteAt(t,e,i){let s=this.getSpritesAt(t,e,i);return s.sort(((t,e)=>-1*(t._layer-e._layer))),s[0]}_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)&&(t[s][e._uid]=0,e[s][t._uid]=0);for(let t of e.groups){(!i[s][t._uid]||i[s][t._uid]<0)&&(t[s][i._uid]=0,i[s][t._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:-3,i[s][e._uid]=0!=i[s][e._uid]?-2:-3;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:-3,e[s][t._uid]=0!=e[s][t._uid]?-2:-3)}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:-3,i[s][t._uid]=0!=i[s][t._uid]?-2:-3;for(let e of i.groups)t[s][e._uid]=0!=t[s][e._uid]?-2:3,e[s][t._uid]=0!=e[s][t._uid]?-2:3}}}_findContact(t,e,i,s){let r=e[t][i._uid];if(r&&(!s||!0!==r))return r;let o=i instanceof this.p.Sprite;if(o)for(let o of i.groups)if(r=e[t][o._uid],r&&(!s||!0!==r))return r;if(e instanceof this.p.Sprite)for(let h of e.groups){if(r=h[t][i._uid],r&&(!s||!0!==r))return r;if(o)for(let o of i.groups)if(r=h[t][o._uid],r&&(!s||!0!==r)&&(h._uid!=o._uid||e._uid{for(let t=0;t0&&(t=t<.1?this.p.map(t,0,.1,30,4):t<.5?this.p.map(t,.1,.5,4,2.5):t<.8?this.p.map(t,.5,.8,2.5,1):t<.9?this.p.map(t,.8,.9,1,.5):this.p.map(t,.9,1,.5,.2)),this._springiness=t,"wheel"==this.type?this._j.setSpringFrequencyHz(t):this._j.setFrequency(t)}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}remove(){this._removed||(this.spriteA.joints.splice(this.spriteA.joints.indexOf(this),1),this.spriteB.joints.splice(this.spriteB.joints.indexOf(this),1),this.p.world.destroyJoint(this._j),this._removed=!0)}},this.GlueJoint=class extends this.Joint{constructor(t,e){super(...arguments,"glue")}},this.DistanceJoint=class extends this.Joint{constructor(t,e){super(...arguments,"distance");let s=i.DistanceJoint({},t.body,e.body,t.body.getWorldCenter(),e.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=o(t.x,t.y,this.spriteA.tileSize)),(this.offsetB.x||this.offsetB.y)&&(e=this.spriteB.body.getWorldPoint(this._j.m_localAnchorB),e=o(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 this.Joint{constructor(t,e){super(...arguments,"wheel");let s=i.WheelJoint({maxMotorTorque:1e3,frequencyHz:4,dampingRatio:.7},t.body,e.body,e.body.getWorldCenter(),new i.Vec2(0,1));this._createJoint(s),this._angle="degrees"==this.p._angleMode?90:1.5707963267948966}_display(){let t,e,i=this.spriteA.x,s=this.spriteA.y;if(this.offsetB.x||this.offsetB.y){let i=this.spriteB.body.getWorldPoint(this._j.m_localAnchorB);i=o(i.x,i.y,this.spriteB.tileSize),t=i.x,e=i.y}else t=this.spriteB.x,e=this.spriteB.y;let r=this.p.tan(this.spriteA.rotation),h=this.p.tan(this._angle+this.spriteA.rotation),n=(e-s+r*i-h*t)/(r-h),a=r*(n-i)+s;this._draw(n,a,t,e),this.visible=null}get angle(){return this._angle}set angle(t){t!=this._angle&&(this._angle=t,this._j.m_localXAxisA=new i.Vec2(this.p.cos(t),this.p.sin(t)),this._j.m_localXAxisA.normalize(),this._j.m_localYAxisA=i.Vec2.crossNumVec2(1,this._j.m_localXAxisA))}},this.HingeJoint=class extends this.Joint{constructor(t,e){super(...arguments,"hinge");let s=i.RevoluteJoint({},t.body,e.body,t.body.getWorldCenter());this._createJoint(s)}_display(){const t=this.offsetA.x,e=this.offsetA.y,i=this.spriteA.rotation,s=t*this.p.cos(i)-e*this.p.sin(i),r=t*this.p.sin(i)+e*this.p.cos(i);this._draw(this.spriteA.x+s,this.spriteA.y+r),this.visible=null}get range(){return this.upperLimit-this.lowerLimit}set range(t){t/=2,this.upperLimit=t,this.lowerLimit=-t}get lowerLimit(){let t=this._j.getLowerLimit();return"radians"==this.p._angleMode?t:this.p.degrees(t)}set lowerLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),this.spriteA.body.setAwake(!0),this.spriteB.body.setAwake(!0),"degrees"==this.p._angleMode&&(t=this.p.radians(t)),this._j.m_lowerAngle=t}get upperLimit(){let t=this._j.getUpperLimit();return"radians"==this.p._angleMode?t:this.p.degrees(t)}set upperLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),this.spriteA.body.setAwake(!0),this.spriteB.body.setAwake(!0),"degrees"==this.p._angleMode&&(t=this.p.radians(t)),this._j.m_upperAngle=t}get angle(){let e=this._j.getJointAngle();return"radians"==this.p._angleMode?e:t.radians(e)}},this.RevoluteJoint=this.HingeJoint,this.SliderJoint=class extends this.Joint{constructor(t,e){super(...arguments,"slider");let s=i.PrismaticJoint({lowerTranslation:-1,upperTranslation:1,enableLimit:!0,maxMotorForce:50,motorSpeed:0,enableMotor:!0},t.body,e.body,t.body.getWorldCenter(),new i.Vec2(1,0));this._createJoint(s),this._angle=0}get angle(){return this._angle}set angle(t){t!=this._angle&&(this._angle=t,this._j.m_localXAxisA=new i.Vec2(this.p.cos(t),this.p.sin(t)),this._j.m_localXAxisA.normalize(),this._j.m_localYAxisA=i.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*s}set lowerLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),t=t*this.spriteA.tileSize/s,this._j.setLimits(t,this._j.getUpperLimit())}get upperLimit(){return this._j.getUpperLimit()/this.spriteA.tileSize*s}set upperLimit(t){this._j.isLimitEnabled()||this._j.enableLimit(!0),t=t*this.spriteA.tileSize/s,this._j.setLimits(this._j.getLowerLimit(),t)}},this.PrismaticJoint=this.SliderJoint,this.RopeJoint=class extends this.Joint{constructor(t,e){super(...arguments,"rope");let s=i.RopeJoint({maxLength:1},t.body,e.body,t.body.getWorldCenter());this._createJoint(s),this._j.m_localAnchorB.x=0,this._j.m_localAnchorB.y=0}get maxLength(){return t=this._j.getMaxLength(),e=this.spriteA.tileSize,t/e*s;var t,e}set maxLength(t){var e,i;this._j.setMaxLength((e=t,i=this.spriteA.tileSize,e*i/s))}};class l{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(){let t=new Float32Array(1),e=new Int32Array(t.buffer)}();function p(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 d(t,e){return"triangle"==e?t=[t,-120,3]:"square"==e?t=[t,-90,4]:"pentagon"==e?t=[t,-72,5]:"hexagon"==e?t=[t,-60,6]:"septagon"==e?t=[t,-51.4285714286,7]:"octagon"==e?t=[t,-45,8]:"enneagon"==e?t=[t,-40,9]:"decagon"==e?t=[t,-36,10]:"hendecagon"==e?t=[t,-32.7272727273,11]:"dodecagon"==e&&(t=[t,-30,12]),t}this.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;let s;return"number"==typeof i&&(i=t.p5play.palettes[i]),i??=t.p5play.palettes[0],i&&(s=i[e]),""===s||"."===e||" "===e?t.color(0,0,0,0):t.color(s||e)},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,n=t.createImage(o*i,h*i);n.loadPixels();for(let t=0;tnew Promise(t?e=>{setTimeout(e,t)}:requestAnimationFrame),this.sleep=t=>this.delay(t),this.play=t=>{if(!t.play)throw new Error("Tried to play your input but it wasn't a sound object: "+t);return new Promise(((e,i)=>{t.play(),t.onended((()=>e()))}))},this.p5play.playIntro=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.src="https://p5play.org/v3/made_with_p5play.png",i.style="position: absolute; top: 50%; left: 50%; width: 40vh; height: 20vh; margin-left: -20vh; margin-top: -10vh; z-index: 1000; opacity: 0; transition: opacity 0.1s ease-in-out;",document.body.append(e),e.append(i),await t.delay(100),i.style.opacity="1",i.style.transition="scale 1.4s, opacity 0.4s ease-in-out",i.style.scale="1.1",await t.delay(1100),i.style.opacity="0",await t.delay(300),e.style.display="none",e.remove(),document.getElementById("p5play-intro")?.remove(),t._decrementPreload()};{let t=location.hostname;switch(t){case"":case"127.0.0.1":case"localhost":case"p5play.org":case"editor.p5js.org":case"codepen.io":case"codera.app":case"cdpn.io":case"glitch.com":case"replit.com":case"stackblitz.com":case"jsfiddle.net":case"aijs-912fe.web.app":break;default:if(/^[\d\.]+$/.test(t)||t.endsWith("stackblitz.io")||t.endsWith("glitch.me")||t.endsWith("repl.co")||t.endsWith("codehs.com")||t.endsWith("openprocessing.org")||location.origin.endsWith("preview.p5js.org"))break;this.p5play.playIntro()}}let u=p5.disableFriendlyErrors;p5.disableFriendlyErrors=!0,this.canvas=this.canvas;const c=this.createCanvas;this.createCanvas=function(){let e,i,s,r,o=[...arguments],h=!1,n=!1;if("string"==typeof o[0]&&(o[0].includes(":")?s=o[0].split(":"):(o[2]=o[0],o[0]=void 0),"fullscreen"==o[1]&&(h=!0)),o[0]?"number"==typeof o[0]&&"number"!=typeof o[1]&&(o[2]=o[1],o[1]=o[0]):(o[0]=window.innerWidth,o[1]=window.innerHeight,h=!0),"string"==typeof o[2]){let t=o[2].toLowerCase();"p2d"!=t&&"webgl"!=t&&(t=t.split(" "),o.pop()),"pixelated"==t[0]&&(n=!0,t[1]?r=Number(t[1].slice(1)):h=!0,s=[o[0],o[1]]),"fullscreen"==t[0]&&(h=!0)}if(s){let t=Number(s[0]),h=Number(s[1]);r?(e=t*r,i=h*r):(e=window.innerWidth,i=window.innerWidth*(h/t),i>window.innerHeight&&(e=window.innerHeight*(t/h),i=window.innerHeight)),e=Math.round(e),i=Math.round(i),n||(o[0]=e,o[1]=i)}let a=c.call(t,...o);this.canvas.tabIndex=0,this.canvas.w=o[0],this.canvas.h=o[1],this.canvas.addEventListener("keydown",(function(t){" "!=t.key&&"/"!=t.key&&"ArrowUp"!=t.key&&"ArrowDown"!=t.key&&"ArrowLeft"!=t.key&&"ArrowRight"!=t.key||t.preventDefault()})),this.canvas.addEventListener("mouseover",(()=>{this.mouse.isOnCanvas=!0,this.mouse.active=!0})),this.canvas.addEventListener("mouseleave",(()=>{this.mouse.isOnCanvas=!1})),this.canvas.addEventListener("touchstart",(t=>t.preventDefault())),this.canvas.addEventListener("contextmenu",(t=>t.preventDefault())),this.canvas.resize=this.resizeCanvas,this.world.resize(),this.camera.x=this.world.hw,this.camera.y=this.world.hh,u||(p5.disableFriendlyErrors=!1);let l="\n.p5Canvas, .q5Canvas {\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}\nmain {\n\toverscroll-behavior: none;\n}";h&&(l="html,\nbody,\n"+l,l+="\nhtml, body {\n\tmargin: 0;\n\tpadding: 0;\n\toverflow: hidden;\n\theight: 100%;\n}\nmain {\n\tmargin: auto;\n\tdisplay: flex;\n\tflex-wrap: wrap;\n\talign-content: center;\n\tjustify-content: center;\n\theight: 100%;\n}"),n&&(l+=`\n#${this.canvas.id} {\n\timage-rendering: pixelated;\n\twidth: ${e}px!important;\n\theight: ${i}px!important;\n}`);let p=document.createElement("style");p.innerHTML=l,document.head.appendChild(p),n&&(t.pixelDensity(1),t.noSmooth());let d=navigator.userAgent.indexOf("iPhone OS");if(d>-1){let e=navigator.userAgent.substring(d+10,d+12);this.p5play.version=e,e<16&&t.pixelDensity(1),this.p5play.os.platform="iOS",this.p5play.os.version=e}else void 0!==navigator.userAgentData&&(this.p5play.os.platform=navigator.userAgentData.platform);return a},this.Canvas=class{constructor(t,e,i){}get w(){}get width(){}get h(){}get height(){}resize(){}},this.Canvas=function(){return t.createCanvas(...arguments)};const _=this.resizeCanvas;this.resizeCanvas=(t,e)=>{_.call(this,t,e),this.world.resize(),this.camera._pos.x=this.world.hw,this.camera._pos.y=this.world.hh};const f=this.background;this.background=function(){let t,e=arguments;1==e.length&&("string"==typeof e[0]||e[0]instanceof p5.Color)&&(t=this.colorPal(e[0])),void 0!==t?f.call(this,t):f.call(this,...e)};const g=this.fill;this.fill=function(){let t,e=arguments;1==e.length&&(t=this.colorPal(e[0])),void 0!==t?g.call(this,t):g.call(this,...e)};const y=this.stroke;this.stroke=function(){let t,e=arguments;1==e.length&&(t=this.colorPal(e[0])),void 0!==t?y.call(this,t):y.call(this,...e)},this.p5play.images={onLoad:t=>{}},this.p5play.disableImages=!1;const m=this.loadImage;this.loadImage=this.loadImg=function(){if(this.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 1==r.width&&1==r.height||!r.pixels.length?e?(r.cbs.push(e),r.calls++):t._decrementPreload():(e&&e(),t._decrementPreload()),r;return r=m.call(t,s,(e=>{e.w=e.width,e.h=e.height;for(let t of e.cbs)t(e);for(let i=1;ii[e])),o+=h,p5._friendlyError(o,t)}}this.allSprites=new this.Group,this.world=new this.World,this.camera=new this.Camera,this.InputDevice=class{constructor(){this.holdThreshold=12}init(t){for(let e of t)this[e]=0}ac(t){return t}presses(t){return t??=this.default,void 0===this[t]&&(t=this.ac(t)),1==this[t]||-2==this[t]}pressing(t){return t??=this.default,void 0===this[t]&&(t=this.ac(t)),-2==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)),-3==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 this.InputDevice{constructor(){super();let t=this;this._position={get x(){return t.x},set x(e){t.x=e},get y(){return t.y},set y(e){t.y=e}};this.init(["x","y","left","center","right"]),this.default="left",this.drag={left:0,center:0,right:0},this.isOnCanvas=!1,this.active=!1,this.x,this.y,this._visible=!0,this._cursor="default"}get pos(){return this._position}get position(){return this._position}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"}ac(t){return t=t.slice(0,4)?"left":"right"==t.slice(0,5)?"right":"middle"==t.slice(0,6)?"center":t.toLowerCase()}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,-1==this.drag[t]}},this.mouse=new this._Mouse,this._SpriteMouse=class extends this._Mouse{constructor(){super(),this.hover=0}hovers(){return 1==this.hover}hovering(){return this.hover>0?this.hover:0}hovered(){return-1==this.hover}};const b=function(t){if(this.mouse[t]++,this.mouse.active=!0,this.world.mouseSprites.length){let e=this.world.mouseSprite;e&&(e.mouse[t]=0,e.mouse.drag[t]=0),e=this.world.mouseSprites[0],e.mouse[t]=1,this.world.mouseSprite=e}},S=t._onmousedown;t._onmousedown=function(t){let e="left";1===t.button?e="center":2===t.button&&(e="right"),b.call(this,e),S.call(this,t)};const A=t._ontouchstart;t._ontouchstart=function(t){b.call(this,"left"),A.call(this,t)};const C=function(t){let e=this.mouse;if(e[t]>0&&e.drag[t]<=0){e.drag[t]=1,e._isDragging=!0;let i=this.world.mouseSprite?.mouse;i&&(i.drag[t]=1,i._isDragging=!0)}},k=t._onmousemove;t._onmousemove=function(t){let e="left";1===t.button?e="center":2===t.button&&(e="right"),C.call(this,e),k.call(this,t)};const z=function(t){let e=this.mouse;e[t]>=e.holdThreshold?e[t]=-3:e[t]>1?e[t]=-1:e[t]=-2;let i=this.world.mouseSprite?.mouse;i&&(i.hover>1?(i[t]>=this.mouse.holdThreshold?i[t]=-3:i[t]>1?i[t]=-1:i[t]=-2,i.drag[t]>0&&(i.drag[t]=i[t])):(i[t]=0,i.drag[t]=0))},j=t._onmouseup;t._onmouseup=function(t){let e="left";1===t.button?e="center":2===t.button&&(e="right"),z.call(this,e),j.call(this,t)};const M=t._ontouchend;if(t._ontouchend=function(t){z.call(this,"left"),M.call(this,t)},delete this._Mouse,this._KeyBoard=class extends this.InputDevice{constructor(){super(),this.default=" "}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," ")}return t.toLowerCase()}_pre(t){(!this[t]||this[t]<0)&&(this[t]=1)}_rel(t){this[t]>=this.holdThreshold?this[t]=-3:this[t]>1?this[t]=-1:this[t]=-2}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}get arrowup(){return this.arrowUp}get arrowdown(){return this.arrowDown}get arrowleft(){return this.arrowLeft}get arrowright(){return this.arrowRight}get capslock(){return this.capsLock}},this.kb=new this._KeyBoard,delete this._KeyBoard,this.keyboard=this.kb,navigator.keyboard){const t=navigator.keyboard;window==window.top?t.getLayoutMap().then((t=>{"w"!=t.get("KeyW")&&(this.p5play.standardizeKeyboard=!0)})):this.p5play.standardizeKeyboard=!0}else this.p5play.standardizeKeyboard=!0;function T(t){let e=t.code;return 4==e.length&&"Key"==e.slice(0,3)?e[3].toLowerCase():t.key}let L={arrowUp:"up",arrowDown:"down",arrowLeft:"left",arrowRight:"right"};{let t=L;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"}const D=t._onkeydown;t._onkeydown=function(t){let e=t.key;if(this.p5play.standardizeKeyboard&&(e=T(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=L[e];i&&this.kb._pre(i),D.call(this,t)};const P=t._onkeyup;t._onkeyup=function(t){let e=t.key;if(this.p5play.standardizeKeyboard&&(e=T(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=L[e];if(i&&this.kb._rel(i),t.shiftKey){let t=e.toLowerCase();this.kb[t]>0&&this.kb._rel(t)}P.call(this,t)},this._Contro=class extends this.InputDevice{constructor(t){super();this.init(["a","b","x","y","l","r","lt","rt","select","start","up","down","left","right","leftTrigger","rightTrigger"]),this.leftStick={x:0,y:0,btn:0},this.rightStick={x:0,y:0,btn:0},this._btns={a:0,b:1,x:2,y:3,l:4,r:5,lt:6,rt:7,select:8,start:9,leftStickButton:10,rightStickButton:11,up:12,down:13,left:14,right:15},this._axes={leftStick:{x:0,y:1},rightStick:{x:2,y:3},leftTrigger:4,rightTrigger:5},t.id.includes("GuliKit")&&(this._btns.a=1,this._btns.b=0,this._btns.x=3,this._btns.y=2),e(t),this.gamepad=t,this.id=t.id}ac(t){return t.toLowerCase()}_update(){if(this.gamepad=navigator.getGamepads()[this.gamepad.index],!this.gamepad)return;let t=this.gamepad;for(let e in this._btns){let i=this._btns[e];t.buttons[i].pressed?this[e]++:this[e]=this[e]>0?-1:0}return this.leftStick.x=t.axes[this._axes.leftStick.x],this.leftStick.y=t.axes[this._axes.leftStick.y],this.rightStick.x=t.axes[this._axes.rightStick.x],this.rightStick.y=t.axes[this._axes.rightStick.y],void 0!==t.axes[this._axes.leftTrigger]?(this.leftTrigger=t.axes[this._axes.leftTrigger],this.rightTrigger=t.axes[this._axes.rightTrigger]):(this.leftTrigger=t.buttons[this._btns.lt].value,this.rightTrigger=t.buttons[this._btns.rt].value),!0}},this._Contros=class extends Array{constructor(){super();let t=this;window.addEventListener("gamepadconnected",(e=>{t._addContro(e.gamepad)})),window.addEventListener("gamepaddisconnected",(e=>{t._removeContro(e.gamepad)})),this.default="a";let e=["presses","pressing","pressed","holds","holding","held","released"];for(let t of e)this[t]=e=>{if(this[0])return this[0][t](e)};let i=["a","b","x","y","l","r","lt","rt","select","start","leftStickButton","rightStickButton","up","down","left","right"];for(let e of i)Object.defineProperty(this,e,{get:()=>t[0]?t[0][e]:0});let s=["leftStick","rightStick"];for(let e of s){this[e]={};for(let i of["x","y"])Object.defineProperty(this[e],i,{get:()=>t[0]?t[0][e][i]:0})}if(!navigator?.getGamepads)return;let r=navigator.getGamepads();for(let t of r)t&&this._addContro(t)}_addContro(i){i&&(e("controller "+this.length+" connected: "+i.id),this.push(new t._Contro(i)))}_removeContro(t){if(t){e("controller "+this.length+" disconnected: "+t.id);for(let e=0;ethis.p5play._fps,this.p5play._fpsArr=[60],this.renderStats=(t,e)=>{let i=this.p5play._renderStats;void 0===i.show&&(1==this.allSprites.tileSize||this.allSprites.tileSize>16?i.fontSize=16:i.fontSize=10,i.gap=1.25*i.fontSize,console.warn("renderStats() uses inaccurate FPS approximations. Even if your game runs at a solid 60hz display rate, the fps calculations shown may be lower. The only way to get accurate results is to use your web browser's performance testing tools.")),i.x=t||10,i.y=e||20,i.show=!0}})),p5.prototype.registerMethod("pre",(function(){this.p5play._fps&&(this.p5play._preDrawFrameTime=performance.now()),this.p5play.spritesDrawn=0,this.mouse.x=(this.mouseX-this.world.hw)/this.camera.zoom+this.camera.x,this.mouse.y=(this.mouseY-this.world.hh)/this.camera.zoom+this.camera.y,this.camera.mouse.x=this.mouseX,this.camera.mouse.y=this.mouseY,this.contro._update()})),p5.prototype.registerMethod("post",(function(){this.p5play._inPostDraw=!0,this.allSprites.autoCull&&this.allSprites.cull(1e4),this.allSprites._autoDraw&&(this.camera.on(),this.allSprites.draw(),this.camera.off()),this.allSprites._autoDraw??=!0;let t=this.p5play._renderStats;if(t.show){if(1==this.frameCount||this.frameCount%60==0){let t,e=this.p5play._fpsArr.reduce(((t,e)=>t+e));e=Math.round(e/this.p5play._fpsArr.length),this.p5play._fpsAvg=e,this.p5play._fpsMin=Math.min(...this.p5play._fpsArr),this.p5play._fpsMax=Math.max(...this.p5play._fpsArr),this.p5play._fpsArr=[],t=e>55?this.color(30,255,30):e>25?this.color(255,100,30):this.color(255,30,30),this.p5play._statsColor=t}this.p5play._fpsArr.push(this.getFPS()),this.push(),this.fill(0,0,0,128),this.rect(t.x-5,t.y-t.fontSize,8.5*t.fontSize,4*t.gap+5),this.fill(this.p5play._statsColor),this.textSize(t.fontSize),this.textFont("monospace");let e=t.x,i=t.y;this.text("sprites: "+this.p5play.spritesDrawn,e,i),this.text("fps avg: "+this.p5play._fpsAvg,e,i+t.gap),this.text("fps min: "+this.p5play._fpsMin,e,i+2*t.gap),this.text("fps max: "+this.p5play._fpsMax,e,i+3*t.gap),this.pop(),t.show=!1}this.world.autoStep&&this.world.step(),this.world.autoStep??=!0,this.allSprites._autoUpdate&&this.allSprites.update(),this.allSprites._autoUpdate??=!0;for(let t of this.allSprites)t.autoDraw??=!0,t.autoUpdate??=!0;for(let t in this.kb)"holdThreshold"!=t&&(this.kb[t]<0?this.kb[t]=0:this.kb[t]>0&&this.kb[t]++);let e=this.mouse,i=this.world.mouseSprite?.mouse;for(let t of["left","center","right"])e[t]<0?e[t]=0:e[t]>0&&e[t]++,i&&(i[t]=e[t]);if(this.world.mouseTracking){let t=this.world.getSpritesAt(e.x,e.y);t.sort(((t,e)=>-1*(t._layer-e._layer)));let s=this.world.getSpritesAt(this.camera.mouse.x,this.camera.mouse.y,this.allSprites,!1);s.sort(((t,e)=>-1*(t._layer-e._layer))),t=t.concat(s);for(let e=0;e0?i.mouse.hover=-1:i.mouse.hover<0&&(i.mouse.hover=0):i.mouse.hover++}let r=this.world.mouseSprite;if(e.left<=0&&e.center<=0&&e.right<=0)r=null,this.world.mouseSprite=null;else for(let t of["left","center","right"])e.drag[t]<0?e.drag[t]=0:e.drag[t]>0&&e.drag[t]++,i&&(i.drag[t]=e.drag[t],i.x=r.x-e.x,i.y=r.y-e.y);for(let e of this.world.mouseSprites)if(!(i?._isDragging&&e==r||t.includes(e))){let t=e.mouse;t.hover=-1,t.left=t.center=t.right=0}this.world.mouseSprites=t}this.camera.off(),this.p5play._fps&&(this.p5play._postDrawFrameTime=performance.now(),this.p5play._fps=Math.round(1e3/(this.p5play._postDrawFrameTime-this.p5play._preDrawFrameTime))||1),this.p5play._inPostDraw=!1})); diff --git a/package.json b/package.json index 02c9ebd1..21fcf549 100644 --- a/package.json +++ b/package.json @@ -39,5 +39,5 @@ "version": "git add -A", "postversion": "git push" }, - "version": "3.12.4" + "version": "3.12.5" }