2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2018-02-09 15:23:33 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @function Phaser.Physics.Impact.SeperateX
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Physics.Impact.World} world - [description]
|
|
|
|
* @param {Phaser.Physics.Impact.Body} left - [description]
|
|
|
|
* @param {Phaser.Physics.Impact.Body} right - [description]
|
|
|
|
* @param {Phaser.Physics.Impact.Body} [weak] - [description]
|
|
|
|
*/
|
2017-06-21 23:47:35 +00:00
|
|
|
var SeperateX = function (world, left, right, weak)
|
|
|
|
{
|
|
|
|
var nudge = left.pos.x + left.size.x - right.pos.x;
|
|
|
|
|
|
|
|
// We have a weak entity, so just move this one
|
|
|
|
if (weak)
|
|
|
|
{
|
|
|
|
var strong = (left === weak) ? right : left;
|
|
|
|
|
|
|
|
weak.vel.x = -weak.vel.x * weak.bounciness + strong.vel.x;
|
|
|
|
|
2017-06-22 01:40:10 +00:00
|
|
|
var resWeak = world.collisionMap.trace(weak.pos.x, weak.pos.y, weak === left ? -nudge : nudge, 0, weak.size.x, weak.size.y);
|
2017-06-21 23:47:35 +00:00
|
|
|
|
|
|
|
weak.pos.x = resWeak.pos.x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var v2 = (left.vel.x - right.vel.x) / 2;
|
|
|
|
|
|
|
|
left.vel.x = -v2;
|
|
|
|
right.vel.x = v2;
|
|
|
|
|
2017-06-22 01:40:10 +00:00
|
|
|
var resLeft = world.collisionMap.trace(left.pos.x, left.pos.y, -nudge / 2, 0, left.size.x, left.size.y);
|
2017-06-21 23:47:35 +00:00
|
|
|
|
|
|
|
left.pos.x = Math.floor(resLeft.pos.x);
|
|
|
|
|
2017-06-22 01:40:10 +00:00
|
|
|
var resRight = world.collisionMap.trace(right.pos.x, right.pos.y, nudge / 2, 0, right.size.x, right.size.y);
|
2017-06-21 23:47:35 +00:00
|
|
|
|
|
|
|
right.pos.x = Math.ceil(resRight.pos.x);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SeperateX;
|