diff --git a/src/config/constants.ts b/src/config/constants.ts index 3d4109c..22a212f 100644 --- a/src/config/constants.ts +++ b/src/config/constants.ts @@ -68,3 +68,4 @@ export const TACKLE_SUCCESS_MODIFIER = 1; // Multiplier for tackle succ export const TACKLE_PUCK_LOOSE_CHANCE = 0.6; // Chance puck becomes loose after tackle export const TACKLE_COOLDOWN = 1000; // ms - time between tackles for same player export const TACKLE_FALL_DURATION = 500; // ms - time player stays down after being tackled +export const TACKLE_MIN_SPEED = 2; // m/s - minimum speed required to execute tackle diff --git a/src/entities/Player.ts b/src/entities/Player.ts index 60f3dd8..15472e2 100644 --- a/src/entities/Player.ts +++ b/src/entities/Player.ts @@ -324,6 +324,13 @@ export class Player extends Phaser.GameObjects.Container { this.body.setVelocity(0, 0); } + /** + * Get current speed in m/s + */ + public getCurrentSpeed(): number { + return this.currentSpeed; + } + /** * Update debug visualizations (target position and path line) */ diff --git a/src/game/GameScene.ts b/src/game/GameScene.ts index 5f7a9b7..d4b7227 100644 --- a/src/game/GameScene.ts +++ b/src/game/GameScene.ts @@ -17,7 +17,8 @@ import { PUCK_PICKUP_RADIUS, SHOT_SPEED, TACKLE_SUCCESS_MODIFIER, - TACKLE_PUCK_LOOSE_CHANCE + TACKLE_PUCK_LOOSE_CHANCE, + TACKLE_MIN_SPEED } from '../config/constants'; import { Goal } from './Goal'; import { Puck } from '../entities/Puck'; @@ -315,6 +316,16 @@ export class GameScene extends Phaser.Scene { * Execute tackle using tackling skill vs balance skill */ private executeTackle(tackler: Player, tackled: Player) { + // Check if tackler has sufficient speed to execute tackle + const tacklerSpeed = tackler.getCurrentSpeed(); + + if (tacklerSpeed < TACKLE_MIN_SPEED) { + console.log( + `[Tackle] ${tackler.id} moving too slow (${tacklerSpeed.toFixed(1)} m/s < ${TACKLE_MIN_SPEED} m/s) - tackle impossible` + ); + return; // Tackle cannot occur + } + // Calculate tackle success based on tackling vs balance // Formula: (tackling / (tackling + balance)) * modifier const tacklerSkill = tackler.attributes.tackling; @@ -324,7 +335,7 @@ export class GameScene extends Phaser.Scene { const success = Math.random() < successChance; console.log( - `[Tackle] ${tackler.id} (tackling: ${tacklerSkill}) tackles ${tackled.id} (balance: ${tackledBalance}) - ${success ? 'SUCCESS' : 'FAILED'} (${(successChance * 100).toFixed(1)}%)` + `[Tackle] ${tackler.id} (tackling: ${tacklerSkill}, speed: ${tacklerSpeed.toFixed(1)} m/s) tackles ${tackled.id} (balance: ${tackledBalance}) - ${success ? 'SUCCESS' : 'FAILED'} (${(successChance * 100).toFixed(1)}%)` ); // Mark tackle performed (cooldown starts)