2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2018-02-12 16:01:20 +00:00
|
|
|
* @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.SeperateY
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Physics.Impact.World} world - [description]
|
|
|
|
* @param {Phaser.Physics.Impact.Body} top - [description]
|
|
|
|
* @param {Phaser.Physics.Impact.Body} bottom - [description]
|
|
|
|
* @param {Phaser.Physics.Impact.Body} [weak] - [description]
|
|
|
|
*/
|
2017-06-21 23:47:35 +00:00
|
|
|
var SeperateY = function (world, top, bottom, weak)
|
|
|
|
{
|
|
|
|
var nudge = (top.pos.y + top.size.y - bottom.pos.y);
|
2017-06-22 15:22:21 +00:00
|
|
|
var nudgeX;
|
|
|
|
var resTop;
|
2017-06-21 23:47:35 +00:00
|
|
|
|
|
|
|
if (weak)
|
|
|
|
{
|
|
|
|
var strong = (top === weak) ? bottom : top;
|
|
|
|
|
|
|
|
weak.vel.y = -weak.vel.y * weak.bounciness + strong.vel.y;
|
|
|
|
|
|
|
|
// Riding on a platform?
|
2017-06-22 15:22:21 +00:00
|
|
|
nudgeX = 0;
|
2017-06-21 23:47:35 +00:00
|
|
|
|
|
|
|
if (weak === top && Math.abs(weak.vel.y - strong.vel.y) < weak.minBounceVelocity)
|
|
|
|
{
|
|
|
|
weak.standing = true;
|
|
|
|
nudgeX = strong.vel.x * world.delta;
|
|
|
|
}
|
|
|
|
|
2017-06-22 15:22:21 +00:00
|
|
|
var resWeak = world.collisionMap.trace(weak.pos.x, weak.pos.y, nudgeX, weak === top ? -nudge : nudge, weak.size.x, weak.size.y);
|
2017-06-21 23:47:35 +00:00
|
|
|
|
|
|
|
weak.pos.y = resWeak.pos.y;
|
|
|
|
weak.pos.x = resWeak.pos.x;
|
|
|
|
}
|
|
|
|
else if (world.gravity && (bottom.standing || top.vel.y > 0))
|
|
|
|
{
|
2017-06-22 15:22:21 +00:00
|
|
|
resTop = world.collisionMap.trace(top.pos.x, top.pos.y, 0, -(top.pos.y + top.size.y - bottom.pos.y), top.size.x, top.size.y);
|
2017-06-21 23:47:35 +00:00
|
|
|
|
|
|
|
top.pos.y = resTop.pos.y;
|
|
|
|
|
|
|
|
if (top.bounciness > 0 && top.vel.y > top.minBounceVelocity)
|
|
|
|
{
|
2017-06-22 15:22:21 +00:00
|
|
|
top.vel.y *= -top.bounciness;
|
2017-06-21 23:47:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
top.standing = true;
|
|
|
|
top.vel.y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var v2 = (top.vel.y - bottom.vel.y) / 2;
|
|
|
|
|
|
|
|
top.vel.y = -v2;
|
|
|
|
bottom.vel.y = v2;
|
|
|
|
|
2017-06-22 15:22:21 +00:00
|
|
|
nudgeX = bottom.vel.x * world.delta;
|
2017-06-21 23:47:35 +00:00
|
|
|
|
2017-06-22 15:22:21 +00:00
|
|
|
resTop = world.collisionMap.trace(top.pos.x, top.pos.y, nudgeX, -nudge / 2, top.size.x, top.size.y);
|
2017-06-21 23:47:35 +00:00
|
|
|
|
|
|
|
top.pos.y = resTop.pos.y;
|
|
|
|
|
2017-06-22 15:22:21 +00:00
|
|
|
var resBottom = world.collisionMap.trace(bottom.pos.x, bottom.pos.y, 0, nudge / 2, bottom.size.x, bottom.size.y);
|
2017-06-21 23:47:35 +00:00
|
|
|
|
|
|
|
bottom.pos.y = resBottom.pos.y;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SeperateY;
|