2017-11-22 01:16:46 +00:00
|
|
|
var GetTileAt = require('./GetTileAt');
|
|
|
|
|
2017-11-27 13:33:30 +00:00
|
|
|
/**
|
|
|
|
* Calculates interesting faces at the given tile coordinates of the specified layer. Interesting
|
|
|
|
* faces are used internally for optimizing collisions against tiles. This method is mostly used
|
|
|
|
* internally to optimize recalculating faces when only one tile has been changed.
|
|
|
|
*
|
2017-11-29 21:07:56 +00:00
|
|
|
* @param {integer} tileX - [description]
|
|
|
|
* @param {integer} tileY - [description]
|
2017-11-27 13:33:30 +00:00
|
|
|
* @param {LayerData} layer - [description]
|
|
|
|
*/
|
2017-11-22 01:16:46 +00:00
|
|
|
var RecalculateFacesAt = function (tileX, tileY, layer)
|
|
|
|
{
|
|
|
|
var tile = GetTileAt(tileX, tileY, true, layer);
|
|
|
|
var above = GetTileAt(tileX, tileY - 1, true, layer);
|
|
|
|
var below = GetTileAt(tileX, tileY + 1, true, layer);
|
|
|
|
var left = GetTileAt(tileX - 1, tileY, true, layer);
|
|
|
|
var right = GetTileAt(tileX + 1, tileY, true, layer);
|
|
|
|
var tileCollides = tile && tile.collides;
|
|
|
|
|
|
|
|
// Assume the changed tile has all interesting edges
|
|
|
|
if (tileCollides)
|
|
|
|
{
|
|
|
|
tile.faceBottom = true;
|
|
|
|
tile.faceBottom = true;
|
|
|
|
tile.faceLeft = true;
|
|
|
|
tile.faceRight = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset edges that are shared between tile and its neighbors
|
|
|
|
if (above && above.collides)
|
|
|
|
{
|
|
|
|
if (tileCollides) { tile.faceTop = false; }
|
|
|
|
above.faceBottom = !tileCollides;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (below && below.collides)
|
|
|
|
{
|
|
|
|
if (tileCollides) { tile.faceBottom = false; }
|
|
|
|
below.faceTop = !tileCollides;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left && left.collides)
|
|
|
|
{
|
|
|
|
if (tileCollides) { tile.faceLeft = false; }
|
|
|
|
left.faceRight = !tileCollides;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (right && right.collides)
|
|
|
|
{
|
|
|
|
if (tileCollides) { tile.faceRight = false; }
|
|
|
|
right.faceLeft = !tileCollides;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tile;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = RecalculateFacesAt;
|