/
TileCheckY.js
84 lines (74 loc) · 2.17 KB
/
TileCheckY.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013-2023 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var ProcessTileSeparationY = require('./ProcessTileSeparationY');
/**
* Check the body against the given tile on the Y axis.
* Used internally by the SeparateTile function.
*
* @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.
* @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.
* @param {boolean} isLayer - Is this check coming from a TilemapLayer or an array of tiles?
*
* @return {number} The amount of separation that occurred.
*/
var TileCheckY = function (body, tile, tileTop, tileBottom, tileBias, isLayer)
{
var oy = 0;
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 && collideDown && body.checkCollision.up)
{
// Body is moving UP
if (faceBottom && body.y < tileBottom)
{
oy = body.y - tileBottom;
if (oy < -tileBias)
{
oy = 0;
}
}
}
else if (body.deltaY() > 0 && collideUp && body.checkCollision.down)
{
// Body is moving DOWN
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;