/* RESPAWN BUTTON WITH PULSING EFFECT */ let respawnButton = { show: false, x: 400, y: 280, width: 120, height: 50, text: "RESPAWN", pulse: 0, // current pulse value pulseDir: 1 // direction of pulse (1=increasing, -1=decreasing) }; // Click handler c.addEventListener("click", (e) => { if(respawnButton.show){ const rect = c.getBoundingClientRect(); const mx = e.clientX - rect.left; const my = e.clientY - rect.top; if(mx > respawnButton.x && mx < respawnButton.x + respawnButton.width && my > respawnButton.y && my < respawnButton.y + respawnButton.height){ respawnPlayer(); } } }); // Respawn function function respawnPlayer(){ player.hp = player.maxHp; player.mana = player.maxMana; player.x = 450; player.y = 300; spawnBoss(); minis = []; for(let i=0;i<3;i++) spawnMini(); enemyFire.length = 0; particles.length = 0; respawnButton.show = false; respawnButton.pulse = 0; respawnButton.pulseDir = 1; loop(); } // Draw button with pulsing glow function drawRespawnButton(){ if(!respawnButton.show) return; // Update pulse respawnButton.pulse += 0.02 * respawnButton.pulseDir; if(respawnButton.pulse > 0.5) respawnButton.pulseDir = -1; if(respawnButton.pulse < 0) respawnButton.pulseDir = 1; // Button base ctx.fillStyle = "#222"; ctx.fillRect(respawnButton.x, respawnButton.y, respawnButton.width, respawnButton.height); ctx.lineWidth = 3; // Hover effect let rect = c.getBoundingClientRect(); let mx = (mouse.x), my = (mouse.y); let hover = mx > respawnButton.x && mx < respawnButton.x + respawnButton.width && my > respawnButton.y && my < respawnButton.y + respawnButton.height; ctx.strokeStyle = hover ? `rgba(0,255,255,${0.5 + respawnButton.pulse})` : `rgba(255,255,255,${0.5 + respawnButton.pulse})`; ctx.strokeRect(respawnButton.x, respawnButton.y, respawnButton.width, respawnButton.height); // Glow effect ctx.shadowColor = hover ? "cyan" : "white"; ctx.shadowBlur = 10 + respawnButton.pulse * 20; // Text ctx.fillStyle = hover ? "cyan" : "white"; ctx.font = "20px sans-serif"; ctx.textAlign = "center"; ctx.textBaseline = "middle"; ctx.fillText(respawnButton.text, respawnButton.x + respawnButton.width/2, respawnButton.y + respawnButton.height/2); // Reset shadow ctx.shadowBlur = 0; }