diff --git a/src/entities/Player.ts b/src/entities/Player.ts index 57e29b3..85f9a6f 100644 --- a/src/entities/Player.ts +++ b/src/entities/Player.ts @@ -31,6 +31,7 @@ export class Player extends Phaser.GameObjects.Container { // Player state public state: PlayerState; + private speedMultiplier: number = 1.0; constructor( scene: Phaser.Scene, @@ -57,6 +58,9 @@ export class Player extends Phaser.GameObjects.Container { this.attributes = attributes; this.state = 'defensive'; + // Listen for goal events + this.scene.events.on('goal', this.onGoal, this); + // Add to scene scene.add.existing(this); scene.physics.add.existing(this); @@ -125,6 +129,24 @@ export class Player extends Phaser.GameObjects.Container { this.targetY = targetY; } + /** + * Handle goal event + */ + private onGoal(_data: { team: string; goal: string }) { + // Gradually decelerate player after goal + const decelerate = () => { + this.speedMultiplier *= 0.9; + + if (this.speedMultiplier > 0.01) { + this.scene.time.delayedCall(50, decelerate); + } else { + this.speedMultiplier = 0; + } + }; + + decelerate(); + } + /** * Update player movement each frame */ @@ -142,7 +164,8 @@ export class Player extends Phaser.GameObjects.Container { // Calculate velocity based on speed attribute // speed attribute (0-100) maps to actual m/s (e.g., 80 -> 8 m/s) - const speed = (this.attributes.speed / 10) * SCALE; // Convert to pixels/s + const baseSpeed = (this.attributes.speed / 10) * SCALE; // Convert to pixels/s + const speed = baseSpeed * this.speedMultiplier; // Apply speed multiplier // Normalize direction and apply speed const dirX = dx / distance; diff --git a/src/game/GameScene.ts b/src/game/GameScene.ts index 3defbbd..e0db366 100644 --- a/src/game/GameScene.ts +++ b/src/game/GameScene.ts @@ -42,7 +42,7 @@ export class GameScene extends Phaser.Scene { 'home', 'C', -10, - 0, + -10, { speed: 80, skill: 75 } );