96 lines
2.4 KiB
C#
96 lines
2.4 KiB
C#
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;
|
|
[Export] private Label _scoreLabel;
|
|
|
|
public int Wave { get; private set; }
|
|
public int Currency { get; private set; }
|
|
public int Score { 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 = _ShrineStartHP;
|
|
|
|
_CurrencyLabel.Text = Currency.ToString();
|
|
_ShrineHealthLabel.Text = $"{(100f * (ShrineHealth /_ShrineStartHP)):F1}%";
|
|
_scoreLabel.Text = "0";
|
|
|
|
CallDeferred(nameof(DelayNextWave));
|
|
}
|
|
|
|
private void StartWave()
|
|
{
|
|
if (_waveOnGoing) return;
|
|
Wave++;
|
|
_waveOnGoing = true;
|
|
|
|
int amountToSpawn = (int)Math.Round(5 * Math.Pow(Wave, 1.025));
|
|
|
|
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)
|
|
{
|
|
SceneManager.Instance.ChangeScene(Scenes.End);
|
|
}
|
|
}
|
|
|
|
public void AddCurrency(int v)
|
|
{
|
|
v = Math.Abs(v);
|
|
Currency += v;
|
|
Score += v;
|
|
_scoreLabel.Text = Score.ToString();
|
|
_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;
|
|
}
|
|
}
|