Refactor death pulse effect to BaseEnemy with per-enemy color customization
This commit is contained in:
parent
d0b7b79af0
commit
b17cb86c55
|
|
@ -1,7 +1,5 @@
|
|||
import { BaseEnemy } from './BaseEnemy.js';
|
||||
|
||||
const GRID = 80;
|
||||
|
||||
export class ChaseEnemy extends BaseEnemy {
|
||||
constructor(scene, x, y, player) {
|
||||
super(scene, x, y, player, {
|
||||
|
|
@ -12,6 +10,7 @@ export class ChaseEnemy extends BaseEnemy {
|
|||
xp: 15,
|
||||
contactDamage: 12,
|
||||
});
|
||||
this._deathPulseColor = 0x00ff44;
|
||||
}
|
||||
|
||||
update(delta) {
|
||||
|
|
@ -24,43 +23,7 @@ export class ChaseEnemy extends BaseEnemy {
|
|||
}
|
||||
|
||||
_die() {
|
||||
this._gridDeathPulse(this.x, this.y);
|
||||
this._gridDeathPulse();
|
||||
super._die();
|
||||
}
|
||||
|
||||
_gridDeathPulse(px, py) {
|
||||
const scene = this.scene;
|
||||
const W = scene.scale.width;
|
||||
const H = scene.scale.height;
|
||||
const col = Math.floor(px / GRID);
|
||||
const row = Math.floor(py / GRID);
|
||||
|
||||
const makeTile = (c, r, alpha) => {
|
||||
if (c < 0 || r < 0 || c * GRID >= W || r * GRID >= H) return null;
|
||||
return scene.add.rectangle(
|
||||
c * GRID + GRID / 2,
|
||||
r * GRID + GRID / 2,
|
||||
GRID, GRID, 0x00ff44, alpha,
|
||||
).setDepth(2);
|
||||
};
|
||||
|
||||
const center = makeTile(col, row, 0.55);
|
||||
|
||||
// Pre-create adjacent tiles but hide them until ADJ_MS elapses
|
||||
const adjacents = [];
|
||||
[[-1, 0], [1, 0], [0, -1], [0, 1]].forEach(([dc, dr]) => {
|
||||
const t = makeTile(col + dc, row + dr, 0.38);
|
||||
if (t) { t.setVisible(false); adjacents.push(t); }
|
||||
});
|
||||
|
||||
scene._pulseEffects.push({
|
||||
center,
|
||||
adjacents,
|
||||
elapsed: 0,
|
||||
adjSpawned: false,
|
||||
ADJ_MS: 80,
|
||||
FADE_MS: 120,
|
||||
END_MS: 400,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,12 @@ export class ShooterEnemy extends BaseEnemy {
|
|||
});
|
||||
this._shootTimer = SHOOT_INTERVAL * Math.random(); // stagger first shot
|
||||
this.projectiles = scene.add.group();
|
||||
this._deathPulseColor = 0x9900ff;
|
||||
}
|
||||
|
||||
_die() {
|
||||
this._gridDeathPulse();
|
||||
super._die();
|
||||
}
|
||||
|
||||
update(delta) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,12 @@ export class SprayerEnemy extends BaseEnemy {
|
|||
});
|
||||
this._shootTimer = SHOOT_INTERVAL * Math.random();
|
||||
this.projectiles = scene.add.group();
|
||||
this._deathPulseColor = 0x00ffcc;
|
||||
}
|
||||
|
||||
_die() {
|
||||
this._gridDeathPulse();
|
||||
super._die();
|
||||
}
|
||||
|
||||
update(delta) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,12 @@ export class SwarmerEnemy extends BaseEnemy {
|
|||
// Slight random offset so swarms don't stack perfectly
|
||||
this._offsetAngle = Math.random() * Math.PI * 2;
|
||||
this._wobble = Math.random() * 0.5;
|
||||
this._deathPulseColor = 0xff2222;
|
||||
}
|
||||
|
||||
_die() {
|
||||
this._gridDeathPulse();
|
||||
super._die();
|
||||
}
|
||||
|
||||
update(delta) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue