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-10-26 15:38:22 +00:00
|
|
|
// var GetPointsOnLine = require('../geom/line/GetPointsOnLine');
|
|
|
|
var BresenhamPoints = require('../geom/line/BresenhamPoints');
|
2017-03-30 23:46:19 +00:00
|
|
|
|
2017-10-04 16:05:26 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @function Phaser.Actions.PlaceOnTriangle
|
|
|
|
* @since 3.0.0
|
2018-01-25 06:55:04 +00:00
|
|
|
*
|
2018-03-20 14:57:12 +00:00
|
|
|
* @param {(array|Phaser.GameObjects.GameObject[])} items - An array of Game Objects. The contents of this array are updated by this Action.
|
2017-10-04 16:05:26 +00:00
|
|
|
* @param {Phaser.Geom.Triangle} triangle - [description]
|
|
|
|
* @param {number} [stepRate=1] - [description]
|
2017-10-06 02:05:01 +00:00
|
|
|
*
|
2017-10-04 16:05:26 +00:00
|
|
|
* @return {array} The array of Game Objects that was passed to this Action.
|
|
|
|
*/
|
2017-03-30 23:46:19 +00:00
|
|
|
var PlaceOnTriangle = function (items, triangle, stepRate)
|
|
|
|
{
|
2017-10-26 15:38:22 +00:00
|
|
|
var p1 = BresenhamPoints({ x1: triangle.x1, y1: triangle.y1, x2: triangle.x2, y2: triangle.y2 }, stepRate);
|
|
|
|
var p2 = BresenhamPoints({ x1: triangle.x2, y1: triangle.y2, x2: triangle.x3, y2: triangle.y3 }, stepRate);
|
|
|
|
var p3 = BresenhamPoints({ x1: triangle.x3, y1: triangle.y3, x2: triangle.x1, y2: triangle.y1 }, stepRate);
|
2017-03-30 23:46:19 +00:00
|
|
|
|
|
|
|
// Remove overlaps
|
|
|
|
p1.pop();
|
|
|
|
p2.pop();
|
|
|
|
p3.pop();
|
|
|
|
|
|
|
|
p1 = p1.concat(p2, p3);
|
|
|
|
|
|
|
|
var step = p1.length / items.length;
|
|
|
|
var p = 0;
|
|
|
|
|
|
|
|
for (var i = 0; i < items.length; i++)
|
|
|
|
{
|
|
|
|
var item = items[i];
|
|
|
|
var point = p1[Math.floor(p)];
|
|
|
|
|
2018-01-25 06:55:04 +00:00
|
|
|
item.x = point.x;
|
|
|
|
item.y = point.y;
|
2017-03-30 23:46:19 +00:00
|
|
|
|
|
|
|
p += step;
|
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = PlaceOnTriangle;
|