remove penalties

This commit is contained in:
Pierre Wessman 2025-09-16 13:08:41 +02:00
parent 961dcc3a25
commit abe1e2ca54
8 changed files with 1 additions and 207 deletions

View File

@ -26,10 +26,6 @@
</div> </div>
<div id="game-stats"> <div id="game-stats">
<div id="shots">Shots: <span id="home-shots">0</span> - <span id="away-shots">0</span></div> <div id="shots">Shots: <span id="home-shots">0</span> - <span id="away-shots">0</span></div>
<div id="penalties">
<div id="home-penalties"></div>
<div id="away-penalties"></div>
</div>
</div> </div>
</div> </div>
<div id="controls"> <div id="controls">

View File

@ -90,13 +90,6 @@ class GameEngine {
}); });
this.gameState.on('penalty', (data) => {
const penalizedPlayer = this.players.find(p => p.name === data.player);
if (penalizedPlayer) {
penalizedPlayer.state.penaltyTime = data.duration;
}
});
this.gameState.on('period-end', () => { this.gameState.on('period-end', () => {
}); });
@ -229,16 +222,6 @@ class GameEngine {
duration: 500, duration: 500,
startTime: Date.now() startTime: Date.now()
}); });
if (Math.random() < 0.1) {
const penalizedPlayer = speed1 > speed2 ? player1 : player2;
this.gameState.addPenalty(
penalizedPlayer.team,
penalizedPlayer.name,
'Checking',
120
);
}
} }
} }
@ -304,7 +287,6 @@ class GameEngine {
player.velocity = new Vector2(0, 0); player.velocity = new Vector2(0, 0);
player.state.hasPuck = false; player.state.hasPuck = false;
player.state.energy = 100; player.state.energy = 100;
player.state.penaltyTime = 0;
player.aiState.lastAction = 0; player.aiState.lastAction = 0;
}); });

View File

