2014-05-29 16:37:28 +00:00
/* p2.js custom build for Phaser v2.0.6 - http://phaser.io - @photonstorm - (c) 2014 Photon Storm Ltd. */
2014-04-29 14:39:53 +00:00
! function ( a ) { "object" == typeof exports ? module . exports = a ( ) : "function" == typeof define && define . amd ? define ( "p2" , function ( ) { return this . p2 = a ( ) } ( ) ) : "undefined" != typeof window ? window . p2 = a ( ) : "undefined" != typeof global ? self . p2 = a ( ) : "undefined" != typeof self && ( self . p2 = a ( ) ) } ( function ( ) { return function a ( b , c , d ) { function e ( g , h ) { if ( ! c [ g ] ) { if ( ! b [ g ] ) { var i = "function" == typeof require && require ; if ( ! h && i ) return i ( g , ! 0 ) ; if ( f ) return f ( g , ! 0 ) ; throw new Error ( "Cannot find module '" + g + "'" ) } var j = c [ g ] = { exports : { } } ; b [ g ] [ 0 ] . call ( j . exports , function ( a ) { var c = b [ g ] [ 1 ] [ a ] ; return e ( c ? c : a ) } , j , j . exports , a , b , c , d ) } return c [ g ] . exports } for ( var f = "function" == typeof require && require , g = 0 ; g < d . length ; g ++ ) e ( d [ g ] ) ; return e } ( { 1 : [ function ( a , b , c ) { if ( ! d ) var d = 1e-6 ; if ( ! e ) var e = "undefined" != typeof Float32Array ? Float32Array : Array ; var f = { } ; f . setMatrixArrayType = function ( a ) { e = a } , "undefined" != typeof c && ( c . glMatrix = f ) ; var g = { } ; g . create = function ( ) { var a = new e ( 2 ) ; return a [ 0 ] = 0 , a [ 1 ] = 0 , a } , g . clone = function ( a ) { var b = new e ( 2 ) ; return b [ 0 ] = a [ 0 ] , b [ 1 ] = a [ 1 ] , b } , g . fromValues = function ( a , b ) { var c = new e ( 2 ) ; return c [ 0 ] = a , c [ 1 ] = b , c } , g . copy = function ( a , b ) { return a [ 0 ] = b [ 0 ] , a [ 1 ] = b [ 1 ] , a } , g . set = function ( a , b , c ) { return a [ 0 ] = b , a [ 1 ] = c , a } , g . add = function ( a , b , c ) { return a [ 0 ] = b [ 0 ] + c [ 0 ] , a [ 1 ] = b [ 1 ] + c [ 1 ] , a } , g . subtract = function ( a , b , c ) { return a [ 0 ] = b [ 0 ] - c [ 0 ] , a [ 1 ] = b [ 1 ] - c [ 1 ] , a } , g . sub = g . subtract , g . multiply = function ( a , b , c ) { return a [ 0 ] = b [ 0 ] * c [ 0 ] , a [ 1 ] = b [ 1 ] * c [ 1 ] , a } , g . mul = g . multiply , g . divide = function ( a , b , c ) { return a [ 0 ] = b [ 0 ] / c [ 0 ] , a [ 1 ] = b [ 1 ] / c [ 1 ] , a } , g . div = g . divide , g . min = function ( a , b , c ) { return a [ 0 ] = Math . min ( b [ 0 ] , c [ 0 ] ) , a [ 1 ] = Math . min ( b [ 1 ] , c [ 1 ] ) , a } , g . max = function ( a , b , c ) { return a [ 0 ] = Math . max ( b [ 0 ] , c [ 0 ] ) , a [ 1 ] = Math . max ( b [ 1 ] , c [ 1 ] ) , a } , g . scale = function ( a , b , c ) { return a [ 0 ] = b [ 0 ] * c , a [ 1 ] = b [ 1 ] * c , a } , g . distance = function ( a , b ) { var c = b [ 0 ] - a [ 0 ] , d = b [ 1 ] - a [ 1 ] ; return Math . sqrt ( c * c + d * d ) } , g . dist = g . distance , g . squaredDistance = function ( a , b ) { var c = b [ 0 ] - a [ 0 ] , d = b [ 1 ] - a [ 1 ] ; return c * c + d * d } , g . sqrDist = g . squaredDistance , g . length = function ( a ) { var b = a [ 0 ] , c = a [ 1 ] ; return Math . sqrt ( b * b + c * c ) } , g . len = g . length , g . squaredLength = function ( a ) { var b = a [ 0 ] , c = a [ 1 ] ; return b * b + c * c } , g . sqrLen = g . squaredLength , g . negate = function ( a , b ) { return a [ 0 ] = - b [ 0 ] , a [ 1 ] = - b [ 1 ] , a } , g . normalize = function ( a , b ) { var c = b [ 0 ] , d = b [ 1 ] , e = c * c + d * d ; return e > 0 && ( e = 1 / Math . sqrt ( e ) , a [ 0 ] = b [ 0 ] * e , a [ 1 ] = b [ 1 ] * e ) , a } , g . dot = function ( a , b ) { return a [ 0 ] * b [ 0 ] + a [ 1 ] * b [ 1 ] } , g . cross = function ( a , b , c ) { var d = b [ 0 ] * c [ 1 ] - b [ 1 ] * c [ 0 ] ; return a [ 0 ] = a [ 1 ] = 0 , a [ 2 ] = d , a } , g . lerp = function ( a , b , c , d ) { var e = b [ 0 ] , f = b [ 1 ] ; return a [ 0 ] = e + d * ( c [ 0 ] - e ) , a [ 1 ] = f + d * ( c [ 1 ] - f ) , a } , g . transformMat2 = function ( a , b , c ) { var d = b [ 0 ] , e = b [ 1 ] ; return a [ 0 ] = c [ 0 ] * d + c [ 2 ] * e , a [ 1 ] = c [ 1 ] * d + c [ 3 ] * e , a } , g . transformMat2d = function ( a , b , c ) { var d = b [ 0 ] , e = b [ 1 ] ; return a [ 0 ] = c [ 0 ] * d + c [ 2 ] * e + c [ 4 ] , a [ 1 ] = c [ 1 ] * d + c [ 3 ] * e + c [ 5 ] , a } , g . transformMat3 = function ( a , b , c ) { var d = b [ 0 ] , e = b [ 1 ] ; return a [ 0 ] = c [ 0 ] * d + c [ 3 ] * e + c [ 6 ] , a [ 1 ] = c [ 1 ] * d + c [ 4 ] * e + c [ 7 ] , a } , g . transformMat4 = function ( a , b , c ) { var d = b [ 0 ] , e = b [ 1 ] ; return a [ 0 ] = c [ 0 ] * d + c [ 4 ] * e + c [ 12 ] , a [ 1 ] = c [ 1 ] * d + c [ 5 ] * e + c [ 13 ] , a } , g . forEach = function ( ) { var a = g . create ( ) ; return function ( b , c , d , e , f , g ) { var h , i ; for ( c || ( c = 2 ) , d || ( d = 0 ) , i = e ? Math . min ( e * c + d , b . length ) : b . length , h = d ; i > h ; h += c ) a [ 0 ] = b [ h ] , a [ 1 ] = b [ h + 1 ] , f ( a , a , g ) , b [ h ] = a [ 0 ] , b [ h + 1 ] = a [ 1 ] ; return b } } ( ) , g . str = function ( a ) { return "vec2(" + a [ 0 ] + ", " + a [ 1 ] + ")" } , "undefined" != typeof c && ( c . vec2 = g ) } , { } ] , 2 : [ function ( a , b ) { function c ( ) { } var d = a ( "./Scalar" ) ; b . exports = c , c . lineInt = function ( a , b , c ) { c = c || 0 ; var e , f , g , h , i , j , k , l = [ 0 , 0 ] ; return e = a [ 1 ] [ 1 ] - a [ 0 ] [ 1 ] , f = a [ 0 ] [ 0 ] - a [ 1 ] [ 0 ] , g = e * a [ 0 ] [ 0 ] + f * a [ 0 ] [ 1 ] , h = b [ 1 ] [ 1 ] - b [ 0 ] [ 1 ] , i = b [ 0 ] [ 0 ] - b [ 1 ] [ 0 ] , j = h * b [ 0 ] [ 0 ] + i * b [ 0 ] [ 1 ] , k = e * i - h * f , d . eq ( k , 0 , c ) || ( l [ 0 ] = ( i * g - f * j ) / k , l [ 1 ] = ( e * j - h * g ) / k ) , l } , c . segmentsIntersect = function ( a , b , c , d ) { var e = b [ 0 ] - a [ 0 ] , f = b [ 1 ] - a [ 1 ] , g = d [ 0 ] - c [ 0 ] , h = d [ 1 ] - c [ 1 ] ; if ( g * f - h * e == 0 ) return ! 1 ; var i = ( e * ( c [ 1 ] - a [ 1 ] ) + f * ( a [ 0 ] - c [ 0 ] ) ) / ( g * f - h * e ) , j = ( g * ( a [ 1 ] - c [ 1 ] ) + h * ( c [ 0 ] - a [ 0 ] ) ) / ( h * e - g * f ) ; return i >= 0 && 1 >= i && j >= 0 && 1 >= j } } , { "./Scalar" : 5 } ] , 3 : [ function ( a , b ) { function c ( ) { } b . exports = c , c . area = function ( a , b , c ) { return ( b [ 0 ] - a [ 0 ] ) * ( c [ 1 ] - a [ 1 ] ) - ( c [ 0 ] - a [ 0 ] ) * ( b [ 1 ] - a [ 1 ] ) } , c . left = function ( a , b , d ) { return c . area ( a , b , d ) > 0 } , c . leftOn = function ( a , b , d ) { return c . area ( a , b , d ) >= 0 } , c . right = function ( a , b , d ) { return c . area ( a , b , d ) < 0 } , c . rightOn = function ( a , b , d ) { return c . area ( a , b , d ) <= 0 } ; var d = [ ] , e = [ ] ; c . collinear = function ( a , b , f , g
c . prototype [ q . CIRCLE | q . HEIGHTFIELD ] = c . prototype . circleHeightfield = function ( a , b , c , d , e , i , j , k , l , m ) { var n = i . data , m = m || b . radius , o = i . elementWidth , p = hb , q = gb , r = kb , s = mb , t = lb , u = ib , v = jb , w = Math . floor ( ( c [ 0 ] - m - j [ 0 ] ) / o ) , x = Math . ceil ( ( c [ 0 ] + m - j [ 0 ] ) / o ) ; 0 > w && ( w = 0 ) , x >= n . length && ( x = n . length - 1 ) ; for ( var y = n [ w ] , z = n [ x ] , A = w ; x > A ; A ++ ) n [ A ] < z && ( z = n [ A ] ) , n [ A ] > y && ( y = n [ A ] ) ; if ( c [ 1 ] - m > y ) return l ? ! 1 : 0 ; c [ 1 ] + m < z ; for ( var B = ! 1 , A = w ; x > A ; A ++ ) { f . set ( u , A * o , n [ A ] ) , f . set ( v , ( A + 1 ) * o , n [ A + 1 ] ) , f . add ( u , u , j ) , f . add ( v , v , j ) , f . sub ( t , v , u ) , f . rotate ( t , t , Math . PI / 2 ) , f . normalize ( t , t ) , f . scale ( q , t , - m ) , f . add ( q , q , c ) , f . sub ( p , q , u ) ; var C = f . dot ( p , t ) ; if ( q [ 0 ] >= u [ 0 ] && q [ 0 ] < v [ 0 ] && 0 >= C ) { if ( l ) return ! 0 ; B = ! 0 , f . scale ( p , t , - C ) , f . add ( r , q , p ) , f . copy ( s , t ) ; var D = this . createContactEquation ( e , a , i , b ) ; f . copy ( D . normalA , s ) , f . scale ( D . contactPointB , D . normalA , - m ) , h ( D . contactPointB , D . contactPointB , c ) , g ( D . contactPointB , D . contactPointB , a . position ) , f . copy ( D . contactPointA , r ) , f . sub ( D . contactPointA , D . contactPointA , e . position ) , this . contactEquations . push ( D ) , this . enableFriction && this . frictionEquations . push ( this . createFrictionFromContact ( D ) ) } } if ( B = ! 1 , m > 0 ) for ( var A = w ; x >= A ; A ++ ) if ( f . set ( u , A * o , n [ A ] ) , f . add ( u , u , j ) , f . sub ( p , c , u ) , f . squaredLength ( p ) < m * m ) { if ( l ) return ! 0 ; B = ! 0 ; var D = this . createContactEquation ( e , a , i , b ) ; f . copy ( D . normalA , p ) , f . normalize ( D . normalA , D . normalA ) , f . scale ( D . contactPointB , D . normalA , - m ) , h ( D . contactPointB , D . contactPointB , c ) , g ( D . contactPointB , D . contactPointB , a . position ) , g ( D . contactPointA , u , j ) , h ( D . contactPointA , D . contactPointA , j ) , g ( D . contactPointA , D . contactPointA , e . position ) , this . contactEquations . push ( D ) , this . enableFriction && this . frictionEquations . push ( this . createFrictionFromContact ( D ) ) } return B ? 1 : 0 } ; var nb = f . create ( ) , ob = f . create ( ) , pb = f . create ( ) , qb = new p ( [ f . create ( ) , f . create ( ) , f . create ( ) , f . create ( ) ] ) ; c . prototype [ q . RECTANGLE | q . HEIGHTFIELD ] = c . prototype [ q . CONVEX | q . HEIGHTFIELD ] = c . prototype . convexHeightfield = function ( a , b , c , d , e , g , h , i , j ) { var k = g . data , l = g . elementWidth , m = nb , n = ob , o = pb , p = qb , q = Math . floor ( ( a . aabb . lowerBound [ 0 ] - h [ 0 ] ) / l ) , r = Math . ceil ( ( a . aabb . upperBound [ 0 ] - h [ 0 ] ) / l ) ; 0 > q && ( q = 0 ) , r >= k . length && ( r = k . length - 1 ) ; for ( var s = k [ q ] , t = k [ r ] , u = q ; r > u ; u ++ ) k [ u ] < t && ( t = k [ u ] ) , k [ u ] > s && ( s = k [ u ] ) ; if ( a . aabb . lowerBound [ 1 ] > s ) return j ? ! 1 : 0 ; for ( var v = 0 , u = q ; r > u ; u ++ ) { f . set ( m , u * l , k [ u ] ) , f . set ( n , ( u + 1 ) * l , k [ u + 1 ] ) , f . add ( m , m , h ) , f . add ( n , n , h ) ; var w = 100 ; f . set ( o , . 5 * ( n [ 0 ] + m [ 0 ] ) , . 5 * ( n [ 1 ] + m [ 1 ] - w ) ) , f . sub ( p . vertices [ 0 ] , n , o ) , f . sub ( p . vertices [ 1 ] , m , o ) , f . copy ( p . vertices [ 2 ] , p . vertices [ 1 ] ) , f . copy ( p . vertices [ 3 ] , p . vertices [ 0 ] ) , p . vertices [ 2 ] [ 1 ] -= w , p . vertices [ 3 ] [ 1 ] -= w , v += this . convexConvex ( a , b , c , d , e , p , o , 0 , j ) } return v } } , { "../equations/ContactEquation" : 21 , "../equations/Equation" : 22 , "../equations/FrictionEquation" : 23 , "../math/vec2" : 30 , "../objects/Body" : 31 , "../shapes/Circle" : 35 , "../shapes/Convex" : 36 , "../shapes/Rectangle" : 41 , "../shapes/Shape" : 42 , "../utils/TupleDictionary" : 46 , "../utils/Utils" : 47 } ] , 13 : [ function ( a , b ) { function c ( ) { e . call ( this , e . SAP ) , this . axisList = [ ] , this . world = null , this . axisIndex = 0 ; var a = this . axisList ; this . _addBodyHandler = function ( b ) { a . push ( b . body ) } , this . _removeBodyHandler = function ( b ) { var c = a . indexOf ( b . body ) ; - 1 !== c && a . splice ( c , 1 ) } } var d = a ( "../utils/Utils" ) , e = a ( "../collision/Broadphase" ) ; b . exports = c , c . prototype = new e , c . prototype . setWorld = function ( a ) { this . axisList . length = 0 , d . appendArray ( this . axisList , a . bodies ) , a . off ( "addBody" , this . _addBodyHandler ) . off ( "removeBody" , this . _removeBodyHandler ) , a . on ( "addBody" , this . _addBodyHandler ) . on ( "removeBody" , this . _removeBodyHandler ) , this . world = a } , c . sortAxisList = function ( a , b ) { b = 0 | b ; for ( var c = 1 , d = a . length ; d > c ; c ++ ) { for ( var e = a [ c ] , f = c - 1 ; f >= 0 && ! ( a [ f ] . aabb . lowerBound [ b ] <= e . aabb . lowerBound [ b ] ) ; f -- ) a [ f + 1 ] = a [ f ] ; a [ f + 1 ] = e } return a } , c . prototype . getCollisionPairs = function ( ) { var a = this . axisList , b = this . result , d = this . axisIndex ; b . length = 0 ; for ( var f = a . length ; f -- ; ) { var g = a [ f ] ; g . aabbNeedsUpdate && g . updateAABB ( ) } c . sortAxisList ( a , d ) ; for ( var h = 0 , i = 0 | a . length ; h !== i ; h ++ ) for ( var j = a [ h ] , k = h + 1 ; i > k ; k ++ ) { var l = a [ k ] , m = l . aabb . lowerBound [ d ] <= j . aabb . upperBound [ d ] ; if ( ! m ) break ; e . canCollide ( j , l ) && this . boundingVolumeCheck ( j , l ) && b . push ( j , l ) } return b } } , { "../collision/Broadphase" : 9 , "../utils/Utils" : 47 } ] , 14 : [ function ( a , b ) { function c ( a , b , c , e ) { this . type = c , e = d . defaults ( e , { collideConnected : ! 0 ,
var z = d . crossLength ( w , s ) , A = d . crossLength ( x , s ) ; e . angularForce -= z , o . angularForce += A } } , { "../math/vec2" : 30 , "../utils/Utils" : 47 } ] , 33 : [ function ( a , b ) { b . exports = { AABB : a ( "./collision/AABB" ) , AngleLockEquation : a ( "./equations/AngleLockEquation" ) , Body : a ( "./objects/Body" ) , Broadphase : a ( "./collision/Broadphase" ) , Capsule : a ( "./shapes/Capsule" ) , Circle : a ( "./shapes/Circle" ) , Constraint : a ( "./constraints/Constraint" ) , ContactEquation : a ( "./equations/ContactEquation" ) , ContactMaterial : a ( "./material/ContactMaterial" ) , Convex : a ( "./shapes/Convex" ) , DistanceConstraint : a ( "./constraints/DistanceConstraint" ) , Equation : a ( "./equations/Equation" ) , EventEmitter : a ( "./events/EventEmitter" ) , FrictionEquation : a ( "./equations/FrictionEquation" ) , GearConstraint : a ( "./constraints/GearConstraint" ) , GridBroadphase : a ( "./collision/GridBroadphase" ) , GSSolver : a ( "./solver/GSSolver" ) , Heightfield : a ( "./shapes/Heightfield" ) , Line : a ( "./shapes/Line" ) , LockConstraint : a ( "./constraints/LockConstraint" ) , Material : a ( "./material/Material" ) , Narrowphase : a ( "./collision/Narrowphase" ) , NaiveBroadphase : a ( "./collision/NaiveBroadphase" ) , Particle : a ( "./shapes/Particle" ) , Plane : a ( "./shapes/Plane" ) , RevoluteConstraint : a ( "./constraints/RevoluteConstraint" ) , PrismaticConstraint : a ( "./constraints/PrismaticConstraint" ) , Rectangle : a ( "./shapes/Rectangle" ) , RotationalVelocityEquation : a ( "./equations/RotationalVelocityEquation" ) , SAPBroadphase : a ( "./collision/SAPBroadphase" ) , Shape : a ( "./shapes/Shape" ) , Solver : a ( "./solver/Solver" ) , Spring : a ( "./objects/Spring" ) , Utils : a ( "./utils/Utils" ) , World : a ( "./world/World" ) , vec2 : a ( "./math/vec2" ) , version : a ( "../package.json" ) . version } } , { "../package.json" : 7 , "./collision/AABB" : 8 , "./collision/Broadphase" : 9 , "./collision/GridBroadphase" : 10 , "./collision/NaiveBroadphase" : 11 , "./collision/Narrowphase" : 12 , "./collision/SAPBroadphase" : 13 , "./constraints/Constraint" : 14 , "./constraints/DistanceConstraint" : 15 , "./constraints/GearConstraint" : 16 , "./constraints/LockConstraint" : 17 , "./constraints/PrismaticConstraint" : 18 , "./constraints/RevoluteConstraint" : 19 , "./equations/AngleLockEquation" : 20 , "./equations/ContactEquation" : 21 , "./equations/Equation" : 22 , "./equations/FrictionEquation" : 23 , "./equations/RotationalVelocityEquation" : 25 , "./events/EventEmitter" : 26 , "./material/ContactMaterial" : 27 , "./material/Material" : 28 , "./math/vec2" : 30 , "./objects/Body" : 31 , "./objects/Spring" : 32 , "./shapes/Capsule" : 34 , "./shapes/Circle" : 35 , "./shapes/Convex" : 36 , "./shapes/Heightfield" : 37 , "./shapes/Line" : 38 , "./shapes/Particle" : 39 , "./shapes/Plane" : 40 , "./shapes/Rectangle" : 41 , "./shapes/Shape" : 42 , "./solver/GSSolver" : 43 , "./solver/Solver" : 44 , "./utils/Utils" : 47 , "./world/World" : 51 } ] , 34 : [ function ( a , b ) { function c ( a , b ) { this . length = a || 1 , this . radius = b || 1 , d . call ( this , d . CAPSULE ) } var d = a ( "./Shape" ) , e = a ( "../math/vec2" ) ; b . exports = c , c . prototype = new d , c . prototype . computeMomentOfInertia = function ( a ) { var b = this . radius , c = this . length + b , d = 2 * b ; return a * ( d * d + c * c ) / 12 } , c . prototype . updateBoundingRadius = function ( ) { this . boundingRadius = this . radius + this . length / 2 } , c . prototype . updateArea = function ( ) { this . area = Math . PI * this . radius * this . radius + 2 * this . radius * this . length } ; var f = e . create ( ) ; c . prototype . computeAABB = function ( a , b , c ) { var d = this . radius ; e . set ( f , this . length , 0 ) , e . rotate ( f , f , c ) , e . set ( a . upperBound , Math . max ( f [ 0 ] + d , - f [ 0 ] + d ) , Math . max ( f [ 1 ] + d , - f [ 1 ] + d ) ) , e . set ( a . lowerBound , Math . min ( f [ 0 ] - d , - f [ 0 ] - d ) , Math . min ( f [ 1 ] - d , - f [ 1 ] - d ) ) , e . add ( a . lowerBound , a . lowerBound , b ) , e . add ( a . upperBound , a . upperBound , b ) } } , { "../math/vec2" : 30 , "./Shape" : 42 } ] , 35 : [ function ( a , b ) { function c ( a ) { this . radius = a || 1 , d . call ( this , d . CIRCLE ) } var d = a ( "./Shape" ) , e = a ( "../math/vec2" ) ; b . exports = c , c . prototype = new d , c . prototype . computeMomentOfInertia = function ( a ) { var b = this . radius ; return a * b * b / 2 } , c . prototype . updateBoundingRadius = function ( ) { this . boundingRadius = this . radius } , c . prototype . updateArea = function ( ) { this . area = Math . PI * this . radius * this . radius } , c . prototype . computeAABB = function ( a , b ) { var c = this . radius ; e . set ( a . upperBound , c , c ) , e . set ( a . lowerBound , - c , - c ) , b && ( e . add ( a . lowerBound , a . lowerBound , b ) , e . add ( a . upperBound , a . upperBound , b ) ) } } , { "../math/vec2" : 30 , "./Shape" : 42 } ] , 36 : [ function ( a , b ) { function c ( a ) { this . vertices = [ ] ; for ( var b = 0 ; b < a . length ; b ++ ) { var c = e . create
2014-07-02 22:23:26 +00:00
switch ( l . type ) { case y . DISTANCE : e ( m , { distance : l . distance , maxForce : l . getMaxForce ( ) } ) , b . distanceConstraints . push ( m ) ; break ; case y . REVOLUTE : e ( m , { pivotA : d ( l . pivotA ) , pivotB : d ( l . pivotB ) , maxForce : l . maxForce , motorSpeed : l . getMotorSpeed ( ) || 0 , motorEnabled : ! ! l . getMotorSpeed ( ) , lowerLimit : l . lowerLimit , lowerLimitEnabled : l . lowerLimitEnabled , upperLimit : l . upperLimit , upperLimitEnabled : l . upperLimitEnabled } ) , b . revoluteConstraints . push ( m ) ; break ; case y . PRISMATIC : e ( m , { localAxisA : d ( l . localAxisA ) , localAnchorA : d ( l . localAnchorA ) , localAnchorB : d ( l . localAnchorB ) , maxForce : l . maxForce , upperLimitEnabled : l . upperLimitEnabled , lowerLimitEnabled : l . lowerLimitEnabled , upperLimit : l . upperLimit , lowerLimit : l . lowerLimit , motorEnabled : l . motorEnabled , motorSpeed : l . motorSpeed } ) , b . prismaticConstraints . push ( m ) ; break ; case y . LOCK : e ( m , { localOffsetB : d ( l . localOffsetB ) , localAngleB : l . localAngleB , maxForce : l . getMaxForce ( ) } ) , b . lockConstraints . push ( m ) ; break ; case y . GEAR : e ( m , { angle : l . angle , ratio : l . ratio , maxForce : l . maxForce || 1e6 } ) , b . gearConstraints . push ( m ) ; break ; default : console . error ( "Constraint not supported yet: " , l . type ) } } for ( var k = 0 ; k !== a . bodies . length ; k ++ ) { var n = a . bodies [ k ] , o = n . shapes , p = { id : n . id , mass : n . mass , angle : n . angle , position : d ( n . position ) , velocity : d ( n . velocity ) , angularVelocity : n . angularVelocity , force : d ( n . force ) , motionState : n . motionState , fixedRotation : n . fixedRotation , circleShapes : [ ] , planeShapes : [ ] , particleShapes : [ ] , lineShapes : [ ] , rectangleShapes : [ ] , convexShapes : [ ] , capsuleShapes : [ ] } ; n . concavePath && ( p . concavePath = n . concavePath ) ; for ( var q = 0 ; q < o . length ; q ++ ) { var g = o [ q ] , r = { } ; switch ( r . offset = d ( n . shapeOffsets [ q ] ) , r . angle = n . shapeAngles [ q ] , r . collisionGroup = g . collisionGroup , r . collisionMask = g . collisionMask , r . material = g . material ? g . material . id : null , g . type ) { case t . CIRCLE : e ( r , { radius : g . radius } ) , p . circleShapes . push ( r ) ; break ; case t . PLANE : p . planeShapes . push ( r ) ; break ; case t . PARTICLE : p . particleShapes . push ( r ) ; break ; case t . LINE : r . length = g . length , p . lineShapes . push ( r ) ; break ; case t . RECTANGLE : e ( r , { width : g . width , height : g . height } ) , p . rectangleShapes . push ( r ) ; break ; case t . CONVEX : for ( var s = [ ] , u = 0 ; u < g . vertices . length ; u ++ ) s . push ( d ( g . vertices [ u ] ) ) ; e ( r , { vertices : s } ) , p . convexShapes . push ( r ) ; break ; case t . CAPSULE : e ( r , { length : g . length , radius : g . radius } ) , p . capsuleShapes . push ( r ) ; break ; default : console . error ( "Shape type not supported yet!" ) } } b . bodies . push ( p ) } for ( var k = 0 ; k < a . contactMaterials . length ; k ++ ) { var v = a . contactMaterials [ k ] ; b . contactMaterials . push ( f ( v ) ) } for ( var w = { } , k = 0 ; k < a . contactMaterials . length ; k ++ ) { var v = a . contactMaterials [ k ] ; w [ v . materialA . id + "" ] = v . materialA , w [ v . materialB . id + "" ] = v . materialB } for ( var x in w ) { var z = w [ parseInt ( x ) ] ; b . materials . push ( { id : z . id } ) } return b } , c . prototype . fromJSON = function ( a ) { function b ( a , b , c ) { b . collisionMask = c . collisionMask , b . collisionGroup = c . collisionGroup , c . material && ( b . material = h [ c . material + "" ] ) , a . addShape ( b , c . offset , c . angle ) } if ( this . clear ( ) , ! a . p2 ) return ! 1 ; var c = this ; switch ( j . copy ( c . gravity , a . gravity ) , c . islandSplit = a . islandSplit , c . enableIslandSleeping = a . enableIslandSleeping , c . enableBodySleeping = a . enableBodySleeping , a . solver . type ) { case "GSSolver" : var d = a . solver , e = new g ; c . solver = e , e . iterations = d . iterations ; break ; default : throw new Error ( "Solver type not recognized: " + a . solver . type ) } switch ( a . broadphase . type ) { case "NaiveBroadphase" : c . broadphase = new i ; break ; case "SAPBroadphase" : c . broadphase = new F } c . broadphase . setWorld ( c ) ; for ( var f = c . bodies , h = { } , r = 0 ; r !== a . materials . length ; r ++ ) { var t = a . materials [ r ] , y = new v ; h [ t . id + "" ] = y , y . id = t . id } c . defaultMaterial . id = a . defaultContactMaterial . materialA ; for ( var r = 0 ; r !== a . bodies . length ; r ++ ) { var D = a . bodies [ r ] , E = new s ( { mass : D . mass , position : D . position , angle : D . angle , velocity : D . velocity , angularVelocity : D . angularVelocity , force : D . force , fixedRotation : D . fixedRotation } ) ; E . id = D . id , E . motionState = D . motionState ; for ( var G = 0 ; G < D . circleShapes . length ; G ++ ) { var e = D . circleShapes [ G ] ; b ( E , new k ( e . radius ) , e ) } for ( var G = 0 ; G < D . planeShapes . length ; G ++ ) { var e = D . planeShapes [ G ] ; b ( E , new o , e ) } for ( var G = 0 ; G < D . particleShapes . length ; G ++ ) { var e = D . particleShapes [ G ] ; b ( E , new q , e ) } for ( var G = 0 ; G < D . lineShapes . length ; G ++ ) { var e = D . lineShapes [ G ] ; b ( E , new n ( e . length ) , e ) } for ( var G = 0 ; G < D . rectangleShapes . length ; G ++ ) { var e = D . re
this . data . force [ 0 ] += b * Math . cos ( c ) , this . data . force [ 1 ] += b * Math . sin ( c ) } , reverse : function ( a ) { var b = this . world . pxmi ( - a ) , c = this . data . angle + Math . PI / 2 ; this . data . force [ 0 ] -= b * Math . cos ( c ) , this . data . force [ 1 ] -= b * Math . sin ( c ) } , moveLeft : function ( a ) { this . data . velocity [ 0 ] = this . world . pxmi ( - a ) } , moveRight : function ( a ) { this . data . velocity [ 0 ] = this . world . pxmi ( a ) } , moveUp : function ( a ) { this . data . velocity [ 1 ] = this . world . pxmi ( - a ) } , moveDown : function ( a ) { this . data . velocity [ 1 ] = this . world . pxmi ( a ) } , preUpdate : function ( ) { this . removeNextStep && ( this . removeFromWorld ( ) , this . removeNextStep = ! 1 ) } , postUpdate : function ( ) { this . sprite . x = this . world . mpxi ( this . data . position [ 0 ] ) , this . sprite . y = this . world . mpxi ( this . data . position [ 1 ] ) , this . fixedRotation || ( this . sprite . rotation = this . data . angle ) } , reset : function ( a , b , c , d ) { "undefined" == typeof c && ( c = ! 1 ) , "undefined" == typeof d && ( d = ! 1 ) , this . setZeroForce ( ) , this . setZeroVelocity ( ) , this . setZeroRotation ( ) , c && this . setZeroDamping ( ) , d && ( this . mass = 1 ) , this . x = a , this . y = b } , addToWorld : function ( ) { if ( this . game . physics . p2 . _toRemove ) for ( var a = 0 ; a < this . game . physics . p2 . _toRemove . length ; a ++ ) this . game . physics . p2 . _toRemove [ a ] === this && this . game . physics . p2 . _toRemove . splice ( a , 1 ) ; this . data . world !== this . game . physics . p2 . world && this . game . physics . p2 . addBody ( this ) } , removeFromWorld : function ( ) { this . data . world === this . game . physics . p2 . world && this . game . physics . p2 . removeBodyNextStep ( this ) } , destroy : function ( ) { this . removeFromWorld ( ) , this . clearShapes ( ) , this . _bodyCallbacks = { } , this . _bodyCallbackContext = { } , this . _groupCallbacks = { } , this . _groupCallbackContext = { } , this . debugBody && this . debugBody . destroy ( ) , this . debugBody = null , this . sprite = null } , clearShapes : function ( ) { for ( var a = this . data . shapes . length ; a -- ; ) this . data . removeShape ( this . data . shapes [ a ] ) ; this . shapeChanged ( ) } , addShape : function ( a , b , c , d ) { return "undefined" == typeof b && ( b = 0 ) , "undefined" == typeof c && ( c = 0 ) , "undefined" == typeof d && ( d = 0 ) , this . data . addShape ( a , [ this . world . pxmi ( b ) , this . world . pxmi ( c ) ] , d ) , this . shapeChanged ( ) , a } , addCircle : function ( a , b , c , d ) { var e = new p2 . Circle ( this . world . pxm ( a ) ) ; return this . addShape ( e , b , c , d ) } , addRectangle : function ( a , b , c , d , e ) { var f = new p2 . Rectangle ( this . world . pxm ( a ) , this . world . pxm ( b ) ) ; return this . addShape ( f , c , d , e ) } , addPlane : function ( a , b , c ) { var d = new p2 . Plane ; return this . addShape ( d , a , b , c ) } , addParticle : function ( a , b , c ) { var d = new p2 . Particle ; return this . addShape ( d , a , b , c ) } , addLine : function ( a , b , c , d ) { var e = new p2 . Line ( this . world . pxm ( a ) ) ; return this . addShape ( e , b , c , d ) } , addCapsule : function ( a , b , c , d , e ) { var f = new p2 . Capsule ( this . world . pxm ( a ) , b ) ; return this . addShape ( f , c , d , e ) } , addPolygon : function ( a , b ) { a = a || { } , b = Array . prototype . slice . call ( arguments , 1 ) ; var c = [ ] ; if ( 1 === b . length && Array . isArray ( b [ 0 ] ) ) c = b [ 0 ] . slice ( 0 ) ; else if ( Array . isArray ( b [ 0 ] ) ) c = b [ 0 ] . slice ( 0 ) ; else if ( "number" == typeof b [ 0 ] ) for ( var d = 0 , e = b . length ; e > d ; d += 2 ) c . push ( [ b [ d ] , b [ d + 1 ] ] ) ; var f = c . length - 1 ; c [ f ] [ 0 ] === c [ 0 ] [ 0 ] && c [ f ] [ 1 ] === c [ 0 ] [ 1 ] && c . pop ( ) ; for ( var g = 0 ; g < c . length ; g ++ ) c [ g ] [ 0 ] = this . world . pxmi ( c [ g ] [ 0 ] ) , c [ g ] [ 1 ] = this . world . pxmi ( c [ g ] [ 1 ] ) ; var h = this . data . fromPolygon ( c , a ) ; return this . shapeChanged ( ) , h } , removeShape : function ( a ) { var b = this . data . removeShape ( a ) ; return this . shapeChanged ( ) , b } , setCircle : function ( a , b , c , d ) { return this . clearShapes ( ) , this . addCircle ( a , b , c , d ) } , setRectangle : function ( a , b , c , d , e ) { return "undefined" == typeof a && ( a = 16 ) , "undefined" == typeof b && ( b = 16 ) , this . clearShapes ( ) , this . addRectangle ( a , b , c , d , e ) } , setRectangleFromSprite : function ( a ) { return "undefined" == typeof a && ( a = this . sprite ) , this . clearShapes ( ) , this . addRectangle ( a . width , a . height , 0 , 0 , a . rotation ) } , setMaterial : function ( a , b ) { if ( "undefined" == typeof b ) for ( var c = this . data . shapes . length - 1 ; c >= 0 ; c -- ) this . data . shapes [ c ] . material = a ; else b . material = a } , shapeChanged : function ( ) { this . debugBody && this . debugBody . draw ( ) } , addPhaserPolygon : function ( a , b ) { for ( var c = this . game . cache . getPhysicsData ( a , b ) , d = [ ] , e = 0 ; e < c . length ; e ++ ) { var f = c [ e ] , g = this . addFixture ( f ) ; d [ f . filter . group ] = d [ f . filter . group ] || [ ] , d [ f . filter . group ] = d [ f . filter . group ] . concat ( g ) , f . fixtureKey && ( d [ f . fixtureKey ] = g ) } return this . data . aabbNeedsUpdate = ! 0 , this . shapeChanged ( ) , d } , addFixture : function ( a ) { var b = [ ] ; if ( a . circle ) { var c = new p2 . Circle ( this . world . pxm ( a . circle . radius ) ) ; c . collisionGroup = a .