player
This commit is contained in:
parent
d2fb60df8d
commit
3d15dc716b
@ -31,6 +31,7 @@ export class Player extends Phaser.GameObjects.Container {
|
|||||||
|
|
||||||
// Player state
|
// Player state
|
||||||
public state: PlayerState;
|
public state: PlayerState;
|
||||||
|
private speedMultiplier: number = 1.0;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
scene: Phaser.Scene,
|
scene: Phaser.Scene,
|
||||||
@ -57,6 +58,9 @@ export class Player extends Phaser.GameObjects.Container {
|
|||||||
this.attributes = attributes;
|
this.attributes = attributes;
|
||||||
this.state = 'defensive';
|
this.state = 'defensive';
|
||||||
|
|
||||||
|
// Listen for goal events
|
||||||
|
this.scene.events.on('goal', this.onGoal, this);
|
||||||
|
|
||||||
// Add to scene
|
// Add to scene
|
||||||
scene.add.existing(this);
|
scene.add.existing(this);
|
||||||
scene.physics.add.existing(this);
|
scene.physics.add.existing(this);
|
||||||
@ -125,6 +129,24 @@ export class Player extends Phaser.GameObjects.Container {
|
|||||||
this.targetY = targetY;
|
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
|
* Update player movement each frame
|
||||||
*/
|
*/
|
||||||
@ -142,7 +164,8 @@ export class Player extends Phaser.GameObjects.Container {
|
|||||||
|
|
||||||
// Calculate velocity based on speed attribute
|
// Calculate velocity based on speed attribute
|
||||||
// speed attribute (0-100) maps to actual m/s (e.g., 80 -> 8 m/s)
|
// 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
|
// Normalize direction and apply speed
|
||||||
const dirX = dx / distance;
|
const dirX = dx / distance;
|
||||||
|
|||||||
@ -42,7 +42,7 @@ export class GameScene extends Phaser.Scene {
|
|||||||
'home',
|
'home',
|
||||||
'C',
|
'C',
|
||||||
-10,
|
-10,
|
||||||
0,
|
-10,
|
||||||
{ speed: 80, skill: 75 }
|
{ speed: 80, skill: 75 }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user