2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-11-16 02:06:07 +00:00
|
|
|
var GetTilesWithin = require('./GetTilesWithin');
|
2018-02-07 17:10:01 +00:00
|
|
|
var ShuffleArray = require('../../utils/array/Shuffle');
|
2017-11-16 02:06:07 +00:00
|
|
|
|
2017-11-27 13:33:30 +00:00
|
|
|
/**
|
|
|
|
* Shuffles the tiles in a rectangular region (specified in tile coordinates) within the given
|
|
|
|
* layer. It will only randomize the tiles in that area, so if they're all the same nothing will
|
|
|
|
* appear to have changed! This method only modifies tile indexes and does not change collision
|
|
|
|
* information.
|
|
|
|
*
|
2018-02-08 01:08:59 +00:00
|
|
|
* @function Phaser.Tilemaps.Components.Shuffle
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2017-11-29 21:07:56 +00:00
|
|
|
* @param {integer} [tileX=0] - [description]
|
|
|
|
* @param {integer} [tileY=0] - [description]
|
|
|
|
* @param {integer} [width=max width based on tileX] - [description]
|
|
|
|
* @param {integer} [height=max height based on tileY] - [description]
|
2018-02-08 02:02:37 +00:00
|
|
|
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
2017-11-27 13:33:30 +00:00
|
|
|
*/
|
2017-11-16 02:06:07 +00:00
|
|
|
var Shuffle = function (tileX, tileY, width, height, layer)
|
|
|
|
{
|
2017-11-26 00:03:21 +00:00
|
|
|
var tiles = GetTilesWithin(tileX, tileY, width, height, null, layer);
|
2017-11-16 02:06:07 +00:00
|
|
|
|
2017-11-29 19:22:30 +00:00
|
|
|
var indexes = tiles.map(function (tile) { return tile.index; });
|
|
|
|
ShuffleArray(indexes);
|
2017-11-16 02:06:07 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < tiles.length; i++)
|
|
|
|
{
|
2017-11-29 19:22:30 +00:00
|
|
|
tiles[i].index = indexes[i];
|
2017-11-16 02:06:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Shuffle;
|