Refactor BomberEnemy to support distinct explosion behaviors for proximity vs death triggers
This commit is contained in:
parent
303956ae4d
commit
802f11430c
|
|
@ -1,8 +1,10 @@
|
|||
import { BaseEnemy } from './BaseEnemy.js';
|
||||
|
||||
const EXPLODE_RADIUS = 180; // px — triggers explosion when this close to player
|
||||
const SHARD_COUNT = 8;
|
||||
const SHARD_SPEED = 360; // px/s — travels ~250px over SHARD_DURATION
|
||||
const EXPLODE_RADIUS = 180; // px — triggers proximity explosion
|
||||
const PROXIMITY_SHARD_PX = 250; // travel distance for proximity explosion
|
||||
const DEATH_SHARD_PX = 200; // travel distance for on-death explosion
|
||||
const SHARD_COUNT = 8;
|
||||
const SHARD_SPEED = 360; // px/s baseline (overridden per explosion type)
|
||||
const SHARD_DAMAGE = 15;
|
||||
const SHARD_DURATION = 700; // ms until shards disappear
|
||||
const SHARD_HIT_RADIUS = 18; // px — how close a shard must be to damage player
|
||||
|
|
@ -20,6 +22,7 @@ export class BomberEnemy extends BaseEnemy {
|
|||
});
|
||||
this._offsetAngle = Math.random() * Math.PI * 2;
|
||||
this._wobble = 0.3 + Math.random() * 0.4;
|
||||
this._exploded = false;
|
||||
}
|
||||
|
||||
update(delta) {
|
||||
|
|
@ -41,11 +44,22 @@ export class BomberEnemy extends BaseEnemy {
|
|||
|
||||
_triggerExplosion() {
|
||||
if (this._dying) return;
|
||||
this._spawnShards();
|
||||
this._exploded = true;
|
||||
this._spawnShards(PROXIMITY_SHARD_PX);
|
||||
this._die();
|
||||
}
|
||||
|
||||
_spawnShards() {
|
||||
// Override _die so a bullet-killed Bomber still explodes (smaller radius).
|
||||
_die() {
|
||||
if (!this._exploded) {
|
||||
this._exploded = true;
|
||||
this._spawnShards(DEATH_SHARD_PX);
|
||||
}
|
||||
super._die();
|
||||
}
|
||||
|
||||
_spawnShards(travelPx) {
|
||||
const shardSpeed = travelPx / (SHARD_DURATION / 1000);
|
||||
const scene = this.scene;
|
||||
const ox = this.x;
|
||||
const oy = this.y;
|
||||
|
|
@ -85,8 +99,8 @@ export class BomberEnemy extends BaseEnemy {
|
|||
|
||||
shards.push({
|
||||
obj: tri,
|
||||
vx: Math.cos(angle) * SHARD_SPEED,
|
||||
vy: Math.sin(angle) * SHARD_SPEED,
|
||||
vx: Math.cos(angle) * shardSpeed,
|
||||
vy: Math.sin(angle) * shardSpeed,
|
||||
rotSpeed: (Math.random() > 0.5 ? 1 : -1) * (6 + Math.random() * 6), // rad/s
|
||||
alive: true,
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue