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-06-03 20:17:33 +00:00
|
|
|
var CONST = require('./const');
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @function Phaser.Physics.Arcade.GetOverlapY
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Physics.Arcade.Body} body1 - [description]
|
|
|
|
* @param {Phaser.Physics.Arcade.Body} body2 - [description]
|
|
|
|
* @param {boolean} overlapOnly - [description]
|
|
|
|
* @param {number} bias - [description]
|
|
|
|
*
|
|
|
|
* @return {number} [description]
|
|
|
|
*/
|
2017-11-09 15:30:44 +00:00
|
|
|
var GetOverlapY = function (body1, body2, overlapOnly, bias)
|
2017-11-09 13:02:55 +00:00
|
|
|
{
|
|
|
|
var overlap = 0;
|
2017-11-09 15:30:44 +00:00
|
|
|
var maxOverlap = body1.deltaAbsY() + body2.deltaAbsY() + bias;
|
2017-11-09 13:02:55 +00:00
|
|
|
|
2018-06-01 14:41:40 +00:00
|
|
|
if (body1._dy === 0 && body2._dy === 0)
|
2017-11-09 13:02:55 +00:00
|
|
|
{
|
|
|
|
// They overlap but neither of them are moving
|
|
|
|
body1.embedded = true;
|
|
|
|
body2.embedded = true;
|
|
|
|
}
|
2018-06-01 14:41:40 +00:00
|
|
|
else if (body1._dy > body2._dy)
|
2017-11-09 13:02:55 +00:00
|
|
|
{
|
|
|
|
// Body1 is moving down and/or Body2 is moving up
|
|
|
|
overlap = body1.bottom - body2.y;
|
|
|
|
|
|
|
|
if ((overlap > maxOverlap && !overlapOnly) || body1.checkCollision.down === false || body2.checkCollision.up === false)
|
|
|
|
{
|
|
|
|
overlap = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
body1.touching.none = false;
|
|
|
|
body1.touching.down = true;
|
2018-06-03 20:17:33 +00:00
|
|
|
|
2017-11-09 13:02:55 +00:00
|
|
|
body2.touching.none = false;
|
|
|
|
body2.touching.up = true;
|
2018-06-03 20:17:33 +00:00
|
|
|
|
|
|
|
if (body2.physicsType === CONST.STATIC_BODY)
|
|
|
|
{
|
2018-06-19 21:48:07 +00:00
|
|
|
body1.blocked.none = false;
|
2018-06-03 20:17:33 +00:00
|
|
|
body1.blocked.down = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (body1.physicsType === CONST.STATIC_BODY)
|
|
|
|
{
|
2018-06-19 21:48:07 +00:00
|
|
|
body2.blocked.none = false;
|
2018-06-03 20:17:33 +00:00
|
|
|
body2.blocked.up = true;
|
|
|
|
}
|
2017-11-09 13:02:55 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-01 14:41:40 +00:00
|
|
|
else if (body1._dy < body2._dy)
|
2017-11-09 13:02:55 +00:00
|
|
|
{
|
|
|
|
// Body1 is moving up and/or Body2 is moving down
|
|
|
|
overlap = body1.y - body2.bottom;
|
|
|
|
|
|
|
|
if ((-overlap > maxOverlap && !overlapOnly) || body1.checkCollision.up === false || body2.checkCollision.down === false)
|
|
|
|
{
|
|
|
|
overlap = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
body1.touching.none = false;
|
|
|
|
body1.touching.up = true;
|
2018-06-03 20:17:33 +00:00
|
|
|
|
2017-11-09 13:02:55 +00:00
|
|
|
body2.touching.none = false;
|
|
|
|
body2.touching.down = true;
|
2018-06-03 20:17:33 +00:00
|
|
|
|
|
|
|
if (body2.physicsType === CONST.STATIC_BODY)
|
|
|
|
{
|
2018-06-19 21:48:07 +00:00
|
|
|
body1.blocked.none = false;
|
2018-06-03 20:17:33 +00:00
|
|
|
body1.blocked.up = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (body1.physicsType === CONST.STATIC_BODY)
|
|
|
|
{
|
2018-06-19 21:48:07 +00:00
|
|
|
body2.blocked.none = false;
|
2018-06-03 20:17:33 +00:00
|
|
|
body2.blocked.down = true;
|
|
|
|
}
|
2017-11-09 13:02:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resets the overlapY to zero if there is no overlap, or to the actual pixel value if there is
|
|
|
|
body1.overlapY = overlap;
|
|
|
|
body2.overlapY = overlap;
|
|
|
|
|
|
|
|
return overlap;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = GetOverlapY;
|