index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <webdevcat@proton.me> | 2024-06-18 20:24:54 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-06-18 20:24:54 -0700 |
commit | 12890ea00934c6a2df63fe777799332818e4e5ce (patch) | |
tree | 1d903fe87ee0a7187460eb49189d5f9df3f4c417 | |
parent | 157463183403f472f55e0b27273a60c33641e9f2 (diff) |
Clean up a bit
-rw-r--r-- | public/radial.html | 2 | ||||
-rw-r--r-- | src/radial.js | 38 |
2 files changed, 23 insertions, 17 deletions
diff --git a/public/radial.html b/public/radial.html index 21ccc36..9cebada 100644 --- a/public/radial.html +++ b/public/radial.html @@ -134,7 +134,7 @@ </head> <body> - <svg viewBox="-200 -150 400 300" xmlns="http://www.w3.org/2000/svg"> + <svg viewBox="-300 -400 600 800" xmlns="http://www.w3.org/2000/svg"> <!-- <svg viewBox="-30 -20 60 40" xmlns="http://www.w3.org/2000/svg"> --> <defs> <polygon id="hex" points="0,10 8.66,5 8.66,-5 0,-10 -8.66,-5 -8.66,5" /> diff --git a/src/radial.js b/src/radial.js index 0a71f03..22c8904 100644 --- a/src/radial.js +++ b/src/radial.js @@ -62,7 +62,7 @@ function generateRadialCoords(l, { q, r, s }, radius) { } function generateRadialCoordsRect({ rows, columns, odd = false, equal = true } = {}, { q = 0, r = 0, s = 0 } = {}) { - const list = new Set(); + const list = new Map(); for (let row = 0; row < rows; row++) { const alternating = row % 2; @@ -77,7 +77,7 @@ function generateRadialCoordsRect({ rows, columns, odd = false, equal = true } = ds = ds + alternating; } - list.add(toKey(q + dq, r + dr, s + ds)); + list.set(toKey(q + dq, r + dr, s + ds), null); } if (!equal) { @@ -90,7 +90,7 @@ function generateRadialCoordsRect({ rows, columns, odd = false, equal = true } = ds = ds + alternating; } - list.add(toKey(q + dq, r + dr, s + ds)); + list.set(toKey(q + dq, r + dr, s + ds), null); } } } @@ -275,35 +275,40 @@ bld1.appendChild(bld1elv1); bld1hexes.forEach(coords => grid.delete(coords)) bld2hexes.forEach(list => list.forEach(coords => grid.delete(coords))); -// drawHexes(elevation1, grid); - function generateRadialCoords2(l, { q, r, s }) { const origin = toKey(q, r, s); const list = new Map(l); - let level = 0; - list.set(origin, level); + list.set(origin, 0); let queue = [origin]; - const top = 5; - const bottom = 5; - - const left = 1; - const right = 1; + const top = 26; + const bottom = 27; + const left = 17; + const right = 17; + const offset = 'right'; while (queue.length > 0) { - level++; const v = queue.shift(); + getNeighbors(v).forEach(w => { const [wq, wr, ws] = w.split(',').map(n => +n); const rDist = Math.abs(wr - r); const dr = (rDist + rDist % 2) / 2; + let dLeft = left; + let dRight = right; + + if (offset === 'left') + dRight -= rDist % 2; + else if (offset === 'right') + dLeft -= rDist % 2; + if ([ !list.has(w), wr < bottom + r && wr > -top + r, - wq > -right + q - dr && wq < left + q + dr, - ws > -left + s - dr && ws < right + s + dr, + wq > -dRight + q - dr && wq < dLeft + q + dr, + ws > -dLeft + s - dr && ws < dRight + s + dr, ].every(v => v)) { list.set(w, dr); queue.push(w); @@ -335,7 +340,8 @@ const list = generateRadialCoords2(new Map(), { q: 0, r: 0, s: 0 }); // q [-2, -8] // s [-2, 4] -drawHexes(elevation2, generateRadialCoords(new Map(), { q: 0, r: 0, s: 0 }, 10)); +// drawHexes(elevation2, generateRadialCoords(new Map(), { q: 0, r: 0, s: 0 }, 10)); +drawHexes(elevation2, grid); drawHexes(elevation1, list); const defs = svg.querySelector('defs'); |