2017-11-21 02:06:49 +00:00
|
|
|
var SetTileCollision = require('./SetTileCollision');
|
|
|
|
var RecalculateFaces = require('./RecalculateFaces');
|
2017-11-22 01:13:43 +00:00
|
|
|
var SetLayerCollisionIndex = require('./SetLayerCollisionIndex');
|
2017-11-21 02:06:49 +00:00
|
|
|
|
|
|
|
var SetCollisionBetween = function (start, stop, collides, recalculateFaces, layer)
|
|
|
|
{
|
|
|
|
if (collides === undefined) { collides = true; }
|
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
|
|
|
if (start > stop) { return; }
|
|
|
|
|
2017-11-22 01:13:43 +00:00
|
|
|
// Update the array of colliding indexes
|
|
|
|
for (var index = start; index <= stop; index++)
|
|
|
|
{
|
|
|
|
SetLayerCollisionIndex(index, collides, layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the tiles
|
2017-11-21 02:06:49 +00:00
|
|
|
for (var ty = 0; ty < layer.height; ty++)
|
|
|
|
{
|
|
|
|
for (var tx = 0; tx < layer.width; tx++)
|
|
|
|
{
|
|
|
|
var tile = layer.data[ty][tx];
|
|
|
|
if (tile)
|
|
|
|
{
|
|
|
|
if (tile.index >= start && tile.index <= stop)
|
|
|
|
{
|
|
|
|
SetTileCollision(tile, collides);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recalculateFaces) { RecalculateFaces(layer); }
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SetCollisionBetween;
|