using Godot; using System; public partial class GameController : Node { public static GameController Instance; [Export] private float _ShrineStartHP; [Export] private Label _CurrencyLabel; [Export] private Label _ShrineHealthLabel; public int Wave { get; private set; } public int Currency { get; private set; } public float ShrineHealth { get; private set; } private bool _waveOnGoing = false; public override void _Ready() { GameController.Instance = this; Wave = 0; Currency = 300; ShrineHealth = 100; _CurrencyLabel.Text = Currency.ToString(); _ShrineHealthLabel.Text = $"{(100f * (ShrineHealth /_ShrineStartHP)):F1}%"; CallDeferred(nameof(DelayNextWave)); } private void StartWave() { if (_waveOnGoing) return; Wave++; _waveOnGoing = true; int amountToSpawn = (int)Math.Round(5 * Math.Pow(Wave, 1.05)); for (int i = 0; i < 100; i++) { // GD.Print((int)Math.Round(5 * Math.Pow(i + 1, 1.05))); } EnemySpawner.Instance.EnemiesSpawned = amountToSpawn; float baseDelay = 0.67f; float minDelay = 0.12f; // never go below this float delay = Math.Max(minDelay, baseDelay * (float)Math.Pow(0.96f, Wave)); for (int i = 0; i < amountToSpawn; i++) { EnemySpawner.Instance.SpawnWithDelay(i * delay); } } private async void DelayNextWave() { await ToSignal(GetTree().CreateTimer(7.5f), SceneTreeTimer.SignalName.Timeout); CallDeferred(nameof(StartWave)); } public void WaveComplete() { _waveOnGoing = false; CallDeferred(nameof(DelayNextWave)); } public void DamageShrine(float v) { v = Math.Abs(v); ShrineHealth -= v; _ShrineHealthLabel.Text = $"{(100f * (ShrineHealth /_ShrineStartHP)):F1}%"; if (ShrineHealth <= 0) { // TODO LOSE SCENARIO } } public void AddCurrency(int v) { v = Math.Abs(v); Currency += v; _CurrencyLabel.Text = Currency.ToString(); } public bool TryRemoveCurrency(int v) { v = Math.Abs(v); if (Currency < v) return false; Currency -= v; _CurrencyLabel.Text = Currency.ToString(); return true; } }