remove penalties
This commit is contained in:
parent
961dcc3a25
commit
abe1e2ca54
@ -26,10 +26,6 @@
|
||||
</div>
|
||||
<div id="game-stats">
|
||||
<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 id="controls">
|
||||
|
||||
@ -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', () => {
|
||||
});
|
||||
@ -229,16 +222,6 @@ class GameEngine {
|
||||
duration: 500,
|
||||
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.state.hasPuck = false;
|
||||
player.state.energy = 100;
|
||||
player.state.penaltyTime = 0;
|
||||
player.aiState.lastAction = 0;
|
||||
});
|
||||
|
||||
|
||||
@ -18,14 +18,12 @@ class GameState {
|
||||
shots: 0,
|
||||
saves: 0,
|
||||
hits: 0,
|
||||
penalties: [],
|
||||
faceoffWins: 0
|
||||
},
|
||||
away: {
|
||||
shots: 0,
|
||||
saves: 0,
|
||||
hits: 0,
|
||||
penalties: [],
|
||||
faceoffWins: 0
|
||||
}
|
||||
};
|
||||
@ -52,10 +50,6 @@ class GameState {
|
||||
]
|
||||
};
|
||||
|
||||
this.powerPlay = {
|
||||
home: null,
|
||||
away: null
|
||||
};
|
||||
|
||||
this.faceoff = {
|
||||
isActive: false,
|
||||
@ -91,7 +85,6 @@ class GameState {
|
||||
this.endPeriod();
|
||||
}
|
||||
|
||||
this.updatePenalties(deltaTime);
|
||||
}
|
||||
|
||||
endPeriod() {
|
||||
@ -128,41 +121,7 @@ class GameState {
|
||||
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) {
|
||||
const event = {
|
||||
@ -271,7 +230,6 @@ class GameState {
|
||||
isPaused: this.isPaused,
|
||||
gameSpeed: this.gameSpeed,
|
||||
gameOver: this.gameOver,
|
||||
powerPlay: { ...this.powerPlay },
|
||||
faceoff: { ...this.faceoff }
|
||||
};
|
||||
}
|
||||
|
||||
@ -28,7 +28,6 @@ class Player {
|
||||
hasPuck: false,
|
||||
energy: 100,
|
||||
checking: false,
|
||||
penaltyTime: 0,
|
||||
injured: false
|
||||
};
|
||||
|
||||
@ -45,11 +44,6 @@ class Player {
|
||||
}
|
||||
|
||||
update(deltaTime, gameState, puck, players) {
|
||||
if (this.state.penaltyTime > 0) {
|
||||
this.state.penaltyTime -= deltaTime;
|
||||
return;
|
||||
}
|
||||
|
||||
this.updateEnergy(deltaTime);
|
||||
this.updateMovement(deltaTime);
|
||||
this.updateAngle(deltaTime);
|
||||
|
||||
@ -99,8 +99,6 @@ class Puck {
|
||||
let closestDistance = Infinity;
|
||||
|
||||
players.forEach(player => {
|
||||
if (player.state.penaltyTime > 0) return;
|
||||
|
||||
const distance = this.position.distance(player.position);
|
||||
const collisionDistance = this.radius + player.radius;
|
||||
|
||||
|
||||
@ -84,7 +84,6 @@ class AISystem {
|
||||
gameTime: gameState.timeRemaining,
|
||||
period: gameState.period,
|
||||
scoreGap: gameState.homeScore - gameState.awayScore,
|
||||
powerPlay: gameState.powerPlay,
|
||||
zone: this.determinePuckZone(puck, gameState)
|
||||
};
|
||||
|
||||
@ -104,9 +103,6 @@ class AISystem {
|
||||
}
|
||||
|
||||
selectFormation(context) {
|
||||
if (context.powerPlay.home || context.powerPlay.away) {
|
||||
return context.powerPlay.home ? 'offensive' : 'defensive';
|
||||
}
|
||||
|
||||
switch (context.zone) {
|
||||
case 'offensive':
|
||||
@ -124,7 +120,6 @@ class AISystem {
|
||||
if (context.gameTime < 300) urgency += 0.3;
|
||||
if (context.gameTime < 120) urgency += 0.3;
|
||||
if (Math.abs(context.scoreGap) > 1) urgency += 0.2;
|
||||
if (context.powerPlay.home || context.powerPlay.away) urgency += 0.4;
|
||||
|
||||
return Math.min(1, urgency);
|
||||
}
|
||||
|
||||
@ -142,9 +142,7 @@ class Renderer {
|
||||
this.applyCamera();
|
||||
|
||||
players.forEach(player => {
|
||||
if (player.state.penaltyTime <= 0) {
|
||||
player.render(this.ctx);
|
||||
}
|
||||
});
|
||||
|
||||
this.ctx.restore();
|
||||
@ -160,7 +158,6 @@ class Renderer {
|
||||
drawUI(gameState) {
|
||||
this.updateScoreBoard(gameState);
|
||||
this.updateGameStats(gameState);
|
||||
this.updatePenalties(gameState);
|
||||
}
|
||||
|
||||
updateScoreBoard(gameState) {
|
||||
@ -175,27 +172,6 @@ class Renderer {
|
||||
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') {
|
||||
this.ctx.save();
|
||||
|
||||
@ -3,15 +3,11 @@ class RulesSystem {
|
||||
this.gameState = gameState;
|
||||
this.lastOffsideCheck = 0;
|
||||
this.lastIcingCheck = 0;
|
||||
this.penaltyQueue = [];
|
||||
}
|
||||
|
||||
update(players, puck, deltaTime) {
|
||||
this.checkOffside(players, puck);
|
||||
this.checkIcing(players, puck);
|
||||
this.checkGoaltenderInterference(players, puck);
|
||||
this.checkHighSticking(players, puck);
|
||||
this.processPenaltyQueue();
|
||||
}
|
||||
|
||||
checkOffside(players, puck) {
|
||||
@ -126,81 +122,6 @@ class RulesSystem {
|
||||
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) {
|
||||
setTimeout(() => {
|
||||
@ -223,34 +144,8 @@ class RulesSystem {
|
||||
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() {
|
||||
this.lastOffsideCheck = 0;
|
||||
this.lastIcingCheck = 0;
|
||||
this.penaltyQueue = [];
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user