@ -18,14 +18,12 @@ class GameState {
shots: 0, shots: 0,
saves: 0, saves: 0,
hits: 0, hits: 0,
penalties: [],
faceoffWins: 0 faceoffWins: 0
}, },
away: { away: {
shots: 0, shots: 0,
saves: 0, saves: 0,
hits: 0, hits: 0,
penalties: [],
faceoffWins: 0 faceoffWins: 0
} }
}; };
@ -52,10 +50,6 @@ class GameState {
] ]
}; };
this.powerPlay = {
home: null,
away: null
};
this.faceoff = { this.faceoff = {
isActive: false, isActive: false,
@ -91,7 +85,6 @@ class GameState {
this.endPeriod(); this.endPeriod();
} }
this.updatePenalties(deltaTime);
} }
endPeriod() { endPeriod() {
@ -128,41 +121,7 @@ class GameState {
this.emit('save', { team, saves: this.stats[team].saves }); this.emit('save', { team, saves: this.stats[team].saves });
} }
addPenalty(team, player, type, duration = 120) {
const penalty = {
player,
type,
duration,
timeRemaining: duration
};
this.stats[team].penalties.push(penalty);
this.addEvent(`PENALTY - ${team.toUpperCase()} ${player}: ${type}`);
const oppositeTeam = team === 'home' ? 'away' : 'home';
this.powerPlay[oppositeTeam] = Date.now() + (duration * 1000);
this.emit('penalty', { team, player, type, duration });
}
updatePenalties(deltaTime) {
['home', 'away'].forEach(team => {
this.stats[team].penalties = this.stats[team].penalties.filter(penalty => {
penalty.timeRemaining -= deltaTime * this.gameSpeed;
if (penalty.timeRemaining <= 0) {
this.emit('penalty-expired', { team, penalty });
return false;
}
return true;
});
});
['home', 'away'].forEach(team => {
if (this.powerPlay[team] && Date.now() > this.powerPlay[team]) {
this.powerPlay[team] = null;
}
});
}
addEvent(description) { addEvent(description) {
const event = { const event = {
@ -271,7 +230,6 @@ class GameState {
isPaused: this.isPaused, isPaused: this.isPaused,
gameSpeed: this.gameSpeed, gameSpeed: this.gameSpeed,
gameOver: this.gameOver, gameOver: this.gameOver,
powerPlay: { ...this.powerPlay },
faceoff: { ...this.faceoff } faceoff: { ...this.faceoff }
}; };
} }

View File

@ -28,7 +28,6 @@ class Player {
hasPuck: false, hasPuck: false,
energy: 100, energy: 100,
checking: false, checking: false,
penaltyTime: 0,
injured: false injured: false
}; };
@ -45,11 +44,6 @@ class Player {
} }
update(deltaTime, gameState, puck, players) { update(deltaTime, gameState, puck, players) {
if (this.state.penaltyTime > 0) {
this.state.penaltyTime -= deltaTime;
return;
}
this.updateEnergy(deltaTime); this.updateEnergy(deltaTime);
this.updateMovement(deltaTime); this.updateMovement(deltaTime);
this.updateAngle(deltaTime); this.updateAngle(deltaTime);

View File

@ -99,8 +99,6 @@ class Puck {
let closestDistance = Infinity; let closestDistance = Infinity;
players.forEach(player => { players.forEach(player => {
if (player.state.penaltyTime > 0) return;
const distance = this.position.distance(player.position); const distance = this.position.distance(player.position);
const collisionDistance = this.radius + player.radius; const collisionDistance = this.radius + player.radius;

View File

@ -84,7 +84,6 @@ class AISystem {
gameTime: gameState.timeRemaining, gameTime: gameState.timeRemaining,
period: gameState.period, period: gameState.period,
scoreGap: gameState.homeScore - gameState.awayScore, scoreGap: gameState.homeScore - gameState.awayScore,
powerPlay: gameState.powerPlay,
zone: this.determinePuckZone(puck, gameState) zone: this.determinePuckZone(puck, gameState)
}; };
@ -104,9 +103,6 @@ class AISystem {
} }
selectFormation(context) { selectFormation(context) {
if (context.powerPlay.home || context.powerPlay.away) {
return context.powerPlay.home ? 'offensive' : 'defensive';
}
switch (context.zone) { switch (context.zone) {
case 'offensive': case 'offensive':
@ -124,7 +120,6 @@ class AISystem {
if (context.gameTime < 300) urgency += 0.3; if (context.gameTime < 300) urgency += 0.3;
if (context.gameTime < 120) urgency += 0.3; if (context.gameTime < 120) urgency += 0.3;
if (Math.abs(context.scoreGap) > 1) urgency += 0.2; if (Math.abs(context.scoreGap) > 1) urgency += 0.2;
if (context.powerPlay.home || context.powerPlay.away) urgency += 0.4;
return Math.min(1, urgency); return Math.min(1, urgency);
} }

View File

@ -142,9 +142,7 @@ class Renderer {
this.applyCamera(); this.applyCamera();
players.forEach(player => { players.forEach(player => {
if (player.state.penaltyTime <= 0) {
player.render(this.ctx); player.render(this.ctx);
}
}); });
this.ctx.restore(); this.ctx.restore();
@ -160,7 +158,6 @@ class Renderer {
drawUI(gameState) { drawUI(gameState) {
this.updateScoreBoard(gameState); this.updateScoreBoard(gameState);
this.updateGameStats(gameState); this.updateGameStats(gameState);
this.updatePenalties(gameState);
} }
updateScoreBoard(gameState) { updateScoreBoard(gameState) {
@ -175,27 +172,6 @@ class Renderer {
document.getElementById('away-shots').textContent = gameState.stats.away.shots; document.getElementById('away-shots').textContent = gameState.stats.away.shots;
} }
updatePenalties(gameState) {
const homePenalties = document.getElementById('home-penalties');
const awayPenalties = document.getElementById('away-penalties');
homePenalties.innerHTML = '';
awayPenalties.innerHTML = '';
gameState.stats.home.penalties.forEach(penalty => {
const penaltyDiv = document.createElement('div');
penaltyDiv.className = 'penalty-box';
penaltyDiv.textContent = `${penalty.player}: ${penalty.type} (${Math.ceil(penalty.timeRemaining)}s)`;
homePenalties.appendChild(penaltyDiv);
});
gameState.stats.away.penalties.forEach(penalty => {
const penaltyDiv = document.createElement('div');
penaltyDiv.className = 'penalty-box';
penaltyDiv.textContent = `${penalty.player}: ${penalty.type} (${Math.ceil(penalty.timeRemaining)}s)`;
awayPenalties.appendChild(penaltyDiv);
});
}
drawParticleEffect(position, type, color = '#ffff00') { drawParticleEffect(position, type, color = '#ffff00') {
this.ctx.save(); this.ctx.save();

View File

@ -3,15 +3,11 @@ class RulesSystem {
this.gameState = gameState; this.gameState = gameState;
this.lastOffsideCheck = 0; this.lastOffsideCheck = 0;
this.lastIcingCheck = 0; this.lastIcingCheck = 0;
this.penaltyQueue = [];
} }
update(players, puck, deltaTime) { update(players, puck, deltaTime) {
this.checkOffside(players, puck); this.checkOffside(players, puck);
this.checkIcing(players, puck); this.checkIcing(players, puck);
this.checkGoaltenderInterference(players, puck);
this.checkHighSticking(players, puck);
this.processPenaltyQueue();
} }
checkOffside(players, puck) { checkOffside(players, puck) {
@ -126,81 +122,6 @@ class RulesSystem {
this.scheduleFaceoff(faceoffPosition); this.scheduleFaceoff(faceoffPosition);
} }
checkGoaltenderInterference(players, puck) {
const goalies = players.filter(p => p.role === 'G');
goalies.forEach(goalie => {
const crease = this.getCreaseArea(goalie.team);
const opponents = players.filter(p =>
p.team !== goalie.team &&
this.isPlayerInCrease(p, crease)
);
opponents.forEach(opponent => {
if (opponent.velocity.magnitude() > 100) {
this.callGoaltenderInterference(opponent);
}
});
});
}
checkHighSticking(players, puck) {
if (puck.position.y < 200) {
const lastTouch = puck.lastPlayerTouch;
if (lastTouch && Math.random() < 0.1) {
this.callHighSticking(lastTouch);
}
}
}
isPlayerInCrease(player, crease) {
return player.position.x >= crease.x &&
player.position.x <= crease.x + crease.width &&
player.position.y >= crease.y &&
player.position.y <= crease.y + crease.height;
}
getCreaseArea(team) {
const goalY = this.gameState.rink.centerY;
const goalX = team === 'home' ? 50 : this.gameState.rink.width - 50;
return {
x: goalX - 30,
y: goalY - 60,
width: 60,
height: 120
};
}
callGoaltenderInterference(player) {
this.queuePenalty(player.team, player.name, 'Goaltender Interference', 120);
}
callHighSticking(player) {
this.queuePenalty(player.team, player.name, 'High Sticking', 120);
}
queuePenalty(team, player, type, duration) {
this.penaltyQueue.push({
team,
player,
type,
duration,
timestamp: Date.now()
});
}
processPenaltyQueue() {
if (this.penaltyQueue.length === 0) return;
const penalty = this.penaltyQueue.shift();
this.gameState.addPenalty(
penalty.team,
penalty.player,
penalty.type,
penalty.duration
);
}
scheduleFaceoff(position) { scheduleFaceoff(position) {
setTimeout(() => { setTimeout(() => {
@ -223,34 +144,8 @@ class RulesSystem {
return nearest; return nearest;
} }
checkFighting(players) {
for (let i = 0; i < players.length; i++) {
for (let j = i + 1; j < players.length; j++) {
const player1 = players[i];
const player2 = players[j];
if (player1.team !== player2.team &&
player1.position.distance(player2.position) < 20 &&
player1.velocity.magnitude() > 150 &&
player2.velocity.magnitude() > 150 &&
Math.random() < 0.01) {
this.callFighting(player1, player2);
}
}
}
}
callFighting(player1, player2) {
this.queuePenalty(player1.team, player1.name, 'Fighting', 300);
this.queuePenalty(player2.team, player2.name, 'Fighting', 300);
this.gameState.addEvent(`FIGHT - ${player1.name} vs ${player2.name}`);
}
reset() { reset() {
this.lastOffsideCheck = 0; this.lastOffsideCheck = 0;
this.lastIcingCheck = 0; this.lastIcingCheck = 0;
this.penaltyQueue = [];
} }
} }