phaser-ce
Version:
Phaser CE (Community Edition) is a fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers.
3 lines (2 loc) • 836 kB
JavaScript
/* Phaser v2.20.2 - http://phaser.io - @photonstorm - (c) 2016 Photon Storm Ltd. */
!function(t){var e;"object"==typeof exports?module.exports=t():("undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.p2=t())}(function(){return function n(r,o,a){function h(i,t){if(!o[i]){if(!r[i]){var e="function"==typeof require&&require;if(!t&&e)return e(i,!0);if(l)return l(i,!0);throw new Error("Cannot find module '"+i+"'")}var s=o[i]={exports:{}};r[i][0].call(s.exports,function(t){var e=r[i][1][t];return h(e||t)},s,s.exports,n,r,o,a)}return o[i].exports}for(var l="function"==typeof require&&require,t=0;t<a.length;t++)h(a[t]);return h}({1:[function(t,e,i){var u=t("./Scalar");function s(){}(e.exports=s).lineInt=function(t,e,i){i=i||0;var s,n,r,o,a,h,l,c=[0,0];return s=t[1][1]-t[0][1],n=t[0][0]-t[1][0],r=s*t[0][0]+n*t[0][1],o=e[1][1]-e[0][1],a=e[0][0]-e[1][0],h=o*e[0][0]+a*e[0][1],l=s*a-o*n,u.eq(l,0,i)||(c[0]=(a*r-n*h)/l,c[1]=(s*h-o*r)/l),c},s.segmentsIntersect=function(t,e,i,s){var n=e[0]-t[0],r=e[1]-t[1],o=s[0]-i[0],a=s[1]-i[1];if(o*r-a*n==0)return!1;var h=(n*(i[1]-t[1])+r*(t[0]-i[0]))/(o*r-a*n),l=(o*(t[1]-i[1])+a*(i[0]-t[0]))/(a*n-o*r);return 0<=h&&h<=1&&0<=l&&l<=1}},{"./Scalar":4}],2:[function(t,e,i){function l(){}(e.exports=l).area=function(t,e,i){return(e[0]-t[0])*(i[1]-t[1])-(i[0]-t[0])*(e[1]-t[1])},l.left=function(t,e,i){return 0<l.area(t,e,i)},l.leftOn=function(t,e,i){return 0<=l.area(t,e,i)},l.right=function(t,e,i){return l.area(t,e,i)<0},l.rightOn=function(t,e,i){return l.area(t,e,i)<=0};var c=[],u=[];l.collinear=function(t,e,i,s){if(s){var n=c,r=u;n[0]=e[0]-t[0],n[1]=e[1]-t[1],r[0]=i[0]-e[0],r[1]=i[1]-e[1];var o=n[0]*r[0]+n[1]*r[1],a=Math.sqrt(n[0]*n[0]+n[1]*n[1]),h=Math.sqrt(r[0]*r[0]+r[1]*r[1]);return Math.acos(o/(a*h))<s}return 0==l.area(t,e,i)},l.sqdist=function(t,e){var i=e[0]-t[0],s=e[1]-t[1];return i*i+s*s}},{}],3:[function(t,e,i){var a=t("./Line"),w=t("./Point"),d=t("./Scalar");function T(){this.vertices=[]}(e.exports=T).prototype.at=function(t){var e=this.vertices,i=e.length;return e[t<0?t%i+i:t%i]},T.prototype.first=function(){return this.vertices[0]},T.prototype.last=function(){return this.vertices[this.vertices.length-1]},T.prototype.clear=function(){this.vertices.length=0},T.prototype.append=function(t,e,i){if(void 0===e)throw new Error("From is not given!");if(void 0===i)throw new Error("To is not given!");if(i-1<e)throw new Error("lol1");if(i>t.vertices.length)throw new Error("lol2");if(e<0)throw new Error("lol3");for(var s=e;s<i;s++)this.vertices.push(t.vertices[s])},T.prototype.makeCCW=function(){for(var t=0,e=this.vertices,i=1;i<this.vertices.length;++i)(e[i][1]<e[t][1]||e[i][1]==e[t][1]&&e[i][0]>e[t][0])&&(t=i);w.left(this.at(t-1),this.at(t),this.at(t+1))||this.reverse()},T.prototype.reverse=function(){for(var t=[],e=0,i=this.vertices.length;e!==i;e++)t.push(this.vertices.pop());this.vertices=t},T.prototype.isReflex=function(t){return w.right(this.at(t-1),this.at(t),this.at(t+1))};var h=[],l=[];function P(t,e,i,s,n){n=n||0;var r=e[1]-t[1],o=t[0]-e[0],a=r*t[0]+o*t[1],h=s[1]-i[1],l=i[0]-s[0],c=h*i[0]+l*i[1],u=r*l-h*o;return d.eq(u,0,n)?[0,0]:[(l*a-o*c)/u,(r*c-h*a)/u]}T.prototype.canSee=function(t,e){var i,s,n=h,r=l;if(w.leftOn(this.at(t+1),this.at(t),this.at(e))&&w.rightOn(this.at(t-1),this.at(t),this.at(e)))return!1;s=w.sqdist(this.at(t),this.at(e));for(var o=0;o!==this.vertices.length;++o)if((o+1)%this.vertices.length!==t&&o!==t&&w.leftOn(this.at(t),this.at(e),this.at(o+1))&&w.rightOn(this.at(t),this.at(e),this.at(o))&&(n[0]=this.at(t),n[1]=this.at(e),r[0]=this.at(o),r[1]=this.at(o+1),i=a.lineInt(n,r),w.sqdist(this.at(t),i)<s))return!1;return!0},T.prototype.copy=function(t,e,i){var s=i||new T;if(s.clear(),t<e)for(var n=t;n<=e;n++)s.vertices.push(this.vertices[n]);else{for(n=0;n<=e;n++)s.vertices.push(this.vertices[n]);for(n=t;n<this.vertices.length;n++)s.vertices.push(this.vertices[n])}return s},T.prototype.getCutEdges=function(){for(var t=[],e=[],i=[],s=new T,n=Number.MAX_VALUE,r=0;r<this.vertices.length;++r)if(this.isReflex(r))for(var o=0;o<this.vertices.length;++o)if(this.canSee(r,o)){e=this.copy(r,o,s).getCutEdges(),i=this.copy(o,r,s).getCutEdges();for(var a=0;a<i.length;a++)e.push(i[a]);e.length<n&&(n=(t=e).length,t.push([this.at(r),this.at(o)]))}return t},T.prototype.decomp=function(){var t=this.getCutEdges();return 0<t.length?this.slice(t):[this]},T.prototype.slice=function(t){if(0==t.length)return[this];if(t instanceof Array&&t.length&&t[0]instanceof Array&&2==t[0].length&&t[0][0]instanceof Array){for(var e=[this],i=0;i<t.length;i++)for(var s=t[i],n=0;n<e.length;n++){var r=e[n].slice(s);if(r){e.splice(n,1),e.push(r[0],r[1]);break}}return e}s=t,i=this.vertices.indexOf(s[0]),n=this.vertices.indexOf(s[1]);return-1!=i&&-1!=n&&[this.copy(i,n),this.copy(n,i)]},T.prototype.isSimple=function(){for(var t=this.vertices,e=0;e<t.length-1;e++)for(var i=0;i<e-1;i++)if(a.segmentsIntersect(t[e],t[e+1],t[i],t[i+1]))return!1;for(e=1;e<t.length-2;e++)if(a.segmentsIntersect(t[0],t[t.length-1],t[e],t[e+1]))return!1;return!0},T.prototype.quickDecomp=function(t,e,i,s,n,r){n=n||100,r=r||0,s=s||25,t=void 0!==t?t:[],e=e||[],i=i||[];var o=[0,0],a=[0,0],h=[0,0],l=0,c=0,u=0,d=0,p=0,f=0,g=0,m=new T,y=new T,v=this,x=this.vertices;if(x.length<3)return t;if(n<++r)return console.warn("quickDecomp: max level ("+n+") reached."),t;for(var b=0;b<this.vertices.length;++b)if(v.isReflex(b)){e.push(v.vertices[b]),l=c=Number.MAX_VALUE;for(var _=0;_<this.vertices.length;++_)w.left(v.at(b-1),v.at(b),v.at(_))&&w.rightOn(v.at(b-1),v.at(b),v.at(_-1))&&(h=P(v.at(b-1),v.at(b),v.at(_),v.at(_-1)),w.right(v.at(b+1),v.at(b),h)&&(u=w.sqdist(v.vertices[b],h))<c&&(c=u,a=h,f=_)),w.left(v.at(b+1),v.at(b),v.at(_+1))&&w.rightOn(v.at(b+1),v.at(b),v.at(_))&&(h=P(v.at(b+1),v.at(b),v.at(_),v.at(_+1)),w.left(v.at(b-1),v.at(b),h)&&(u=w.sqdist(v.vertices[b],h))<l&&(l=u,o=h,p=_));if(f==(p+1)%this.vertices.length)h[0]=(a[0]+o[0])/2,h[1]=(a[1]+o[1])/2,i.push(h),b<p?(m.append(v,b,p+1),m.vertices.push(h),y.vertices.push(h),0!=f&&y.append(v,f,v.vertices.length),y.append(v,0,b+1)):(0!=b&&m.append(v,b,v.vertices.length),m.append(v,0,p+1),m.vertices.push(h),y.vertices.push(h),y.append(v,f,b+1));else{if(p<f&&(p+=this.vertices.length),d=Number.MAX_VALUE,p<f)return t;for(_=f;_<=p;++_)w.leftOn(v.at(b-1),v.at(b),v.at(_))&&w.rightOn(v.at(b+1),v.at(b),v.at(_))&&(u=w.sqdist(v.at(b),v.at(_)))<d&&(d=u,g=_%this.vertices.length);b<g?(m.append(v,b,g+1),0!=g&&y.append(v,g,x.length),y.append(v,0,b+1)):(0!=b&&m.append(v,b,x.length),m.append(v,0,g+1),y.append(v,g,b+1))}return m.vertices.length<y.vertices.length?(m.quickDecomp(t,e,i,s,n,r),y.quickDecomp(t,e,i,s,n,r)):(y.quickDecomp(t,e,i,s,n,r),m.quickDecomp(t,e,i,s,n,r)),t}return t.push(this),t},T.prototype.removeCollinearPoints=function(t){for(var e=0,i=this.vertices.length-1;3<this.vertices.length&&0<=i;--i)w.collinear(this.at(i-1),this.at(i),this.at(i+1),t)&&(this.vertices.splice(i%this.vertices.length,1),i--,e++);return e}},{"./Line":1,"./Point":2,"./Scalar":4}],4:[function(t,e,i){function s(){}(e.exports=s).eq=function(t,e,i){return i=i||0,Math.abs(t-e)<i}},{}],5:[function(t,e,i){e.exports={Polygon:t("./Polygon"),Point:t("./Point")}},{"./Point":2,"./Polygon":3}],6:[function(t,e,i){e.exports={name:"p2",version:"0.7.1",description:"A JavaScript 2D physics engine.",author:"Stefan Hedman <schteppe@gmail.com> (http://steffe.se)",keywords:["p2.js","p2","physics","engine","2d"],main:"./src/p2.js",engines:{node:"*"},repository:{type:"git",url:"https://github.com/schteppe/p2.js.git"},bugs:{url:"https://github.com/schteppe/p2.js/issues"},licenses:[{type:"MIT"}],devDependencies:{grunt:"^0.4.5","grunt-contrib-jshint":"^0.11.2","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-uglify":"~0.4.0","grunt-contrib-watch":"~0.5.0","grunt-browserify":"~2.0.1","grunt-contrib-concat":"^0.4.0"},dependencies:{"poly-decomp":"0.1.1"}}},{}],7:[function(t,e,i){var p=t("../math/vec2");t("../utils/Utils");function s(t){this.lowerBound=p.create(),t&&t.lowerBound&&p.copy(this.lowerBound,t.lowerBound),this.upperBound=p.create(),t&&t.upperBound&&p.copy(this.upperBound,t.upperBound)}e.exports=s;var f=p.create();s.prototype.setFromPoints=function(t,e,i,s){var n=this.lowerBound,r=this.upperBound;"number"!=typeof i&&(i=0),0!==i?p.rotate(n,t[0],i):p.copy(n,t[0]),p.copy(r,n);for(var o=Math.cos(i),a=Math.sin(i),h=1;h<t.length;h++){var l=t[h];if(0!==i){var c=l[0],u=l[1];f[0]=o*c-a*u,f[1]=a*c+o*u,l=f}for(var d=0;d<2;d++)l[d]>r[d]&&(r[d]=l[d]),l[d]<n[d]&&(n[d]=l[d])}e&&(p.add(this.lowerBound,this.lowerBound,e),p.add(this.upperBound,this.upperBound,e)),s&&(this.lowerBound[0]-=s,this.lowerBound[1]-=s,this.upperBound[0]+=s,this.upperBound[1]+=s)},s.prototype.copy=function(t){p.copy(this.lowerBound,t.lowerBound),p.copy(this.upperBound,t.upperBound)},s.prototype.extend=function(t){for(var e=2;e--;){var i=t.lowerBound[e];this.lowerBound[e]>i&&(this.lowerBound[e]=i);var s=t.upperBound[e];this.upperBound[e]<s&&(this.upperBound[e]=s)}},s.prototype.overlaps=function(t){var e=this.lowerBound,i=this.upperBound,s=t.lowerBound,n=t.upperBound;return(s[0]<=i[0]&&i[0]<=n[0]||e[0]<=n[0]&&n[0]<=i[0])&&(s[1]<=i[1]&&i[1]<=n[1]||e[1]<=n[1]&&n[1]<=i[1])},s.prototype.containsPoint=function(t){var e=this.lowerBound,i=this.upperBound;return e[0]<=t[0]&&t[0]<=i[0]&&e[1]<=t[1]&&t[1]<=i[1]},s.prototype.overlapsRay=function(t){var e=1/t.direction[0],i=1/t.direction[1],s=(this.lowerBound[0]-t.from[0])*e,n=(this.upperBound[0]-t.from[0])*e,r=(this.lowerBound[1]-t.from[1])*i,o=(this.upperBound[1]-t.from[1])*i,a=Math.max(Math.max(Math.min(s,n),Math.min(r,o))),h=Math.min(Math.min(Math.max(s,n),Math.max(r,o)));return h<0?-1:h<a?-1:a}},{"../math/vec2":30,"../utils/Utils":57}],8:[function(t,e,i){var n=t("../math/vec2"),r=t("../objects/Body");function s(t){this.type=t,this.result=[],this.world=null,this.boundingVolumeType=s.AABB}(e.exports=s).AABB=1,s.BOUNDING_CIRCLE=2,s.prototype.setWorld=function(t){this.world=t},s.prototype.getCollisionPairs=function(t){};var o=n.create();s.boundingRadiusCheck=function(t,e){n.sub(o,t.position,e.position);var i=n.squaredLength(o),s=t.boundingRadius+e.boundingRadius;return i<=s*s},s.aabbCheck=function(t,e){return t.getAABB().overlaps(e.getAABB())},s.prototype.boundingVolumeCheck=function(t,e){var i;switch(this.boundingVolumeType){case s.BOUNDING_CIRCLE:i=s.boundingRadiusCheck(t,e);break;case s.AABB:i=s.aabbCheck(t,e);break;default:throw new Error("Bounding volume type not recognized: "+this.boundingVolumeType)}return i},s.canCollide=function(t,e){var i=r.KINEMATIC,s=r.STATIC;return(t.type!==s||e.type!==s)&&(!(t.type===i&&e.type===s||t.type===s&&e.type===i)&&((t.type!==i||e.type!==i)&&((t.sleepState!==r.SLEEPING||e.sleepState!==r.SLEEPING)&&!(t.sleepState===r.SLEEPING&&e.type===s||e.sleepState===r.SLEEPING&&t.type===s))))},s.NAIVE=1,s.SAP=2},{"../math/vec2":30,"../objects/Body":31}],9:[function(t,e,i){t("../shapes/Circle"),t("../shapes/Plane"),t("../shapes/Shape"),t("../shapes/Particle");var h=t("../collision/Broadphase");t("../math/vec2");function s(){h.call(this,h.NAIVE)}(((e.exports=s).prototype=new h).constructor=s).prototype.getCollisionPairs=function(t){for(var e=t.bodies,i=this.result,s=i.length=0,n=e.length;s!==n;s++)for(var r=e[s],o=0;o<s;o++){var a=e[o];h.canCollide(r,a)&&this.boundingVolumeCheck(r,a)&&i.push(r,a)}return i},s.prototype.aabbQuery=function(t,e,i){i=i||[];for(var s=t.bodies,n=0;n<s.length;n++){var r=s[n];r.aabbNeedsUpdate&&r.updateAABB(),r.aabb.overlaps(e)&&i.push(r)}return i}},{"../collision/Broadphase":8,"../math/vec2":30,"../shapes/Circle":39,"../shapes/Particle":43,"../shapes/Plane":44,"../shapes/Shape":45}],10:[function(t,e,i){var X=t("../math/vec2"),W=X.sub,j=X.add,V=X.dot,s=(t("../utils/Utils"),t("../utils/ContactEquationPool")),n=t("../utils/FrictionEquationPool"),r=t("../utils/TupleDictionary"),o=t("../equations/Equation"),a=(t("../equations/ContactEquation"),t("../equations/FrictionEquation"),t("../shapes/Circle")),h=t("../shapes/Convex"),l=t("../shapes/Shape"),T=(t("../objects/Body"),t("../shapes/Box"));e.exports=$;var P=X.fromValues(0,1),H=X.fromValues(0,0),q=X.fromValues(0,0),Y=X.fromValues(0,0),z=X.fromValues(0,0),K=X.fromValues(0,0),O=X.fromValues(0,0),J=X.fromValues(0,0),Q=X.fromValues(0,0),Z=X.fromValues(0,0),k=X.fromValues(0,0),F=X.fromValues(0,0),D=X.fromValues(0,0),U=X.fromValues(0,0),G=X.fromValues(0,0),R=X.fromValues(0,0),L=X.fromValues(0,0),E=X.fromValues(0,0),M=X.fromValues(0,0),N=[];function $(){this.contactEquations=[],this.frictionEquations=[],this.enableFriction=!0,this.enabledEquations=!0,this.slipForce=10,this.frictionCoefficient=.3,this.surfaceVelocity=0,this.contactEquationPool=new s({size:32}),this.frictionEquationPool=new n({size:64}),this.restitution=0,this.stiffness=o.DEFAULT_STIFFNESS,this.relaxation=o.DEFAULT_RELAXATION,this.frictionStiffness=o.DEFAULT_STIFFNESS,this.frictionRelaxation=o.DEFAULT_RELAXATION,this.enableFrictionReduction=!0,this.collidingBodiesLastStep=new r,this.contactSkinSize=.01}var c=X.create(),u=X.create();function x(t,e){X.set(t.vertices[0],.5*-e.length,-e.radius),X.set(t.vertices[1],.5*e.length,-e.radius),X.set(t.vertices[2],.5*e.length,e.radius),X.set(t.vertices[3],.5*-e.length,e.radius)}$.prototype.bodiesOverlap=function(t,e){for(var i=c,s=u,n=0,r=t.shapes.length;n!==r;n++){var o=t.shapes[n];t.toWorldFrame(i,o.position);for(var a=0,h=e.shapes.length;a!==h;a++){var l=e.shapes[a];if(e.toWorldFrame(s,l.position),this[o.type|l.type](t,o,i,o.angle+t.angle,e,l,s,l.angle+e.angle,!0))return!0}}return!1},$.prototype.collidedLastStep=function(t,e){var i=0|t.id,s=0|e.id;return!!this.collidingBodiesLastStep.get(i,s)},$.prototype.reset=function(){this.collidingBodiesLastStep.reset();for(var t=this.contactEquations,e=t.length;e--;){var i=t[e],s=i.bodyA.id,n=i.bodyB.id;this.collidingBodiesLastStep.set(s,n,!0)}for(var r=this.contactEquations,o=this.frictionEquations,a=0;a<r.length;a++)this.contactEquationPool.release(r[a]);for(a=0;a<o.length;a++)this.frictionEquationPool.release(o[a]);this.contactEquations.length=this.frictionEquations.length=0},$.prototype.createContactEquation=function(t,e,i,s){var n=this.contactEquationPool.get();return n.bodyA=t,n.bodyB=e,n.shapeA=i,n.shapeB=s,n.restitution=this.restitution,n.firstImpact=!this.collidedLastStep(t,e),n.stiffness=this.stiffness,n.relaxation=this.relaxation,n.needsUpdate=!0,n.enabled=this.enabledEquations,n.offset=this.contactSkinSize,n},$.prototype.createFrictionEquation=function(t,e,i,s){var n=this.frictionEquationPool.get();return n.bodyA=t,n.bodyB=e,n.shapeA=i,n.shapeB=s,n.setSlipForce(this.slipForce),n.frictionCoefficient=this.frictionCoefficient,n.relativeVelocity=this.surfaceVelocity,n.enabled=this.enabledEquations,n.needsUpdate=!0,n.stiffness=this.frictionStiffness,n.relaxation=this.frictionRelaxation,n.contactEquations.length=0,n},$.prototype.createFrictionFromContact=function(t){var e=this.createFrictionEquation(t.bodyA,t.bodyB,t.shapeA,t.shapeB);return X.copy(e.contactPointA,t.contactPointA),X.copy(e.contactPointB,t.contactPointB),X.rotate90cw(e.t,t.normalA),e.contactEquations.push(t),e},$.prototype.createFrictionFromAverage=function(t){var e=this.contactEquations[this.contactEquations.length-1],i=this.createFrictionEquation(e.bodyA,e.bodyB,e.shapeA,e.shapeB),s=e.bodyA;e.bodyB;X.set(i.contactPointA,0,0),X.set(i.contactPointB,0,0),X.set(i.t,0,0);for(var n=0;n!==t;n++)(e=this.contactEquations[this.contactEquations.length-1-n]).bodyA===s?(X.add(i.t,i.t,e.normalA),X.add(i.contactPointA,i.contactPointA,e.contactPointA),X.add(i.contactPointB,i.contactPointB,e.contactPointB)):(X.sub(i.t,i.t,e.normalA),X.add(i.contactPointA,i.contactPointA,e.contactPointB),X.add(i.contactPointB,i.contactPointB,e.contactPointA)),i.contactEquations.push(e);var r=1/t;return X.scale(i.contactPointA,i.contactPointA,r),X.scale(i.contactPointB,i.contactPointB,r),X.normalize(i.t,i.t),X.rotate90cw(i.t,i.t),i},$.prototype[l.LINE|l.CONVEX]=$.prototype.convexLine=function(t,e,i,s,n,r,o,a,h){return!h&&0},$.prototype[l.LINE|l.BOX]=$.prototype.lineBox=function(t,e,i,s,n,r,o,a,h){return!h&&0};var p=new T({width:1,height:1}),f=X.create();$.prototype[l.CAPSULE|l.CONVEX]=$.prototype[l.CAPSULE|l.BOX]=$.prototype.convexCapsule=function(t,e,i,s,n,r,o,a,h){var l=f;X.set(l,r.length/2,0),X.rotate(l,l,a),X.add(l,l,o);var c=this.circleConvex(n,r,l,a,t,e,i,s,h,r.radius);X.set(l,-r.length/2,0),X.rotate(l,l,a),X.add(l,l,o);var u=this.circleConvex(n,r,l,a,t,e,i,s,h,r.radius);if(h&&(c||u))return!0;var d=p;return x(d,r),this.convexConvex(t,e,i,s,n,d,o,a,h)+c+u},$.prototype[l.CAPSULE|l.LINE]=$.prototype.lineCapsule=function(t,e,i,s,n,r,o,a,h){return!h&&0};var b=X.create(),_=X.create(),w=new T({width:1,height:1});$.prototype[l.CAPSULE|l.CAPSULE]=$.prototype.capsuleCapsule=function(t,e,i,s,n,r,o,a,h){for(var l=b,c=_,u=0,d=0;d<2;d++){X.set(l,(0===d?-1:1)*e.length/2,0),X.rotate(l,l,s),X.add(l,l,i);for(var p=0;p<2;p++){X.set(c,(0===p?-1:1)*r.length/2,0),X.rotate(c,c,a),X.add(c,c,o),this.enableFrictionReduction&&(y=this.enableFriction,this.enableFriction=!1);var f=this.circleCircle(t,e,l,s,n,r,c,a,h,e.radius,r.radius);if(this.enableFrictionReduction&&(this.enableFriction=y),h&&f)return!0;u+=f}}this.enableFrictionReduction&&(y=this.enableFriction,this.enableFriction=!1);var g=w;x(g,e);var m=this.convexCapsule(t,g,i,s,n,r,o,a,h);if(this.enableFrictionReduction&&(this.enableFriction=y),h&&m)return!0;if(u+=m,this.enableFrictionReduction){var y=this.enableFriction;this.enableFriction=!1}x(g,r);var v=this.convexCapsule(n,g,o,a,t,e,i,s,h);return this.enableFrictionReduction&&(this.enableFriction=y),!(!h||!v)||(u+=v,this.enableFrictionReduction&&u&&this.enableFriction&&this.frictionEquations.push(this.createFrictionFromAverage(u)),u)},$.prototype[l.LINE|l.LINE]=$.prototype.lineLine=function(t,e,i,s,n,r,o,a,h){return!h&&0},$.prototype[l.PLANE|l.LINE]=$.prototype.planeLine=function(t,e,i,s,n,r,o,a,h){var l=H,c=q,u=Y,d=z,p=K,f=O,g=J,m=Q,y=Z,v=N,x=0;X.set(l,-r.length/2,0),X.set(c,r.length/2,0),X.rotate(u,l,a),X.rotate(d,c,a),j(u,u,o),j(d,d,o),X.copy(l,u),X.copy(c,d),W(p,c,l),X.normalize(f,p),X.rotate90cw(y,f),X.rotate(m,P,s),v[0]=l,v[1]=c;for(var b=0;b<v.length;b++){var _=v[b];W(g,_,i);var w=V(g,m);if(w<0){if(h)return!0;var T=this.createContactEquation(t,n,e,r);x++,X.copy(T.normalA,m),X.normalize(T.normalA,T.normalA),X.scale(g,m,w),W(T.contactPointA,_,g),W(T.contactPointA,T.contactPointA,t.position),W(T.contactPointB,_,o),j(T.contactPointB,T.contactPointB,o),W(T.contactPointB,T.contactPointB,n.position),this.contactEquations.push(T),this.enableFrictionReduction||this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(T))}}return!h&&(this.enableFrictionReduction||x&&this.enableFriction&&this.frictionEquations.push(this.createFrictionFromAverage(x)),x)},$.prototype[l.PARTICLE|l.CAPSULE]=$.prototype.particleCapsule=function(t,e,i,s,n,r,o,a,h){return this.circleLine(t,e,i,s,n,r,o,a,h,r.radius,0)},$.prototype[l.CIRCLE|l.LINE]=$.prototype.circleLine=function(t,e,i,s,n,r,o,a,h,l,c){l=l||0,c=void 0!==c?c:e.radius;var u=H,d=q,p=Y,f=z,g=K,m=O,y=J,v=Q,x=Z,b=k,_=F,w=D,T=U,P=G,C=N;X.set(v,-r.length/2,0),X.set(x,r.length/2,0),X.rotate(b,v,a),X.rotate(_,x,a),j(b,b,o),j(_,_,o),X.copy(v,b),X.copy(x,_),W(m,x,v),X.normalize(y,m),X.rotate90cw(g,y),W(w,i,v);var S=V(w,g);W(f,v,o),W(T,i,o);var A=c+l;if(Math.abs(S)<A){X.scale(u,g,S),W(p,i,u),X.scale(d,g,V(g,T)),X.normalize(d,d),X.scale(d,d,l),j(p,p,d);var E=V(y,p),M=V(y,v),R=V(y,x);if(M<E&&E<R){if(h)return!0;var L=this.createContactEquation(t,n,e,r);return X.scale(L.normalA,u,-1),X.normalize(L.normalA,L.normalA),X.scale(L.contactPointA,L.normalA,c),j(L.contactPointA,L.contactPointA,i),W(L.contactPointA,L.contactPointA,t.position),W(L.contactPointB,p,o),j(L.contactPointB,L.contactPointB,o),W(L.contactPointB,L.contactPointB,n.position),this.contactEquations.push(L),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(L)),1}}C[0]=v,C[1]=x;for(var B=0;B<C.length;B++){var I=C[B];if(W(w,I,i),X.squaredLength(w)<Math.pow(A,2)){if(h)return!0;L=this.createContactEquation(t,n,e,r);return X.copy(L.normalA,w),X.normalize(L.normalA,L.normalA),X.scale(L.contactPointA,L.normalA,c),j(L.contactPointA,L.contactPointA,i),W(L.contactPointA,L.contactPointA,t.position),W(L.contactPointB,I,o),X.scale(P,L.normalA,-l),j(L.contactPointB,L.contactPointB,P),j(L.contactPointB,L.contactPointB,o),W(L.contactPointB,L.contactPointB,n.position),this.contactEquations.push(L),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(L)),1}}return 0},$.prototype[l.CIRCLE|l.CAPSULE]=$.prototype.circleCapsule=function(t,e,i,s,n,r,o,a,h){return this.circleLine(t,e,i,s,n,r,o,a,h,r.radius)},$.prototype[l.CIRCLE|l.CONVEX]=$.prototype[l.CIRCLE|l.BOX]=$.prototype.circleConvex=function(t,e,i,s,n,r,o,a,h,l){l="number"==typeof l?l:e.radius;for(var c=H,u=q,d=Y,p=z,f=K,g=k,m=F,y=U,v=G,x=R,b=L,_=!1,w=Number.MAX_VALUE,T=r.vertices,P=0;P!==T.length+1;P++){var C=T[P%T.length],S=T[(P+1)%T.length];if(X.rotate(c,C,a),X.rotate(u,S,a),j(c,c,o),j(u,u,o),W(d,u,c),X.normalize(p,d),X.rotate90cw(f,p),X.scale(v,f,-e.radius),j(v,v,i),B(v,r,o,a)){X.sub(x,c,v);var A=Math.abs(X.dot(x,f));A<w&&(X.copy(b,v),w=A,X.scale(y,f,A),X.add(y,y,v),_=!0)}}if(_){if(h)return!0;var E=this.createContactEquation(t,n,e,r);return X.sub(E.normalA,b,i),X.normalize(E.normalA,E.normalA),X.scale(E.contactPointA,E.normalA,l),j(E.contactPointA,E.contactPointA,i),W(E.contactPointA,E.contactPointA,t.position),W(E.contactPointB,y,o),j(E.contactPointB,E.contactPointB,o),W(E.contactPointB,E.contactPointB,n.position),this.contactEquations.push(E),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(E)),1}if(0<l)for(P=0;P<T.length;P++){var M=T[P];if(X.rotate(m,M,a),j(m,m,o),W(g,m,i),X.squaredLength(g)<Math.pow(l,2)){if(h)return!0;E=this.createContactEquation(t,n,e,r);return X.copy(E.normalA,g),X.normalize(E.normalA,E.normalA),X.scale(E.contactPointA,E.normalA,l),j(E.contactPointA,E.contactPointA,i),W(E.contactPointA,E.contactPointA,t.position),W(E.contactPointB,m,o),j(E.contactPointB,E.contactPointB,o),W(E.contactPointB,E.contactPointB,n.position),this.contactEquations.push(E),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(E)),1}}return 0};var g=X.create(),m=X.create(),y=X.create(),v=X.create();function B(t,e,i,s){for(var n=g,r=m,o=y,a=v,h=t,l=e.vertices,c=null,u=0;u!==l.length+1;u++){var d=l[u%l.length],p=l[(u+1)%l.length];X.rotate(n,d,s),X.rotate(r,p,s),j(n,n,i),j(r,r,i),W(o,n,h),W(a,r,h);var f=X.crossLength(o,a);if(null===c&&(c=f),f*c<=0)return!1;c=f}return!0}$.prototype[l.PARTICLE|l.CONVEX]=$.prototype[l.PARTICLE|l.BOX]=$.prototype.particleConvex=function(t,e,i,s,n,r,o,a,h){var l=H,c=q,u=Y,d=z,p=K,f=O,g=J,m=k,y=U,v=E,x=M,b=Number.MAX_VALUE,_=!1,w=r.vertices;if(!B(i,r,o,a))return 0;if(h)return!0;for(var T=0;T!==w.length+1;T++){var P=w[T%w.length],C=w[(T+1)%w.length];X.rotate(l,P,a),X.rotate(c,C,a),j(l,l,o),j(c,c,o),W(u,c,l),X.normalize(d,u),X.rotate90cw(p,d),W(m,i,l);V(m,p);W(f,l,o),W(g,i,o),X.sub(v,l,i);var S=Math.abs(X.dot(v,p));S<b&&(b=S,X.scale(y,p,S),X.add(y,y,i),X.copy(x,p),_=!0)}if(_){var A=this.createContactEquation(t,n,e,r);return X.scale(A.normalA,x,-1),X.normalize(A.normalA,A.normalA),X.set(A.contactPointA,0,0),j(A.contactPointA,A.contactPointA,i),W(A.contactPointA,A.contactPointA,t.position),W(A.contactPointB,y,o),j(A.contactPointB,A.contactPointB,o),W(A.contactPointB,A.contactPointB,n.position),this.contactEquations.push(A),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(A)),1}return 0},$.prototype[l.CIRCLE]=$.prototype.circleCircle=function(t,e,i,s,n,r,o,a,h,l,c){var u=H;l=l||e.radius,c=c||r.radius;W(u,i,o);var d=l+c;if(X.squaredLength(u)>Math.pow(d,2))return 0;if(h)return!0;var p=this.createContactEquation(t,n,e,r);return W(p.normalA,o,i),X.normalize(p.normalA,p.normalA),X.scale(p.contactPointA,p.normalA,l),X.scale(p.contactPointB,p.normalA,-c),j(p.contactPointA,p.contactPointA,i),W(p.contactPointA,p.contactPointA,t.position),j(p.contactPointB,p.contactPointB,o),W(p.contactPointB,p.contactPointB,n.position),this.contactEquations.push(p),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(p)),1},$.prototype[l.PLANE|l.CONVEX]=$.prototype[l.PLANE|l.BOX]=$.prototype.planeConvex=function(t,e,i,s,n,r,o,a,h){var l=H,c=q,u=Y,d=0;X.rotate(c,P,s);for(var p=0;p!==r.vertices.length;p++){var f=r.vertices[p];if(X.rotate(l,f,a),j(l,l,o),W(u,l,i),V(u,c)<=0){if(h)return!0;d++;var g=this.createContactEquation(t,n,e,r);W(u,l,i),X.copy(g.normalA,c);var m=V(u,g.normalA);X.scale(u,g.normalA,m),W(g.contactPointB,l,n.position),W(g.contactPointA,l,u),W(g.contactPointA,g.contactPointA,t.position),this.contactEquations.push(g),this.enableFrictionReduction||this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(g))}}return this.enableFrictionReduction&&this.enableFriction&&d&&this.frictionEquations.push(this.createFrictionFromAverage(d)),d},$.prototype[l.PARTICLE|l.PLANE]=$.prototype.particlePlane=function(t,e,i,s,n,r,o,a,h){var l=H,c=q;a=a||0,W(l,i,o),X.rotate(c,P,a);var u=V(l,c);if(0<u)return 0;if(h)return!0;var d=this.createContactEquation(n,t,r,e);return X.copy(d.normalA,c),X.scale(l,d.normalA,u),W(d.contactPointA,i,l),W(d.contactPointA,d.contactPointA,n.position),W(d.contactPointB,i,t.position),this.contactEquations.push(d),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(d)),1},$.prototype[l.CIRCLE|l.PARTICLE]=$.prototype.circleParticle=function(t,e,i,s,n,r,o,a,h){var l=H;if(W(l,o,i),X.squaredLength(l)>Math.pow(e.radius,2))return 0;if(h)return!0;var c=this.createContactEquation(t,n,e,r);return X.copy(c.normalA,l),X.normalize(c.normalA,c.normalA),X.scale(c.contactPointA,c.normalA,e.radius),j(c.contactPointA,c.contactPointA,i),W(c.contactPointA,c.contactPointA,t.position),W(c.contactPointB,o,n.position),this.contactEquations.push(c),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(c)),1};var C=new a({radius:1}),S=X.create(),A=X.create();X.create();$.prototype[l.PLANE|l.CAPSULE]=$.prototype.planeCapsule=function(t,e,i,s,n,r,o,a,h){var l,c=S,u=A,d=C;X.set(c,-r.length/2,0),X.rotate(c,c,a),j(c,c,o),X.set(u,r.length/2,0),X.rotate(u,u,a),j(u,u,o),d.radius=r.radius,this.enableFrictionReduction&&(l=this.enableFriction,this.enableFriction=!1);var p=this.circlePlane(n,d,c,0,t,e,i,s,h),f=this.circlePlane(n,d,u,0,t,e,i,s,h);if(this.enableFrictionReduction&&(this.enableFriction=l),h)return p||f;var g=p+f;return this.enableFrictionReduction&&g&&this.frictionEquations.push(this.createFrictionFromAverage(g)),g},$.prototype[l.CIRCLE|l.PLANE]=$.prototype.circlePlane=function(t,e,i,s,n,r,o,a,h){var l=t,c=e,u=i,d=n,p=o,f=a;f=f||0;var g=H,m=q,y=Y;W(g,u,p),X.rotate(m,P,f);var v=V(m,g);if(v>c.radius)return 0;if(h)return!0;var x=this.createContactEquation(d,l,r,e);return X.copy(x.normalA,m),X.scale(x.contactPointB,x.normalA,-c.radius),j(x.contactPointB,x.contactPointB,u),W(x.contactPointB,x.contactPointB,l.position),X.scale(y,x.normalA,v),W(x.contactPointA,g,y),j(x.contactPointA,x.contactPointA,p),W(x.contactPointA,x.contactPointA,d.position),this.contactEquations.push(x),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(x)),1},$.prototype[l.CONVEX]=$.prototype[l.CONVEX|l.BOX]=$.prototype[l.BOX]=$.prototype.convexConvex=function(t,e,i,s,n,r,o,a,h,l){var c=H,u=q,d=Y,p=z,f=K,g=J,m=Q,y=Z,v=0;l="number"==typeof l?l:0;if(!$.findSeparatingAxis(e,i,s,r,o,a,c))return 0;W(m,o,i),0<V(c,m)&&X.scale(c,c,-1);var x=$.getClosestEdge(e,s,c,!0),b=$.getClosestEdge(r,a,c);if(-1===x||-1===b)return 0;for(var _=0;_<2;_++){var w,T=x,P=b,C=e,S=r,A=i,E=o,M=s,R=a,L=t,B=n;if(0===_)w=T,T=P,P=w,w=C,C=S,S=w,w=A,A=E,E=w,w=M,M=R,R=w,w=L,L=B,B=w;for(var I=P;I<P+2;I++){var O=S.vertices[(I+S.vertices.length)%S.vertices.length];X.rotate(u,O,R),j(u,u,E);for(var k=0,F=T-1;F<T+2;F++){var D=C.vertices[(F+C.vertices.length)%C.vertices.length],U=C.vertices[(F+1+C.vertices.length)%C.vertices.length];X.rotate(d,D,M),X.rotate(p,U,M),j(d,d,A),j(p,p,A),W(f,p,d),X.rotate90cw(y,f),X.normalize(y,y),W(m,u,d);var G=V(y,m);(F===T&&G<=l||F!==T&&G<=0)&&k++}if(3<=k){if(h)return!0;var N=this.createContactEquation(L,B,C,S);v++;D=C.vertices[T%C.vertices.length],U=C.vertices[(T+1)%C.vertices.length];X.rotate(d,D,M),X.rotate(p,U,M),j(d,d,A),j(p,p,A),W(f,p,d),X.rotate90cw(N.normalA,f),X.normalize(N.normalA,N.normalA),W(m,u,d);G=V(N.normalA,m);X.scale(g,N.normalA,G),W(N.contactPointA,u,A),W(N.contactPointA,N.contactPointA,g),j(N.contactPointA,N.contactPointA,A),W(N.contactPointA,N.contactPointA,L.position),W(N.contactPointB,u,E),j(N.contactPointB,N.contactPointB,E),W(N.contactPointB,N.contactPointB,B.position),this.contactEquations.push(N),this.enableFrictionReduction||this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(N))}}}return this.enableFrictionReduction&&this.enableFriction&&v&&this.frictionEquations.push(this.createFrictionFromAverage(v)),v};var I=X.fromValues(0,0);$.projectConvexOntoAxis=function(t,e,i,s,n){var r,o,a=null,h=null,l=I;X.rotate(l,s,-i);for(var c=0;c<t.vertices.length;c++)r=t.vertices[c],o=V(r,l),(null===a||a<o)&&(a=o),(null===h||o<h)&&(h=o);if(a<h){var u=h;h=a,a=u}var d=V(e,s);X.set(n,h+d,a+d)};var tt=X.fromValues(0,0),et=X.fromValues(0,0),it=X.fromValues(0,0),st=X.fromValues(0,0),nt=X.fromValues(0,0),rt=X.fromValues(0,0);$.findSeparatingAxis=function(t,e,i,s,n,r,o){var a=null,h=!1,l=!1,c=tt,u=et,d=it,p=st,f=nt,g=rt;if(t instanceof T&&s instanceof T)for(var m=0;2!==m;m++){var y=t,v=i;1===m&&(y=s,v=r);for(var x=0;2!==x;x++){0===x?X.set(p,0,1):1===x&&X.set(p,1,0),0!==v&&X.rotate(p,p,v),$.projectConvexOntoAxis(t,e,i,p,f),$.projectConvexOntoAxis(s,n,r,p,g);var b=f,_=g;f[0]>g[0]&&(_=f,b=g,!0),h=(w=_[0]-b[1])<=0,(null===a||a<w)&&(X.copy(o,p),a=w,l=h)}}else for(m=0;2!==m;m++){y=t,v=i;1===m&&(y=s,v=r);for(x=0;x!==y.vertices.length;x++){X.rotate(u,y.vertices[x],v),X.rotate(d,y.vertices[(x+1)%y.vertices.length],v),W(c,d,u),X.rotate90cw(p,c),X.normalize(p,p),$.projectConvexOntoAxis(t,e,i,p,f),$.projectConvexOntoAxis(s,n,r,p,g);var w;b=f,_=g;f[0]>g[0]&&(_=f,b=g,!0),h=(w=_[0]-b[1])<=0,(null===a||a<w)&&(X.copy(o,p),a=w,l=h)}}return l};var d=X.fromValues(0,0),ot=X.fromValues(0,0),at=X.fromValues(0,0);$.getClosestEdge=function(t,e,i,s){var n=d,r=ot,o=at;X.rotate(n,i,-e),s&&X.scale(n,n,-1);for(var a=-1,h=t.vertices.length,l=-1,c=0;c!==h;c++){W(r,t.vertices[(c+1)%h],t.vertices[c%h]),X.rotate90cw(o,r),X.normalize(o,o);var u=V(o,n);(-1===a||l<u)&&(a=c%h,l=u)}return a};var ht=X.create(),lt=X.create(),ct=X.create(),ut=X.create(),dt=X.create(),pt=X.create(),ft=X.create();$.prototype[l.CIRCLE|l.HEIGHTFIELD]=$.prototype.circleHeightfield=function(t,e,i,s,n,r,o,a,h,l){var c=r.heights,u=(l=l||e.radius,r.elementWidth),d=lt,p=ht,f=dt,g=ft,m=pt,y=ct,v=ut,x=Math.floor((i[0]-l-o[0])/u),b=Math.ceil((i[0]+l-o[0])/u);x<0&&(x=0),b>=c.length&&(b=c.length-1);for(var _=c[x],w=c[b],T=x;T<b;T++)c[T]<w&&(w=c[T]),c[T]>_&&(_=c[T]);if(i[1]-l>_)return!h&&0;var P=!1;for(T=x;T<b;T++){X.set(y,T*u,c[T]),X.set(v,(T+1)*u,c[T+1]),X.add(y,y,o),X.add(v,v,o),X.sub(m,v,y),X.rotate(m,m,Math.PI/2),X.normalize(m,m),X.scale(p,m,-l),X.add(p,p,i),X.sub(d,p,y);var C=X.dot(d,m);if(p[0]>=y[0]&&p[0]<v[0]&&C<=0){if(h)return!0;P=!0,X.scale(d,m,-C),X.add(f,p,d),X.copy(g,m);var S=this.createContactEquation(n,t,r,e);X.copy(S.normalA,g),X.scale(S.contactPointB,S.normalA,-l),j(S.contactPointB,S.contactPointB,i),W(S.contactPointB,S.contactPointB,t.position),X.copy(S.contactPointA,f),X.sub(S.contactPointA,S.contactPointA,n.position),this.contactEquations.push(S),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(S))}}if(P=!1,0<l)for(T=x;T<=b;T++)if(X.set(y,T*u,c[T]),X.add(y,y,o),X.sub(d,i,y),X.squaredLength(d)<Math.pow(l,2)){if(h)return!0;P=!0;S=this.createContactEquation(n,t,r,e);X.copy(S.normalA,d),X.normalize(S.normalA,S.normalA),X.scale(S.contactPointB,S.normalA,-l),j(S.contactPointB,S.contactPointB,i),W(S.contactPointB,S.contactPointB,t.position),W(S.contactPointA,y,o),j(S.contactPointA,S.contactPointA,o),W(S.contactPointA,S.contactPointA,n.position),this.contactEquations.push(S),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(S))}return P?1:0};var gt=X.create(),mt=X.create(),yt=X.create(),vt=new h({vertices:[X.create(),X.create(),X.create(),X.create()]});$.prototype[l.BOX|l.HEIGHTFIELD]=$.prototype[l.CONVEX|l.HEIGHTFIELD]=$.prototype.convexHeightfield=function(t,e,i,s,n,r,o,a,h){var l=r.heights,c=r.elementWidth,u=gt,d=mt,p=yt,f=vt,g=Math.floor((t.aabb.lowerBound[0]-o[0])/c),m=Math.ceil((t.aabb.upperBound[0]-o[0])/c);g<0&&(g=0),m>=l.length&&(m=l.length-1);for(var y=l[g],v=l[m],x=g;x<m;x++)l[x]<v&&(v=l[x]),l[x]>y&&(y=l[x]);if(t.aabb.lowerBound[1]>y)return!h&&0;var b=0;for(x=g;x<m;x++){X.set(u,x*c,l[x]),X.set(d,(x+1)*c,l[x+1]),X.add(u,u,o),X.add(d,d,o);X.set(p,.5*(d[0]+u[0]),.5*(d[1]+u[1]-100)),X.sub(f.vertices[0],d,p),X.sub(f.vertices[1],u,p),X.copy(f.vertices[2],f.vertices[1]),X.copy(f.vertices[3],f.vertices[0]),f.vertices[2][1]-=100,f.vertices[3][1]-=100,b+=this.convexConvex(t,e,i,s,n,f,p,0,h)}return b}},{"../equations/ContactEquation":21,"../equations/Equation":22,"../equations/FrictionEquation":23,"../math/vec2":30,"../objects/Body":31,"../shapes/Box":37,"../shapes/Circle":39,"../shapes/Convex":40,"../shapes/Shape":45,"../utils/ContactEquationPool":48,"../utils/FrictionEquationPool":49,"../utils/TupleDictionary":56,"../utils/Utils":57}],11:[function(t,e,i){e.exports=o;var h=t("../math/vec2");t("../collision/RaycastResult"),t("../shapes/Shape"),t("../collision/AABB");function o(t){t=t||{},this.from=t.from?h.fromValues(t.from[0],t.from[1]):h.create(),this.to=t.to?h.fromValues(t.to[0],t.to[1]):h.create(),this.checkCollisionResponse=void 0===t.checkCollisionResponse||t.checkCollisionResponse,this.skipBackfaces=!!t.skipBackfaces,this.collisionMask=void 0!==t.collisionMask?t.collisionMask:-1,this.collisionGroup=void 0!==t.collisionGroup?t.collisionGroup:-1,this.mode=void 0!==t.mode?t.mode:o.ANY,this.callback=t.callback||function(t){},this.direction=h.create(),this.length=1,this.update()}(o.prototype.constructor=o).CLOSEST=1,o.ANY=2,o.ALL=4,o.prototype.update=function(){var t=this.direction;h.sub(t,this.to,this.from),this.length=h.length(t),h.normalize(t,t)},o.prototype.intersectBodies=function(t,e){for(var i=0,s=e.length;!t.shouldStop(this)&&i<s;i++){var n=e[i],r=n.getAABB();(0<=r.overlapsRay(this)||r.containsPoint(this.from))&&this.intersectBody(t,n)}};var l=h.create();o.prototype.intersectBody=function(t,e){var i=this.checkCollisionResponse;if(!i||e.collisionResponse)for(var s=l,n=0,r=e.shapes.length;n<r;n++){var o=e.shapes[n];if((!i||o.collisionResponse)&&(0!=(this.collisionGroup&o.collisionMask)&&0!=(o.collisionGroup&this.collisionMask))){h.rotate(s,o.position,e.angle),h.add(s,s,e.position);var a=o.angle+e.angle;if(this.intersectShape(t,o,a,s,e),t.shouldStop(this))break}}},o.prototype.intersectShape=function(t,e,i,s,n){(function(t,e,i){h.sub(r,i,t);var s=h.dot(r,e);return h.scale(a,e,s),h.add(a,a,t),h.squaredDistance(i,a)})(this.from,this.direction,s)>e.boundingRadius*e.boundingRadius||(this._currentBody=n,(this._currentShape=e).raycast(t,this,s,i),this._currentBody=this._currentShape=null)},o.prototype.getAABB=function(t){var e=this.to,i=this.from;h.set(t.lowerBound,Math.min(e[0],i[0]),Math.min(e[1],i[1])),h.set(t.upperBound,Math.max(e[0],i[0]),Math.max(e[1],i[1]))};h.create();o.prototype.reportIntersection=function(t,e,i,s){this.from,this.to;var n=this._currentShape,r=this._currentBody;if(!(this.skipBackfaces&&0<h.dot(i,this.direction)))switch(this.mode){case o.ALL:t.set(i,n,r,e,s),this.callback(t);break;case o.CLOSEST:(e<t.fraction||!t.hasHit())&&t.set(i,n,r,e,s);break;case o.ANY:t.set(i,n,r,e,s)}};var r=h.create(),a=h.create()},{"../collision/AABB":7,"../collision/RaycastResult":12,"../math/vec2":30,"../shapes/Shape":45}],12:[function(t,e,i){var r=t("../math/vec2"),s=t("../collision/Ray");function n(){this.normal=r.create(),this.shape=null,this.body=null,this.faceIndex=-1,this.fraction=-1,this.isStopped=!1}(e.exports=n).prototype.reset=function(){r.set(this.normal,0,0),this.shape=null,this.body=null,this.faceIndex=-1,this.fraction=-1,this.isStopped=!1},n.prototype.getHitDistance=function(t){return r.distance(t.from,t.to)*this.fraction},n.prototype.hasHit=function(){return-1!==this.fraction},n.prototype.getHitPoint=function(t,e){r.lerp(t,e.from,e.to,this.fraction)},n.prototype.stop=function(){this.isStopped=!0},n.prototype.shouldStop=function(t){return this.isStopped||-1!==this.fraction&&t.mode===s.ANY},n.prototype.set=function(t,e,i,s,n){r.copy(this.normal,t),this.shape=e,this.body=i,this.fraction=s,this.faceIndex=n}},{"../collision/Ray":11,"../math/vec2":30}],13:[function(t,e,i){var s=t("../utils/Utils"),u=t("../collision/Broadphase");function n(){u.call(this,u.SAP),this.axisList=[],this.axisIndex=0;var i=this;this._addBodyHandler=function(t){i.axisList.push(t.body)},this._removeBodyHandler=function(t){var e=i.axisList.indexOf(t.body);-1!==e&&i.axisList.splice(e,1)}}(((e.exports=n).prototype=new u).constructor=n).prototype.setWorld=function(t){this.axisList.length=0,s.appendArray(this.axisList,t.bodies),t.off("addBody",this._addBodyHandler).off("removeBody",this._removeBodyHandler),t.on("addBody",this._addBodyHandler).on("removeBody",this._removeBodyHandler),this.world=t},n.sortAxisList=function(t,e){e|=0;for(var i=1,s=t.length;i<s;i++){for(var n=t[i],r=i-1;0<=r&&!(t[r].aabb.lowerBound[e]<=n.aabb.lowerBound[e]);r--)t[r+1]=t[r];t[r+1]=n}return t},n.prototype.sortList=function(){var t=this.axisList,e=this.axisIndex;n.sortAxisList(t,e)},n.prototype.getCollisionPairs=function(t){var e=this.axisList,i=this.result,s=this.axisIndex;i.length=0;for(var n=e.length;n--;){var r=e[n];r.aabbNeedsUpdate&&r.updateAABB()}this.sortList();for(var o=0,a=0|e.length;o!==a;o++)for(var h=e[o],l=o+1;l<a;l++){var c=e[l];if(!(c.aabb.lowerBound[s]<=h.aabb.upperBound[s]))break;u.canCollide(h,c)&&this.boundingVolumeCheck(h,c)&&i.push(h,c)}return i},n.prototype.aabbQuery=function(t,e,i){i=i||[],this.sortList();var s=this.axisIndex,n="x";1===s&&(n="y"),2===s&&(n="z");for(var r=this.axisList,o=(e.lowerBound[n],e.upperBound[n],0);o<r.length;o++){var a=r[o];a.aabbNeedsUpdate&&a.updateAABB(),a.aabb.overlaps(e)&&i.push(a)}return i}},{"../collision/Broadphase":8,"../utils/Utils":57}],14:[function(t,e,i){e.exports=s;var n=t("../utils/Utils");function s(t,e,i,s){this.type=i,s=n.defaults(s,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=t,this.bodyB=e,this.collideConnected=s.collideConnected,s.wakeUpBodies&&(t&&t.wakeUp(),e&&e.wakeUp())}s.prototype.update=function(){throw new Error("method update() not implmemented in this Constraint subclass!")},s.DISTANCE=1,s.GEAR=2,s.LOCK=3,s.PRISMATIC=4,s.REVOLUTE=5,s.prototype.setStiffness=function(t){for(var e=this.equations,i=0;i!==e.length;i++){var s=e[i];s.stiffness=t,s.needsUpdate=!0}},s.prototype.setRelaxation=function(t){for(var e=this.equations,i=0;i!==e.length;i++){var s=e[i];s.relaxation=t,s.needsUpdate=!0}}},{"../utils/Utils":57}],15:[function(t,e,i){var p=t("./Constraint"),f=t("../equations/Equation"),g=t("../math/vec2"),m=t("../utils/Utils");function s(t,e,i){i=m.defaults(i,{localAnchorA:[0,0],localAnchorB:[0,0]}),p.call(this,t,e,p.DISTANCE,i),this.localAnchorA=g.fromValues(i.localAnchorA[0],i.localAnchorA[1]),this.localAnchorB=g.fromValues(i.localAnchorB[0],i.localAnchorB[1]);var s,n=this.localAnchorA,r=this.localAnchorB;if(this.distance=0,"number"==typeof i.distance)this.distance=i.distance;else{var o=g.create(),a=g.create(),h=g.create();g.rotate(o,n,t.angle),g.rotate(a,r,e.angle),g.add(h,e.position,a),g.sub(h,h,o),g.sub(h,h,t.position),this.distance=g.length(h)}s=void 0===i.maxForce?Number.MAX_VALUE:i.maxForce;var l=new f(t,e,-s,s);this.equations=[l],this.maxForce=s;h=g.create();var c=g.create(),u=g.create(),d=this;l.computeGq=function(){var t=this.bodyA,e=this.bodyB,i=t.position,s=e.position;return g.rotate(c,n,t.angle),g.rotate(u,r,e.angle),g.add(h,s,u),g.sub(h,h,c),g.sub(h,h,i),g.length(h)-d.distance},this.setMaxForce(s),this.upperLimitEnabled=!1,this.upperLimit=1,this.lowerLimitEnabled=!1,this.lowerLimit=0,this.position=0}((e.exports=s).prototype=new p).constructor=s;var c=g.create(),u=g.create(),d=g.create();s.prototype.update=function(){var t=this.equations[0],e=this.bodyA,i=this.bodyB,s=(this.distance,e.position),n=i.position,r=this.equations[0],o=t.G;g.rotate(u,this.localAnchorA,e.angle),g.rotate(d,this.localAnchorB,i.angle),g.add(c,n,d),g.sub(c,c,u),g.sub(c,c,s),this.position=g.length(c);var a=!1;if(this.upperLimitEnabled&&this.position>this.upperLimit&&(r.maxForce=0,r.minForce=-this.maxForce,this.distance=this.upperLimit,a=!0),this.lowerLimitEnabled&&this.position<this.lowerLimit&&(r.maxForce=this.maxForce,r.minForce=0,this.distance=this.lowerLimit,a=!0),!this.lowerLimitEnabled&&!this.upperLimitEnabled||a){r.enabled=!0,g.normalize(c,c);var h=g.crossLength(u,c),l=g.crossLength(d,c);o[0]=-c[0],o[1]=-c[1],o[2]=-h,o[3]=c[0],o[4]=c[1],o[5]=l}else r.enabled=!1},s.prototype.setMaxForce=function(t){var e=this.equations[0];e.minForce=-t,e.maxForce=t},s.prototype.getMaxForce=function(){return this.equations[0].maxForce}},{"../equations/Equation":22,"../math/vec2":30,"../utils/Utils":57,"./Constraint":14}],16:[function(t,e,i){var s=t("./Constraint"),n=(t("../equations/Equation"),t("../equations/AngleLockEquation"));t("../math/vec2");function r(t,e,i){i=i||{},s.call(this,t,e,s.GEAR,i),this.ratio=void 0!==i.ratio?i.ratio:1,this.angle=void 0!==i.angle?i.angle:e.angle-this.ratio*t.angle,i.angle=this.angle,i.ratio=this.ratio,this.equations=[new n(t,e,i)],void 0!==i.maxTorque&&this.setMaxTorque(i.maxTorque)}(((e.exports=r).prototype=new s).constructor=r).prototype.update=function(){var t=this.equations[0];t.ratio!==this.ratio&&t.setRatio(this.ratio),t.angle=this.angle},r.prototype.setMaxTorque=function(t){this.equations[0].setMaxTorque(t)},r.prototype.getMaxTorque=function(t){return this.equations[0].maxForce}},{"../equations/AngleLockEquation":20,"../equations/Equation":22,"../math/vec2":30,"./Constraint":14}],17:[function(t,e,i){var d=t("./Constraint"),p=t("../math/vec2"),f=t("../equations/Equation");function s(t,e,i){i=i||{},d.call(this,t,e,d.LOCK,i);var s=void 0===i.maxForce?Number.MAX_VALUE:i.maxForce,n=(i.localAngleB,new f(t,e,-s,s)),r=new f(t,e,-s,s),o=new f(t,e,-s,s),a=p.create(),h=p.create(),l=this;n.computeGq=function(){return p.rotate(a,l.localOffsetB,t.angle),p.sub(h,e.position,t.position),p.sub(h,h,a),h[0]},r.computeGq=function(){return p.rotate(a,l.localOffsetB,t.angle),p.sub(h,e.position,t.position),p.sub(h,h,a),h[1]};var c=p.create(),u=p.create();o.computeGq=function(){return p.rotate(c,l.localOffsetB,e.angle-l.localAngleB),p.scale(c,c,-1),p.sub(h,t.position,e.position),p.add(h,h,c),p.rotate(u,c,-Math.PI/2),p.normalize(u,u),p.dot(h,u)},this.localOffsetB=p.create(),i.localOffsetB?p.copy(this.localOffsetB,i.localOffsetB):(p.sub(this.localOffsetB,e.position,t.position),p.rotate(this.localOffsetB,this.localOffsetB,-t.angle)),this.localAngleB=0,"number"==typeof i.localAngleB?this.localAngleB=i.localAngleB:this.localAngleB=e.angle-t.angle,this.equations.push(n,r,o),this.setMaxForce(s)}(((e.exports=s).prototype=new d).constructor=s).prototype.setMaxForce=function(t){for(var e=this.equations,i=0;i<this.equations.length;i++)e[i].maxForce=t,e[i].minForce=-t},s.prototype.getMaxForce=function(){return this.equations[0].maxForce};var r=p.create(),o=p.create(),a=p.create(),h=p.fromValues(1,0),l=p.fromValues(0,1);s.prototype.update=function(){var t=this.equations[0],e=this.equations[1],i=this.equations[2],s=this.bodyA,n=this.bodyB;p.rotate(r,this.localOffsetB,s.angle),p.rotate(o,this.localOffsetB,n.angle-this.localAngleB),p.scale(o,o,-1),p.rotate(a,o,Math.PI/2),p.normalize(a,a),t.G[0]=-1,t.G[1]=0,t.G[2]=-p.crossLength(r,h),t.G[3]=1,e.G[0]=0,e.G[1]=-1,e.G[2]=-p.crossLength(r,l),e.G[4]=1,i.G[0]=-a[0],i.G[1]=-a[1],i.G[3]=a[0],i.G[4]=a[1],i.G[5]=p.crossLength(o,a)}},{"../equations/Equation":22,"../math/vec2":30,"./Constraint":14}],18:[function(t,e,i){var g=t("./Constraint"),m=t("../equations/ContactEquation"),y=t("../equations/Equation"),v=t("../math/vec2"),x=t("../equations/RotationalLockEquation");function s(s,n,t){t=t||{},g.call(this,s,n,g.PRISMATIC,t);var r=v.fromValues(0,0),o=v.fromValues(1,0),a=v.fromValues(0,0);t.localAnchorA&&v.copy(r,t.localAnchorA),t.localAxisA&&v.copy(o,t.localAxisA),t.localAnchorB&&v.copy(a,t.localAnchorB),this.localAnchorA=r,this.localAnchorB=a,this.localAxisA=o;var e=this.maxForce=void 0!==t.maxForce?t.maxForce:Number.MAX_VALUE,i=new y(s,n,-e,e),h=new v.create,l=new v.create,c=new v.create,u=new v.create;if(i.computeGq=function(){return v.dot(c,u)},i.updateJacobian=function(){var t=this.G,e=s.position,i=n.position;v.rotate(h,r,s.angle),v.rotate(l,a,n.angle),v.add(c,i,l),v.sub(c,c,e),v.sub(c,c,h),v.rotate(u,o,s.angle+Math.PI/2),t[0]=-u[0],t[1]=-u[1],t[2]=-v.crossLength(h,u)+v.crossLength(u,c),t[3]=u[0],t[4]=u[1],t[5]=v.crossLength(l,u)},this.equations.push(i),!t.disableRotationalLock){var d=new x(s,n,-e,e);this.equations.push(d)}this.position=0,this.velocity=0,this.lowerLimitEnabled=void 0!==t.lowerLimit,this.upperLimitEnabled=void 0!==t.upperLimit,this.lowerLimit=void 0!==t.lowerLimit?t.lowerLimit:0,this.upperLimit=void 0!==t.upperLimit?t.upperLimit:1,this.upperLimitEquation=new m(s,n),this.lowerLimitEquation=new m(s,n),this.upperLimitEquation.minForce=this.lowerLimitEquation.minForce=0,this.upperLimitEquation.maxForce=this.lowerLimitEquation.maxForce=e,this.motorEquation=new y(s,n),this.motorEnabled=!1,this.motorSpeed=0;var p=this,f=this.motorEquation;f.computeGW;f.computeGq=function(){return 0},f.computeGW=function(){var t=this.G,e=this.bodyA,i=this.bodyB,s=e.velocity,n=i.velocity,r=e.angularVelocity,o=i.angularVelocity;return this.gmult(t,s,r,n,o)+p.motorSpeed}}((e.exports=s).prototype=new g).constructor=s;var f=v.create(),b=v.create(),_=v.create(),w=v.create(),T=v.create(),P=v.create();s.prototype.update=function(){var t=this.equations,e=t[0],i=this.upperLimit,s=this.lowerLimit,n=this.upperLimitEquation,r=this.lowerLimitEquation,o=this.bodyA,a=this.bodyB,h=this.localAxisA,l=this.localAnchorA,c=this.localAnchorB;e.updateJacobian(),v.rotate(f,h,o.angle),v.rotate(w,l,o.angle),v.add(b,w,o.position),v.rotate(T,c,a.angle),v.add(_,T,a.position);var u,d=this.position=v.dot(_,f)-v.dot(b,f);if(this.motorEnabled){var p=this.motorEquation.G;p[0]=f[0],p[1]=f[1],p[2]=v.crossLength(f,T),p[3]=-f[0],p[4]=-f[1],p[5]=-v.crossLength(f,w)}this.upperLimitEnabled&&i<d?(v.scale(n.normalA,f,-1),v.sub(n.contactPointA,b,o.position),v.sub(n.contactPointB,_,a.position),v.scale(P,f,i),v.add(n.contactPointA,n.contactPointA,P),-1===t.indexOf(n)&&t.push(n)):-1!==(u=t.indexOf(n))&&t.splice(u,1);this.lowerLimitEnabled&&d<s?(v.scale(r.normalA,f,1),v.sub(r.contactPointA,b,o.position),v.sub(r.contactPointB,_,a.position),v.scale(P,f,s),v.sub(r.contactPointB,r.contactPointB,P),-1===t.indexOf(r)&&t.push(r)):-1!==(u=t.indexOf(r))&&t.splice(u,1)},s.prototype.enableMotor=function(){this.motorEnabled||(this.equations.push(this.motorEquation),this.motorEnabled=!0)},s.prototype.disableMotor=function(){if(this.motorEnabled){var t=this.equations.indexOf(this.motorEquation);this.equations.splice(t,1),this.motorEnabled=!1}},s.prototype.setLimits=function(t,e){"number"==typeof t?(this.lowerLimit=t,this.lowerLimitEnabled=!0):(this.lowerLimit=t,this.lowerLimitEnabled=!1),"number"==typeof e?(this.upperLimit=e,this.upperLimitEnabled=!0):(this.upperLimit=e,this.upperLimitEnabled=!1)}},{"../equations/ContactEquation":21,"../equations/Equation":22,"../equations/RotationalLockEquation":24,"../math/vec2":30,"./Constraint":14}],19:[function(t,e,i){var h=t("./Constraint"),l=t("../equations/Equation"),c=t("../equations/RotationalVelocityEquation"),u=t("../equations/RotationalLockEquation"),p=t("../math/vec2");e.exports=s;var f=p.create(),g=p.create(),m=p.fromValues(1,0),y=p.fromValues(0,1),d=p.create();function s(t,e,i){i=i||{},h.call(this,t,e,h.REVOLUTE,i);var s=this.maxForce=void 0!==i.maxForce?i.maxForce:Number.MAX_VALUE;this.pivotA=p.create(),this.pivotB=p.create(),i.worldPivot?(p.sub(this.pivotA,i.worldPivot,t.position),p.sub(this.pivotB,i.worldPivot,e.position),p.rotate(this.pivotA,this.pivotA,-t.angle),p.rotate(this.pivotB,this.pivotB,-e.angle)):(p.copy(this.pivotA,i.localPivotA),p.copy(this.pivotB,i.localPivotB));var n=this.equations=[new l(t,e,-s,s),new l(t,e,-s,s)],r=n[0],o=n[1],a=this;r.computeGq=function(){return p.rotate(f,a.pivotA,t.angle),p.rotate(g,a.pivotB,e.angle),p.add(d,e.position,g),p.sub(d,d,t.position),p.sub(d,d,f),p.dot(d,m)},o.computeGq=function(){return p.rotate(f,a.pivotA,t.angle),p.rotate(g,a.pivotB,e.angle),p.add(d,e.position,g),p.sub(d,d,t.position),p.sub(d,d,f),p.dot(d,y)},o.minForce=r.minForce=-s,o.maxForce=r.maxForce=s,this.motorEquation=new c(t,e),this.motorEnabled=!1,this.angle=0,this.lowerLimitEnabled=!1,this.upperLimitEnabled=!1,this.lowerLimit=0,this.upperLimit=0,this.upperLimitEquation=new u(t,e),this.lowerLimitEquation=new u(t,e),this.upperLimitEquation.minForce=0,this.lowerLimitEquation.maxForce=0}((s.prototype=new h).constructor=s).prototype.setLimits=function(t,e){"number"==typeof t?(this.lowerLimit=t,this.lowerLimitEnabled=!0):(this.lowerLimit=t,this.lowerLimitEnabled=!1),"number"==typeof e?(this.upperLimit=e,this.upperLimitEnabled=!0):(this.upperLimit=e,this.upperLimitEnabled=!1)},s.prototype.update=function(){var t,e=this.bodyA,i=this.bodyB,s=this.pivotA,n=this.pivotB,r=this.equations,o=(r[0],r[1],r[0]),a=r[1],h=this.upperLimit,l=this.lowerLimit,c=this.upperLimitEquation,u=this.lowerLimitEquation,d=this.angle=i.angle-e.angle;this.upperLimitEnabled&&h<d?(c.angle=h,-1===r.indexOf(c)&&r.push(c)):-1!==(t=r.indexOf(c))&&r.splice(t,1);this.lowerLimitEnabled&&d<l?(u.angle=l,-1===r.indexOf(u)&&r.push(u)):-1!==(t=r.indexOf(u))&&r.splice(t,1);p.rotate(f,s,e.angle),