phaser/src/physics/arcade/tilemap/TileCheckY.js

85 lines
2.2 KiB
JavaScript
Raw Normal View History

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}
*/
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)
{
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)
{
// Body is moving UP
2019-03-05 14:43:20 +00:00
if (faceBottom && body.y < tileBottom)
{
oy = body.y - tileBottom;
if (oy < -tileBias)
{
oy = 0;
}
}
}
2019-03-05 14:43:20 +00:00
else if (body.deltaY() > 0 && !body.blocked.down && collideUp && body.checkCollision.down)
{
// Body is moving DOWN
2019-03-05 14:43:20 +00:00
if (faceTop && body.bottom > tileTop)
{
oy = body.bottom - tileTop;
if (oy > tileBias)
{
oy = 0;
}
}
}
if (oy !== 0)
{
if (body.customSeparateY)
{
body.overlapY = oy;
}
else
{
ProcessTileSeparationY(body, oy);
}
}
return oy;
};
module.exports = TileCheckY;