mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 00:26:04 +00:00
Added regeneration
This commit is contained in:
28
assets/Scripts/Game/Unit/Player/PlayerRegeneration.ts
Normal file
28
assets/Scripts/Game/Unit/Player/PlayerRegeneration.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { GameTimer } from "../../../Services/GameTimer";
|
||||
import { UnitHealth } from "../UnitHealth";
|
||||
|
||||
export class PlayerRegeneration {
|
||||
private currentRegenerationAmount = 0;
|
||||
private regenerationDelay: number;
|
||||
private regenerationTimer: GameTimer = new GameTimer(0);
|
||||
private health: UnitHealth;
|
||||
|
||||
public constructor(health: UnitHealth, regenerationDelay: number) {
|
||||
this.health = health;
|
||||
this.regenerationDelay = regenerationDelay;
|
||||
}
|
||||
|
||||
public upgrade(): void {
|
||||
this.currentRegenerationAmount++;
|
||||
this.regenerationTimer = new GameTimer(this.regenerationDelay / this.currentRegenerationAmount);
|
||||
}
|
||||
|
||||
public gameTick(deltaTime: number): void {
|
||||
if (this.currentRegenerationAmount <= 0) return;
|
||||
|
||||
this.regenerationTimer.gameTick(deltaTime);
|
||||
if (this.regenerationTimer.tryFinishPeriod()) {
|
||||
this.health.heal(1);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user