"use strict"; const CockpitImpactFx = (function(){ const CockpitImpactFx = function(xgravity){ let flash_alpha = 0; let shards = []; this.trigger = () => { flash_alpha = 0.55; // Fogonazo rápido sobre el cristal shards = []; // Sin metralla de piedras }; this.update = (delta_time) => { if(flash_alpha > 0){ flash_alpha = Math.max(0, flash_alpha - (3.2 * delta_time)); } for(let i = shards.length - 1; i >= 0; i--){ const s = shards[i]; s.life -= s.decay * delta_time; if(s.life <= 0){ shards.splice(i, 1); continue; } s.x += s.vx * delta_time; s.y += s.vy * delta_time; s.angle += s.angular_vel * delta_time; s.vx *= 0.96; s.vy *= 0.96; } }; this.render = (ctx, width, height) => { const cx = width / 2; const cy = height / 2; // Flash blanco en pantalla completa if(flash_alpha > 0){ ctx.save(); ctx.fillStyle = "#ffffff"; ctx.globalAlpha = Math.min(0.7, flash_alpha); ctx.fillRect(0, 0, width, height); ctx.restore(); } // Esquirlas de roca sólidas if(shards.length > 0){ ctx.save(); ctx.translate(cx, cy); for(let i = 0; i < shards.length; i++){ const s = shards[i]; ctx.save(); ctx.translate(s.x, s.y); ctx.rotate(s.angle); ctx.fillStyle = s.color; ctx.globalAlpha = Math.max(0, s.life); ctx.beginPath(); ctx.moveTo(s.vertices[0].x, s.vertices[0].y); for(let v = 1; v < s.vertices.length; v++){ ctx.lineTo(s.vertices[v].x, s.vertices[v].y); } ctx.closePath(); ctx.fill(); ctx.lineWidth = 1.0; ctx.strokeStyle = "rgba(15, 23, 42, 0.85)"; ctx.stroke(); ctx.restore(); } ctx.restore(); } }; this.reset = () => { flash_alpha = 0; shards = []; }; }; return CockpitImpactFx; })();