diff options
author | elioat <elioat@tilde.institute> | 2024-12-28 10:02:25 -0500 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2024-12-28 10:02:25 -0500 |
commit | b1e55b1d524fba2e13e5b0f2c349546b43fe8341 (patch) | |
tree | 0fc25e1f60041ec41b7b31d0b07c0c8c63bf5599 /html/rogue/js/fow.js | |
parent | 8a36e1c0f435ce0f78a92a10a4c4b9d77f4c38d2 (diff) | |
download | tour-b1e55b1d524fba2e13e5b0f2c349546b43fe8341.tar.gz |
*
Diffstat (limited to 'html/rogue/js/fow.js')
-rw-r--r-- | html/rogue/js/fow.js | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/html/rogue/js/fow.js b/html/rogue/js/fow.js index e5852d3..7a2914e 100644 --- a/html/rogue/js/fow.js +++ b/html/rogue/js/fow.js @@ -53,38 +53,24 @@ const FogOfWar = { } }, + getFogState(hex) { + if (!this.isRevealed(hex)) return Config.fog.states.HIDDEN; + if (!this.isVisible(hex)) return Config.fog.states.REVEALED; + return Config.fog.states.VISIBLE; + }, + // Draw fog of war effect draw(ctx) { HexGrid.getViewportHexes().forEach(hex => { - const pixel = HexGrid.toPixel(hex); - const screenX = Math.round(pixel.x - Camera.x); - const screenY = Math.round(pixel.y - Camera.y); - - if (!this.isRevealed(hex)) { - ctx.fillStyle = 'rgba(0, 0, 0, 1)'; // Completely opaque for unrevealed - this.drawHexShape(ctx, screenX, screenY); - } else if (!this.isVisible(hex)) { - ctx.fillStyle = 'rgba(0, 0, 0, 0.5)'; // Semi-transparent for revealed but not visible - this.drawHexShape(ctx, screenX, screenY); + const fogState = this.getFogState(hex); + if (fogState.alpha > 0) { + const screen = HexGrid.toScreenCoordinates(hex, Camera); + ctx.fillStyle = fogState === Config.fog.states.HIDDEN ? + Config.colors.FOG.HIDDEN : + Config.colors.FOG.REVEALED; + HexGrid.drawHexPath(ctx, screen.x, screen.y, HexGrid.SIZE, 1); + ctx.fill(); } }); - }, - - // Helper method to draw hex shape - drawHexShape(ctx, x, y) { - const padding = 1; // Add 1 pixel padding to prevent gaps - ctx.beginPath(); - for (let i = 0; i < 6; i++) { - const angle = 2 * Math.PI / 6 * i; - const xPos = Math.round(x + (HexGrid.SIZE + padding) * Math.cos(angle)); - const yPos = Math.round(y + (HexGrid.SIZE + padding) * Math.sin(angle)); - if (i === 0) { - ctx.moveTo(xPos, yPos); - } else { - ctx.lineTo(xPos, yPos); - } - } - ctx.closePath(); - ctx.fill(); } }; \ No newline at end of file |