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-01-11 02:47:25 +00:00
|
|
|
var ProcessTileSeparationY = require('./ProcessTileSeparationY');
|
|
|
|
|
|
|
|
/**
|
2018-02-09 03:44:23 +00:00
|
|
|
* Check the body against the given tile on the Y axis.
|
2018-10-19 16:45:05 +00:00
|
|
|
* Used internally by the SeparateTile function.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @function Phaser.Physics.Arcade.Tilemap.TileCheckY
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Physics.Arcade.Body} body - The Body object to separate.
|
|
|
|
* @param {Phaser.Tilemaps.Tile} tile - The tile to check.
|
2018-10-19 16:45:05 +00:00
|
|
|
* @param {number} tileTop - The top position of the tile within the tile world.
|
|
|
|
* @param {number} tileBottom - The bottom position of the tile within the tile world.
|
|
|
|
* @param {number} tileBias - The tile bias value. Populated by the `World.TILE_BIAS` constant.
|
2019-03-05 14:43:20 +00:00
|
|
|
* @param {boolean} isLayer - Is this check coming from a TilemapLayer or an array of tiles?
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @return {number} The amount of separation that occurred.
|
|
|
|
*/
|
2019-03-05 14:43:20 +00:00
|
|
|
var TileCheckY = function (body, tile, tileTop, tileBottom, tileBias, isLayer)
|
2018-01-11 02:47:25 +00:00
|
|
|
{
|
|
|
|
var oy = 0;
|
|
|
|
|
2019-03-05 14:43:20 +00:00
|
|
|
var faceTop = tile.faceTop;
|
|
|
|
var faceBottom = tile.faceBottom;
|
|
|
|
var collideUp = tile.collideUp;
|
|
|
|
var collideDown = tile.collideDown;
|
|
|
|
|
|
|
|
if (!isLayer)
|
|
|
|
{
|
|
|
|
faceTop = true;
|
|
|
|
faceBottom = true;
|
|
|
|
collideUp = true;
|
|
|
|
collideDown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (body.deltaY() < 0 && !body.blocked.up && collideDown && body.checkCollision.up)
|
2018-01-11 02:47:25 +00:00
|
|
|
{
|
|
|
|
// Body is moving UP
|
2019-03-05 14:43:20 +00:00
|
|
|
if (faceBottom && body.y < tileBottom)
|
2018-01-11 02:47:25 +00:00
|
|
|
{
|
|
|
|
oy = body.y - tileBottom;
|
|
|
|
|
2018-01-11 14:32:07 +00:00
|
|
|
if (oy < -tileBias)
|
2018-01-11 02:47:25 +00:00
|
|
|
{
|
|
|
|
oy = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-05 14:43:20 +00:00
|
|
|
else if (body.deltaY() > 0 && !body.blocked.down && collideUp && body.checkCollision.down)
|
2018-01-11 02:47:25 +00:00
|
|
|
{
|
|
|
|
// Body is moving DOWN
|
2019-03-05 14:43:20 +00:00
|
|
|
if (faceTop && body.bottom > tileTop)
|
2018-01-11 02:47:25 +00:00
|
|
|
{
|
|
|
|
oy = body.bottom - tileTop;
|
|
|
|
|
2018-01-11 14:32:07 +00:00
|
|
|
if (oy > tileBias)
|
2018-01-11 02:47:25 +00:00
|
|
|
{
|
|
|
|
oy = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oy !== 0)
|
|
|
|
{
|
|
|
|
if (body.customSeparateY)
|
|
|
|
{
|
|
|
|
body.overlapY = oy;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ProcessTileSeparationY(body, oy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return oy;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = TileCheckY;
|