diff options
author | elioat <elioat@tilde.institute> | 2024-12-24 17:04:28 -0500 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2024-12-24 17:04:28 -0500 |
commit | 2c9409826b5d61b53ce533b57e76904dc3a96799 (patch) | |
tree | 35dc82fcb701ff3a94c79876557c27d64711345a /html | |
parent | eb9ccdab0a9151e8becd31f1aeb222ca237a2d8b (diff) | |
download | tour-2c9409826b5d61b53ce533b57e76904dc3a96799.tar.gz |
*
Diffstat (limited to 'html')
-rw-r--r-- | html/rogue/js/world.js | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/html/rogue/js/world.js b/html/rogue/js/world.js index fb29e27..789b5f4 100644 --- a/html/rogue/js/world.js +++ b/html/rogue/js/world.js @@ -112,7 +112,6 @@ const GRASS_TYPES = { type: 'grass', width: 30, height: 40, - blades: 5, color: '#33aa55', shadowColor: '#229944' }, @@ -120,7 +119,6 @@ const GRASS_TYPES = { type: 'grass', width: 20, height: 25, - blades: 4, color: '#33bb66', shadowColor: '#22aa55' }, @@ -128,7 +126,6 @@ const GRASS_TYPES = { type: 'grass', width: 30, height: 40, - blades: 5, color: '#eebb33', shadowColor: '#cc9922' }, @@ -136,7 +133,6 @@ const GRASS_TYPES = { type: 'grass', width: 20, height: 25, - blades: 4, color: '#ffcc44', shadowColor: '#ddaa33' }, @@ -144,7 +140,6 @@ const GRASS_TYPES = { type: 'grass', width: 30, height: 40, - blades: 5, color: '#44aaff', shadowColor: '#2299ff', glowing: true @@ -153,7 +148,6 @@ const GRASS_TYPES = { type: 'grass', width: 20, height: 25, - blades: 4, color: '#55bbff', shadowColor: '#33aaff', glowing: true @@ -848,22 +842,35 @@ const renderRock = (ctx, rock, groundY) => { // Add grass rendering function const renderGrass = (ctx, grass, groundY, time) => { const { x, config } = grass; - const { width, height, blades, color, shadowColor, glowing } = config; + const { width, height, color, shadowColor, glowing } = config; // Get or initialize grass state const stateKey = `grass_${x}`; if (!window.gameState.world.grassStates[stateKey]) { + // Ensure blade count is between 4 and 8 (inclusive) + const minBlades = 4; + const maxBlades = 8; + // Use Math.round instead of Math.floor and ensure positive value + const randomValue = Math.abs(seededRandom(x, height)); + const bladeCount = minBlades + Math.round(randomValue * (maxBlades - minBlades)); + window.gameState.world.grassStates[stateKey] = { rustleAmount: 0, - rustleDecay: 0.95 + rustleDecay: 0.95, + bladeCount: bladeCount }; } const state = window.gameState.world.grassStates[stateKey]; - + + // Additional validation as a safety net + if (!state.bladeCount || state.bladeCount < 4) { + state.bladeCount = 4; + } + // Check for player interaction const player = window.gameState.player; const interactionDistance = width; - const distanceToPlayer = Math.abs(player.x + player.width/2 - x); + const distanceToPlayer = Math.abs(player.x + player.width / 2 - x); if (distanceToPlayer < interactionDistance) { state.rustleAmount = Math.min(1, state.rustleAmount + 0.3); @@ -875,17 +882,22 @@ const renderGrass = (ctx, grass, groundY, time) => { if (glowing) { ctx.save(); ctx.shadowColor = color; - ctx.shadowBlur = 10 + Math.sin(time/500) * 3; // Pulsing glow effect + ctx.shadowBlur = 10 + Math.sin(time/500) * 3; } // Draw each blade of grass - for (let i = 0; i < blades; i++) { - const bladeX = x + (i - blades/2) * (width/blades); - const bladeWidth = width / blades * 0.7; + for (let i = 0; i < state.bladeCount; i++) { + // Calculate blade width - consistent regardless of blade count + const bladeWidth = width / 5 * 0.7; + + // Calculate blade position - cluster them together more tightly + const spreadFactor = 0.7; // Reduces the spread to create tighter clumps + const centerOffset = (i - (state.bladeCount - 1) / 2) * (width * spreadFactor / state.bladeCount); + const bladeX = x + centerOffset; // Calculate blade curve based on rustle and time - const rustleOffset = Math.sin(time/300 + i) * 5 * state.rustleAmount; - const baseWave = Math.sin(time/1000 + i) * 2; + const rustleOffset = Math.sin(time / 300 + i) * 5 * state.rustleAmount; + const baseWave = Math.sin(time / 1000 + i) * 2; // Draw blade ctx.fillStyle = i % 2 === 0 ? color : shadowColor; @@ -894,7 +906,7 @@ const renderGrass = (ctx, grass, groundY, time) => { // Control points for quadratic curve const cp1x = bladeX + rustleOffset + baseWave; - const cp1y = groundY - height/2; + const cp1y = groundY - height / 2; const cp2x = bladeX + rustleOffset * 1.5 + baseWave; const cp2y = groundY - height; |