fea: 优化死亡特效

This commit is contained in:
cancerai committed 2026-10-24 02:35:03 +08:00
1 parent afe2f64b9b
commit e7200989ab
9 files changed
+373 -94

No files matched your search

+38 -4
View File
@@ -87,7 +87,7 @@ export class Level {
/** 完整重置(死亡 / 重开) */
reset(full = false) {
// tiles 状态(vanish 等)
if (full) this.deathMarks = []; // 死亡血迹只在整关重开时清空,复活后保留
if (full) { this.deathMarks = []; this.deathFX = []; } // 血迹/死亡特效只在整关重开时清空,复活后保留
this.vanish = new Map();
this.bullets = [];
this.ebullets = [];
@@ -215,14 +215,15 @@ export class Level {
this.totalSaves = saveNo;
}
/** 死亡后的软重置:保留存档点与已拾取道具,其余复位 */
/** 死亡后的软重置:保留存档点与已拾取道具,其余复位。
* 粒子与震屏是"演出层":不清场——无论主动按 R 还是被动死亡后秒按 R,
* 死亡特效都留在死亡位置自然播完(粒子 34 帧 / 冲击环 14 帧 / 震屏衰减),
* 重生只重置关卡逻辑状态,不掐断演出。整关重开(reset(true))才会清空 */
softReset() {
this.vanish.clear();
if (this.vanishT) this.vanishT.clear();
this.bullets.length = 0;
this.ebullets.length = 0;
this.particles?.clear();
this.shake = 0;
for (const m of this.movers) {
const a = m.path[0];
if (a) { m.x = a.x; m.y = a.y; m.i = 0; }
@@ -253,6 +254,31 @@ export class Level {
this.deathMarks.push({ x, y });
}
// 死亡特效(扩散冲击环):记录到关卡层而非玩家——主动重生时玩家当帧就复活了,
// 环要留在死亡位置播完。t 由 update 推进,14 帧扩散淡出后移除
addDeathFX(x, y) {
this.deathFX.push({ x, y, t: 0 });
}
drawDeathRing(ctx, fx) {
const t = fx.t;
if (t > 14) return;
const r = 4 + t * 1.8, a = Math.max(0, 1 - t / 14);
ctx.save();
ctx.globalAlpha = a * 0.85;
ctx.strokeStyle = '#ff8fa3';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.arc(fx.x, fx.y, r, 0, Math.PI * 2);
ctx.stroke();
ctx.globalAlpha = a * 0.3;
ctx.fillStyle = '#ff5c7a';
ctx.beginPath();
ctx.arc(fx.x, fx.y, r * 0.55, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
}
drawDeathMark(ctx, dm) {
const s = 4; // 红叉半边长(< kid 的 11×21,整体约 8px)
ctx.lineCap = 'round';
@@ -370,6 +396,11 @@ export class Level {
this.time += dt;
const t = this.time;
// 死亡特效(冲击环)推进:14 帧后移除;粒子由 particles.update 自理
for (let i = this.deathFX.length - 1; i >= 0; i--) {
if (++this.deathFX[i].t > 14) this.deathFX.splice(i, 1);
}
// 移动平台
for (const m of this.movers) {
if (!m.path.length) continue;
@@ -623,6 +654,9 @@ export class Level {
// 死亡血迹(IWBTG 风格,常驻于死亡地点)
for (const dm of this.deathMarks) this.drawDeathMark(ctx, dm);
// 死亡特效(扩散冲击环,14 帧淡出)
for (const fx of this.deathFX) this.drawDeathRing(ctx, fx);
this.particles.draw(ctx);
ctx.restore();
}