Stabilise pirate projectile hits on player
This commit is contained in:
parent
fbf5791845
commit
f866a02838
@ -431,23 +431,32 @@ class GameScene extends Phaser.Scene {
|
|||||||
hitPlayer(shot) {
|
hitPlayer(shot) {
|
||||||
if (!shot?.active || this.gameState !== 'playing') return;
|
if (!shot?.active || this.gameState !== 'playing') return;
|
||||||
|
|
||||||
const damage = shot.getData('damage') || PIRATE_SHOT_DAMAGE;
|
const rawDamage = Number(shot.getData('damage'));
|
||||||
|
const damage = clamp(Number.isFinite(rawDamage) ? rawDamage : PIRATE_SHOT_DAMAGE, 1, 25);
|
||||||
const { x, y } = shot;
|
const { x, y } = shot;
|
||||||
shot.destroy();
|
|
||||||
|
|
||||||
// Always show projectile impact feedback. Damage is still rate-limited so
|
// Do not destroy an Arcade body from inside the overlap callback. Disable
|
||||||
// one three-shot broadside cannot register as three hull hits.
|
// it immediately, then clean it up and render impact FX on the next tick.
|
||||||
this.spawnExplosion(x, y, 0.32);
|
if (shot.body) shot.disableBody(true, true);
|
||||||
this.flashShip(this.player, 0xffcccc);
|
else shot.setActive(false).setVisible(false);
|
||||||
|
|
||||||
|
this.time.delayedCall(0, () => {
|
||||||
|
if (shot?.scene) shot.destroy();
|
||||||
|
try {
|
||||||
|
this.spawnExplosion(x, y, 0.32);
|
||||||
|
this.flashShip(this.player, 0xffcccc);
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Player impact FX failed', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (this.time.now - this.lastPlayerHitAt < PLAYER_HIT_COOLDOWN_MS) return;
|
if (this.time.now - this.lastPlayerHitAt < PLAYER_HIT_COOLDOWN_MS) return;
|
||||||
this.lastPlayerHitAt = this.time.now;
|
this.lastPlayerHitAt = this.time.now;
|
||||||
|
|
||||||
this.playerHull = Math.max(0, this.playerHull - damage);
|
const currentHull = Number.isFinite(this.playerHull) ? this.playerHull : PLAYER_MAX_HULL;
|
||||||
|
this.playerHull = Math.max(0, currentHull - damage);
|
||||||
|
|
||||||
if (this.playerHull <= 0) {
|
if (this.playerHull <= 0) this.finishGame();
|
||||||
this.finishGame();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spawnExplosion(x, y, scale = 1) {
|
spawnExplosion(x, y, scale = 1) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user