diff options
| author | elioat <elioat@tilde.institute> | 2025-09-04 21:23:18 -0400 |
|---|---|---|
| committer | elioat <elioat@tilde.institute> | 2025-09-04 21:23:18 -0400 |
| commit | 54ecce17edc2d544f1226313788ad03c8453cf83 (patch) | |
| tree | 09b7abf673e02127156c3d965f2ba700b726d222 /html | |
| parent | b6cbc346a2f9e355df4aad8582209833405e9104 (diff) | |
| download | tour-54ecce17edc2d544f1226313788ad03c8453cf83.tar.gz | |
*
Diffstat (limited to 'html')
| -rw-r--r-- | html/strata/game.js | 98 |
1 files changed, 93 insertions, 5 deletions
diff --git a/html/strata/game.js b/html/strata/game.js index 4b0d767..4dcd3be 100644 --- a/html/strata/game.js +++ b/html/strata/game.js @@ -1016,9 +1016,92 @@ const drawPlayer = (ctx, x, y, cellSize, animationState, currentTime) => { }; /** + * Draw magnet card with sparkling effect + */ +const drawMagnetCard = (ctx, x, y, size, currentTime) => { + ctx.save(); + + // Base magnet color (silver) + const baseColor = '#C0C0C0'; + + // Draw base magnet rectangle + ctx.fillStyle = baseColor; + ctx.fillRect(x, y, size, size); + + // Create multiple sparkle points distributed across the card + const sparkleTime = (currentTime % 3000) / 3000; // 3 second cycle for slower, more elegant effect + const sparkleCount = 8; // More sparkles for better distribution + + for (let i = 0; i < sparkleCount; i++) { + // Create different timing for each sparkle + const sparklePhase = (sparkleTime + i / sparkleCount) % 1; + const sparkleIntensity = Math.sin(sparklePhase * Math.PI) * 0.9; // 0 to 0.9 + + if (sparkleIntensity > 0.1) { + ctx.globalAlpha = sparkleIntensity; + + // Distribute sparkles across the entire card area + const sparkleX = x + (size * 0.1) + (i % 3) * (size * 0.3) + Math.sin(sparklePhase * Math.PI * 4) * (size * 0.1); + const sparkleY = y + (size * 0.1) + Math.floor(i / 3) * (size * 0.3) + Math.cos(sparklePhase * Math.PI * 3) * (size * 0.1); + + // Vary sparkle sizes + const sparkleSize = size * (0.08 + Math.sin(sparklePhase * Math.PI * 2) * 0.04); + + // Create a small cross or star shape for sparkles + ctx.fillStyle = '#FFFFFF'; + ctx.strokeStyle = '#E0E0FF'; + ctx.lineWidth = 0.5; + + // Draw cross sparkle + ctx.beginPath(); + ctx.moveTo(sparkleX - sparkleSize, sparkleY); + ctx.lineTo(sparkleX + sparkleSize, sparkleY); + ctx.moveTo(sparkleX, sparkleY - sparkleSize); + ctx.lineTo(sparkleX, sparkleY + sparkleSize); + ctx.stroke(); + + // Add center dot + ctx.beginPath(); + ctx.arc(sparkleX, sparkleY, sparkleSize * 0.3, 0, Math.PI * 2); + ctx.fill(); + } + } + + // Add subtle shimmer overlay that moves across the card + const shimmerPhase = (sparkleTime * 2) % 1; // Faster shimmer + const shimmerAlpha = 0.2 + 0.3 * Math.sin(shimmerPhase * Math.PI * 2); + + ctx.globalAlpha = shimmerAlpha; + const shimmerGradient = ctx.createLinearGradient( + x + shimmerPhase * size, y, + x + shimmerPhase * size + size * 0.3, y + size + ); + shimmerGradient.addColorStop(0, 'rgba(255, 255, 255, 0)'); + shimmerGradient.addColorStop(0.5, 'rgba(255, 255, 255, 0.6)'); + shimmerGradient.addColorStop(1, 'rgba(255, 255, 255, 0)'); + + ctx.fillStyle = shimmerGradient; + ctx.fillRect(x, y, size, size); + + // Add subtle border with slight glow + ctx.globalAlpha = 0.4; + ctx.strokeStyle = '#FFFFFF'; + ctx.lineWidth = 1; + ctx.strokeRect(x, y, size, size); + + // Add outer glow + ctx.globalAlpha = 0.1; + ctx.strokeStyle = '#E0E0FF'; + ctx.lineWidth = 2; + ctx.strokeRect(x - 1, y - 1, size + 2, size + 2); + + ctx.restore(); +}; + +/** * Draw grid with given data */ -const drawGrid = (ctx, startX, startY, cellSize, padding, grid, player, game) => { +const drawGrid = (ctx, startX, startY, cellSize, padding, grid, player, game, currentTime) => { // Get level number for color palette const levelNumber = game.currentLevel ? game.currentLevel.levelNumber : 1; @@ -1101,8 +1184,13 @@ const drawGrid = (ctx, startX, startY, cellSize, padding, grid, player, game) => const cardSize = Math.floor(cellSize * 0.25); // 25% of cell size const cardOffset = 5; // Upper-left corner positioning - ctx.fillStyle = getCardColor(cell.card.type); - ctx.fillRect(x + cardOffset, y + cardOffset, cardSize, cardSize); + if (cell.card.type === CardType.MAGNET) { + // Draw magnet with sparkling effect + drawMagnetCard(ctx, x + cardOffset, y + cardOffset, cardSize, currentTime); + } else { + ctx.fillStyle = getCardColor(cell.card.type); + ctx.fillRect(x + cardOffset, y + cardOffset, cardSize, cardSize); + } // Add border for persistent cards if (cell.card.persistent) { @@ -1218,7 +1306,7 @@ const render = (game, canvas, ctx) => { // Draw old level (if showing) if (showOldLevel) { ctx.globalAlpha = oldLevelAlpha; - drawGrid(ctx, startX, startY, cellSize, padding, game.currentLevel.grid, game.player, game); + drawGrid(ctx, startX, startY, cellSize, padding, game.currentLevel.grid, game.player, game, currentTime); } // Draw new level (if showing) @@ -1226,7 +1314,7 @@ const render = (game, canvas, ctx) => { ctx.globalAlpha = newLevelAlpha; // Create a temporary game object for the new level const tempGame = { ...game, player: game.animationState.newPlayer, currentLevel: game.animationState.newLevel }; - drawGrid(ctx, startX, startY, cellSize, padding, game.animationState.newLevel.grid, game.animationState.newPlayer, tempGame); + drawGrid(ctx, startX, startY, cellSize, padding, game.animationState.newLevel.grid, game.animationState.newPlayer, tempGame, currentTime); } // Reset alpha for other elements |