diff --git a/src/entities/puck.js b/src/entities/puck.js index 8cadc2a..afe04fa 100644 --- a/src/entities/puck.js +++ b/src/entities/puck.js @@ -12,6 +12,9 @@ class Puck { this.bounceCount = 0; this.trail = []; this.maxTrailLength = 10; + + // Collision cooldown tracking + this.goalieCollisionCooldowns = new Map(); // Maps player ID to cooldown end time } update(deltaTime, gameState, players) { @@ -91,6 +94,24 @@ class Puck { } } + isGoalieOnCooldown(goalie) { + const playerId = goalie.id || `${goalie.team}-${goalie.role}`; + const cooldownEnd = this.goalieCollisionCooldowns.get(playerId); + if (cooldownEnd && Date.now() < cooldownEnd) { + return true; + } + // Clean up expired cooldowns + if (cooldownEnd && Date.now() >= cooldownEnd) { + this.goalieCollisionCooldowns.delete(playerId); + } + return false; + } + + setGoalieCooldown(goalie, durationMs = 500) { + const playerId = goalie.id || `${goalie.team}-${goalie.role}`; + this.goalieCollisionCooldowns.set(playerId, Date.now() + durationMs); + } + checkBoardCollisions(gameState) { const rink = gameState.rink; let collision = false; @@ -302,6 +323,11 @@ class Puck { let closestDistance = Infinity; players.forEach(player => { + // Skip goalies who are on collision cooldown + if (player.role === 'G' && this.isGoalieOnCooldown(player)) { + return; + } + const distance = this.position.distance(player.position); const collisionDistance = this.radius + player.radius; @@ -392,10 +418,13 @@ class Puck { difficulty: difficulty }); } else { - console.log("Failed save") + console.log("Failed save - setting collision cooldown") // Failed save - puck continues with reduced velocity (already bounced from collision) // The collision physics have already been applied, so the puck will continue toward the goal this.velocity = this.velocity.multiply(0.8); // Slightly reduce speed but let it continue + + // Set collision cooldown to prevent immediate re-collision with goalie + this.setGoalieCooldown(goalie, 500); // 500ms cooldown } } @@ -417,6 +446,9 @@ class Puck { this.lastTeamTouch = null; this.bounceCount = 0; this.trail = []; + + // Clear all goalie collision cooldowns + this.goalieCollisionCooldowns.clear(); } faceoffDrop(winningTeam, location, participants) {