lychees's picture
Upload 569 files
87b3b3a
/**
* @class Abstract FOV algorithm
* @param {function} lightPassesCallback Does the light pass through x,y?
* @param {object} [options]
* @param {int} [options.topology=8] 4/6/8
*/
ROT.FOV = function(lightPassesCallback, options) {
this._lightPasses = lightPassesCallback;
this._options = {
topology: 8
}
for (var p in options) { this._options[p] = options[p]; }
};
/**
* Compute visibility
* @param {int} x
* @param {int} y
* @param {int} R Maximum visibility radius
* @param {function} callback
*/
ROT.FOV.prototype.compute = function(x, y, R, callback) {}
/**
* Return all neighbors in a concentric ring
* @param {int} cx center-x
* @param {int} cy center-y
* @param {int} r range
*/
ROT.FOV.prototype._getCircle = function(cx, cy, r) {
var result = [];
var dirs, countFactor, startOffset;
switch (this._options.topology) {
case 4:
countFactor = 1;
startOffset = [0, 1];
dirs = [
ROT.DIRS[8][7],
ROT.DIRS[8][1],
ROT.DIRS[8][3],
ROT.DIRS[8][5]
]
break;
case 6:
dirs = ROT.DIRS[6];
countFactor = 1;
startOffset = [-1, 1];
break;
case 8:
dirs = ROT.DIRS[4];
countFactor = 2;
startOffset = [-1, 1];
break;
}
/* starting neighbor */
var x = cx + startOffset[0]*r;
var y = cy + startOffset[1]*r;
/* circle */
for (var i=0;i<dirs.length;i++) {
for (var j=0;j<r*countFactor;j++) {
result.push([x, y]);
x += dirs[i][0];
y += dirs[i][1];
}
}
return result;
}