wobblyhead hg > minor_monsters
diff game/js/map.js @ 6:910b26feca76
full game flow
| author | ark |
|---|---|
| date | 2026-10-19 01:05 +0200 |
| parents | 5492efd60e2c |
| children | 22b604680c5a |
line wrap: on
line diff
--- a/game/js/map.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/js/map.js Mon Oct 19 01:05:29 2026 +0200 @@ -48,6 +48,10 @@ "use strict"; var cfg = MM.config; + // spike sides: distance between route samples, and the share of the + // samples in reach a side needs to count as facing the path + var SIDE_STEP = 4; + var SIDE_SHARE = 0.2; function GameMap(index) { var d = MM.maps[index]; @@ -94,6 +98,35 @@ return best; }; + // which sides of a tower at x, y face the path, as four booleans: up, + // right, down, left. each side covers a quarter of the directions. a side + // faces the path when it holds at least SIDE_SHARE of the route points + // within reach. with no route point in reach, only the side towards the + // nearest one does. + GameMap.prototype.facingSides = function (x, y, reach) { + var count = [0, 0, 0, 0], total = 0, nearest = Infinity, nearSide = 0; + var pt = {}; + this.routes.forEach(function (r) { + pt.seg = 1; + for (var s = 0; s <= r.length; s += SIDE_STEP) { + r.point(s, pt); + var dx = pt.x - x, dy = pt.y - y, d = Math.hypot(dx, dy); + var side = Math.abs(dx) > Math.abs(dy) ? (dx > 0 ? 1 : 3) : (dy > 0 ? 2 : 0); + if (d < nearest) { + nearest = d; + nearSide = side; + } + if (d <= reach) { + count[side]++; + total++; + } + } + }); + return count.map(function (c, i) { + return total ? c >= SIDE_SHARE * total : i === nearSide; + }); + }; + // route weights for a monster of the given speed (balance.md, route // preference). fixed weights from routes.toml take precedence. GameMap.prototype.routeWeights = function (speed) {
