Consume processed pirate shots reliably

This commit is contained in:
Admin 2026-09-18 06:32:23 +00:00
parent 07114e85dc
commit c7188e4f8f
2 changed files with 21 additions and 9 deletions

View File

@ -79,8 +79,6 @@ class GameScene extends Phaser.Scene {
this.player = this.physics.add.sprite(1200, 1550, 'airships', 0); this.player = this.physics.add.sprite(1200, 1550, 'airships', 0);
this.player.setDepth(6).setCollideWorldBounds(true).setDisplaySize(74, 74); this.player.setDepth(6).setCollideWorldBounds(true).setDisplaySize(74, 74);
this.playerBaseScaleX = this.player.scaleX;
this.playerBaseScaleY = this.player.scaleY;
this.player.body.setAllowGravity(false); this.player.body.setAllowGravity(false);
this.player.body.setSize(42, 56, true); this.player.body.setSize(42, 56, true);
this.player.play('player-idle'); this.player.play('player-idle');
@ -537,6 +535,7 @@ class GameScene extends Phaser.Scene {
shot.body.setAllowGravity(false); shot.body.setAllowGravity(false);
shot.setData('bornAt', this.time.now); shot.setData('bornAt', this.time.now);
shot.setData('damage', damage); shot.setData('damage', damage);
if (group === this.pirateShots) shot.setData('playerHitQueued', false);
shot.setVelocity( shot.setVelocity(
Math.cos(angle) * SHOT_SPEED * velocityScale + ship.body.velocity.x * 0.25, Math.cos(angle) * SHOT_SPEED * velocityScale + ship.body.velocity.x * 0.25,
Math.sin(angle) * SHOT_SPEED * velocityScale + ship.body.velocity.y * 0.25, Math.sin(angle) * SHOT_SPEED * velocityScale + ship.body.velocity.y * 0.25,
@ -631,6 +630,10 @@ class GameScene extends Phaser.Scene {
this.playerHull = result.hull; this.playerHull = result.hull;
const { totalDamage, appliedHits, gameOver } = result; const { totalDamage, appliedHits, gameOver } = result;
for (const impact of hits) {
if (impact.shot?.active) impact.shot.destroy();
}
if (appliedHits > 0) { if (appliedHits > 0) {
try { try {
for (const impact of hits) { for (const impact of hits) {
@ -689,20 +692,18 @@ class GameScene extends Phaser.Scene {
if (!this.player?.active) return; if (!this.player?.active) return;
this.tweens.killTweensOf(this.player); this.tweens.killTweensOf(this.player);
this.player.setScale(this.playerBaseScaleX, this.playerBaseScaleY); this.player.setAlpha(1);
this.player.setTint(0xffd7d7); this.player.setTint(0xffd7d7);
this.tweens.add({ this.tweens.add({
targets: this.player, targets: this.player,
scaleX: this.playerBaseScaleX * 1.12, alpha: 0.45,
scaleY: this.playerBaseScaleY * 1.12, duration: 65,
alpha: 0.62,
duration: 70,
yoyo: true, yoyo: true,
repeat: 1,
ease: 'Quad.easeOut', ease: 'Quad.easeOut',
onComplete: () => { onComplete: () => {
if (!this.player?.active) return; if (!this.player?.active) return;
this.player.setScale(this.playerBaseScaleX, this.playerBaseScaleY);
this.player.setAlpha(1); this.player.setAlpha(1);
this.player.clearTint(); this.player.clearTint();
}, },

View File

@ -208,8 +208,19 @@ test('processed player hits drive sprite and HUD hit reactions', async () => {
assert.match(game, /this\.playerHitSequence \+= 1/); assert.match(game, /this\.playerHitSequence \+= 1/);
assert.match(game, /playPlayerHitReaction\(damage = PIRATE_SHOT_DAMAGE\)/); assert.match(game, /playPlayerHitReaction\(damage = PIRATE_SHOT_DAMAGE\)/);
assert.match(game, /scaleX: this\.playerBaseScaleX \* 1\.12/); assert.match(game, /alpha: 0\.45/);
assert.match(game, /repeat: 1/);
assert.match(game, /this\.cameras\.main\.shake\(120/); assert.match(game, /this\.cameras\.main\.shake\(120/);
assert.doesNotMatch(game, /scaleX: this\.playerBaseScaleX/);
assert.match(hud, /steam-player-card\.steam-hit/); assert.match(hud, /steam-player-card\.steam-hit/);
assert.match(hud, /pulsePlayerHit\(state\.player\.hitSequence \?\? 0\)/); assert.match(hud, /pulsePlayerHit\(state\.player\.hitSequence \?\? 0\)/);
}); });
test('processed pirate shots are consumed and later projectiles start clean', async () => {
const source = await read('src/game-v4.js');
assert.match(source, /if \(group === this\.pirateShots\) shot\.setData\('playerHitQueued', false\)/);
assert.match(source, /for \(const impact of hits\) \{[\s\S]*?if \(impact\.shot\?\.active\) impact\.shot\.destroy\(\)/);
assert.match(source, /if \(shot\.getData\('playerHitQueued'\)\) return/);
});