2018-02-09 16:04:43 +00:00
|
|
|
var COLLIDES = require('./COLLIDES');
|
2017-06-21 23:47:35 +00:00
|
|
|
var SeperateX = require('./SeperateX');
|
|
|
|
var SeperateY = require('./SeperateY');
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* Impact Physics Solver
|
|
|
|
*
|
|
|
|
* @function Phaser.Physics.Impact.Solver
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Physics.Impact.World} world - [description]
|
|
|
|
* @param {Phaser.Physics.Impact.Body} bodyA - [description]
|
|
|
|
* @param {Phaser.Physics.Impact.Body} bodyB - [description]
|
|
|
|
*/
|
2017-06-21 23:47:35 +00:00
|
|
|
var Solver = function (world, bodyA, bodyB)
|
|
|
|
{
|
|
|
|
var weak = null;
|
|
|
|
|
|
|
|
if (bodyA.collides === COLLIDES.LITE || bodyB.collides === COLLIDES.FIXED)
|
|
|
|
{
|
|
|
|
weak = bodyA;
|
|
|
|
}
|
|
|
|
else if (bodyB.collides === COLLIDES.LITE || bodyA.collides === COLLIDES.FIXED)
|
|
|
|
{
|
|
|
|
weak = bodyB;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bodyA.last.x + bodyA.size.x > bodyB.last.x && bodyA.last.x < bodyB.last.x + bodyB.size.x)
|
|
|
|
{
|
|
|
|
if (bodyA.last.y < bodyB.last.y)
|
|
|
|
{
|
|
|
|
SeperateY(world, bodyA, bodyB, weak);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SeperateY(world, bodyB, bodyA, weak);
|
|
|
|
}
|
|
|
|
|
|
|
|
bodyA.collideWith(bodyB, 'y');
|
|
|
|
bodyB.collideWith(bodyA, 'y');
|
2017-08-16 15:30:28 +00:00
|
|
|
|
2018-01-12 17:09:09 +00:00
|
|
|
world.emit('collide', bodyA, bodyB, 'y');
|
2017-06-21 23:47:35 +00:00
|
|
|
}
|
|
|
|
else if (bodyA.last.y + bodyA.size.y > bodyB.last.y && bodyA.last.y < bodyB.last.y + bodyB.size.y)
|
|
|
|
{
|
|
|
|
if (bodyA.last.x < bodyB.last.x)
|
|
|
|
{
|
|
|
|
SeperateX(world, bodyA, bodyB, weak);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SeperateX(world, bodyB, bodyA, weak);
|
|
|
|
}
|
|
|
|
|
|
|
|
bodyA.collideWith(bodyB, 'x');
|
|
|
|
bodyB.collideWith(bodyA, 'x');
|
2017-08-16 15:30:28 +00:00
|
|
|
|
2018-01-12 17:09:09 +00:00
|
|
|
world.emit('collide', bodyA, bodyB, 'x');
|
2017-06-21 23:47:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Solver;
|