Files
OpenFrontIO/src/client/graphics/layers/SpawnTimer.ts
T
2025-02-01 12:05:11 -08:00

35 lines
900 B
TypeScript

import { GameView } from "../../../core/game/GameView";
import { TransformHandler } from "../TransformHandler";
import { Layer } from "./Layer";
export class SpawnTimer implements Layer {
constructor(
private game: GameView,
private transformHandler: TransformHandler,
) {}
init() {}
tick() {}
shouldTransform(): boolean {
return false;
}
renderLayer(context: CanvasRenderingContext2D) {
if (!this.game.inSpawnPhase()) {
return;
}
const barHeight = 15;
const barBackgroundWidth = this.transformHandler.width();
const ratio = this.game.ticks() / this.game.config().numSpawnPhaseTurns();
// Draw bar background
context.fillStyle = "rgba(0, 0, 0, 0.5)";
context.fillRect(0, 0, barBackgroundWidth, barHeight);
context.fillStyle = "rgba(0, 128, 255, 0.7)";
context.fillRect(0, 0, barBackgroundWidth * ratio, barHeight);
}
}