diff --git a/public/js/effects/fireworks.js b/public/js/effects/fireworks.js index d0deef1..f1063fa 100644 --- a/public/js/effects/fireworks.js +++ b/public/js/effects/fireworks.js @@ -18,13 +18,19 @@ const FireworksEffect = (() => { * @param {string} color 爆炸颜色 * @param {string} type 爆炸类型:sphere / willow / ring */ - constructor(x, targetY, color, type) { + constructor(x, targetY, color, type, canvasHeight) { this.x = x; - this.y = 9999; // 在 start() 里设置为 canvas.height + this.y = canvasHeight; // 从画布底部出发 this.targetY = targetY; this.color = color; this.type = type; - this.vy = -(12 + Math.random() * 4); // 上升速度 + + // 根据飞行距离动态计算初始速度,保证必然到达目标高度 + // 等比级数求和:total = vy / (1 - 0.98) = vy × 50 + // 加 10%~20% 余量,使火箭略微超过目标再触发爆炸(更真实) + const dist = canvasHeight - targetY; + this.vy = -(dist / 50) * (1.1 + Math.random() * 0.15); + this.trail = []; // 尾迹历史坐标 this.exploded = false; this.done = false; @@ -255,8 +261,7 @@ const FireworksEffect = (() => { const ty = h * (0.08 + Math.random() * 0.45); const color = COLORS[Math.floor(Math.random() * COLORS.length)]; const type = TYPES[Math.floor(Math.random() * TYPES.length)]; - const rocket = new Rocket(x, ty, color, type); - rocket.y = h; // 从底部发射 + const rocket = new Rocket(x, ty, color, type, h); // 传入画布高度 rockets.push(rocket); launchCnt++; }, 600);