-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiles.js
More file actions
34 lines (29 loc) · 962 Bytes
/
tiles.js
File metadata and controls
34 lines (29 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var availableTiles = exports.availableTiles = function(map, x, y, maxDistance, minDistance) {
if (maxDistance === 0) {
return;
}
var negate = [ ];
if (!minDistance) {
var minDistance = 0;
} else if (minDistance > 0){
negate = availableTiles(map, x, y, minDistance);
}
var tiles = [];
var homeTile = map.getTile(x, y);
var neighbours = map.getNeighbours(x, y);
neighbours.forEach(function(tile) {
if (tile.properties.solid === true) {
tile.notAvailable();
}
if (tile.isAvailable()) {
tiles.push(tile);
var availableNeighbours = availableTiles(map, tile.coords[0], tile.coords[1], maxDistance - 1, minDistance - 1);
if (availableNeighbours){
availableNeighbours.forEach(function(neighbour){
tiles.push(neighbour);
});
}
}
});
return tiles;
};