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