feat: add bark battle browser prototype
This commit is contained in:
20
src/games/bark-battle/domain/EnergyTugOfWar.ts
Normal file
20
src/games/bark-battle/domain/EnergyTugOfWar.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export type AdvanceEnergyInput = {
|
||||
energy: number;
|
||||
playerPower: number;
|
||||
opponentPower: number;
|
||||
deltaMs: number;
|
||||
balanceFactor: number;
|
||||
};
|
||||
|
||||
export function advanceEnergy(input: AdvanceEnergyInput) {
|
||||
const deltaSeconds = Math.max(0, input.deltaMs) / 1000;
|
||||
const powerDelta = input.playerPower - input.opponentPower;
|
||||
return clampEnergy(input.energy + powerDelta * input.balanceFactor * deltaSeconds);
|
||||
}
|
||||
|
||||
export function clampEnergy(value: number) {
|
||||
if (!Number.isFinite(value)) {
|
||||
return 0;
|
||||
}
|
||||
return Math.min(100, Math.max(-100, value));
|
||||
}
|
||||
Reference in New Issue
Block a user