HUD.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Godot;
  2. public partial class HUD : CanvasLayer
  3. {
  4. [Signal]
  5. public delegate void StartGame();
  6. public void ShowMessage(string text)
  7. {
  8. var messageLabel = GetNode<Label>("MessageLabel");
  9. messageLabel.Text = text;
  10. messageLabel.Show();
  11. GetNode<Timer>("MessageTimer").Start();
  12. }
  13. public async void ShowGameOver()
  14. {
  15. ShowMessage("Game Over");
  16. var messageTimer = GetNode<Timer>("MessageTimer");
  17. await ToSignal(messageTimer, "timeout");
  18. var messageLabel = GetNode<Label>("MessageLabel");
  19. messageLabel.Text = "Dodge the\nCreeps!";
  20. messageLabel.Show();
  21. GetNode<Button>("StartButton").Show();
  22. }
  23. public void UpdateScore(int score)
  24. {
  25. GetNode<Label>("ScoreLabel").Text = score.ToString();
  26. }
  27. public void OnStartButtonPressed()
  28. {
  29. GetNode<Button>("StartButton").Hide();
  30. EmitSignal(nameof(StartGame));
  31. }
  32. public void OnMessageTimerTimeout()
  33. {
  34. GetNode<Label>("MessageLabel").Hide();
  35. }
  36. }