mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-07 06:45:53 +00:00
Boss HUD
This commit is contained in:
parent
b4fdb9c9e3
commit
4be64cf7ec
12 changed files with 220 additions and 33 deletions
|
|
@ -8,7 +8,9 @@ namespace Cirno.Scripts.Actors;
|
|||
|
||||
public partial class Boss : Enemy, IActivable
|
||||
{
|
||||
[Export] public string BossName { get; private set; }
|
||||
[Export] private Array<BossPhase> Phases;
|
||||
[Export] private PackedScene BossHudPrefab;
|
||||
private int currentPhaseIndex = 0;
|
||||
|
||||
private bool _started = false;
|
||||
|
|
@ -26,6 +28,8 @@ public partial class Boss : Enemy, IActivable
|
|||
|
||||
[Export]
|
||||
private Texture2D _bossPortraitTexture;
|
||||
|
||||
private BossHud _bossHud;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -34,28 +38,45 @@ public partial class Boss : Enemy, IActivable
|
|||
|
||||
_homePosition = this.GlobalPosition;
|
||||
|
||||
if (_bossPortraitTexture is not null)
|
||||
if (BossHudPrefab is not null)
|
||||
{
|
||||
var canvas = new CanvasLayer();
|
||||
canvas.Name = "BossPhaseAnimationCanvas";
|
||||
_bossHud = BossHudPrefab.Instantiate<BossHud>();
|
||||
_gameManager.CallDeferred("add_child", _bossHud);
|
||||
|
||||
_bossHud.BossName = BossName;
|
||||
_bossHud.BossMaxHealth = this.Health;
|
||||
_bossHud.BossHealth = this._currentHealth;
|
||||
_bossHud.SpellCardName = CurrentPhase.PhaseName;
|
||||
|
||||
// TODO: Do some translation for health values to match the thresholds
|
||||
this.HealthChanged += (float newValue) => {_bossHud.BossHealth = newValue;};
|
||||
|
||||
if (_bossPortraitTexture is not null)
|
||||
{
|
||||
// var canvas = new CanvasLayer();
|
||||
// canvas.Name = "BossPhaseAnimationCanvas";
|
||||
|
||||
_gameManager.CallDeferred("add_child", canvas);
|
||||
// _gameManager.CallDeferred("add_child", canvas);
|
||||
|
||||
_animationTextureRect = new TextureRect();
|
||||
_animationTextureRect.Texture = _bossPortraitTexture;
|
||||
_animationTextureRect = new TextureRect();
|
||||
_animationTextureRect.Texture = _bossPortraitTexture;
|
||||
|
||||
canvas.CallDeferred("add_child", _animationTextureRect);
|
||||
_bossHud.CallDeferred("add_child", _animationTextureRect);
|
||||
|
||||
//canvas.AddChild(animationTextureRect);
|
||||
//canvas.AddChild(animationTextureRect);
|
||||
|
||||
_animationTextureRect.Position = new Vector2(180, 10);
|
||||
_animationTextureRect.Position = new Vector2(180, 10);
|
||||
|
||||
_animationTextureRect.Visible = false;
|
||||
_animationTextureRect.Visible = false;
|
||||
|
||||
//var animation = _bossPhaseAnimationPrefab.Instantiate<BossPhaseAnimation>();
|
||||
//var animation = _bossPhaseAnimationPrefab.Instantiate<BossPhaseAnimation>();
|
||||
|
||||
// _gameManager.AddChild(animation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
|
|
@ -68,6 +89,7 @@ public partial class Boss : Enemy, IActivable
|
|||
if (_currentHealth <= CurrentPhase.Threshold && currentPhaseIndex + 1 < Phases.Count)
|
||||
{
|
||||
currentPhaseIndex++;
|
||||
_bossHud.SpellCardName = CurrentPhase.PhaseName;
|
||||
StartPhase(CurrentPhase);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,13 @@ public partial class Enemy : CharacterBody2D
|
|||
set => _navigationEnabled = value;
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
[Signal]
|
||||
public delegate void HealthChangedEventHandler(float newValue);
|
||||
|
||||
#endregion
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -220,6 +227,7 @@ public partial class Enemy : CharacterBody2D
|
|||
if (_isDestroyed) return;
|
||||
|
||||
_currentHealth -= damage;
|
||||
EmitSignal(nameof(HealthChanged), _currentHealth);
|
||||
if (!(_currentHealth <= 0)) return;
|
||||
_isDestroyed = true;
|
||||
Explode();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ namespace Cirno.Scripts.Resources;
|
|||
[GlobalClass]
|
||||
public partial class BossPhase : Resource
|
||||
{
|
||||
[Export] public string PhaseName = string.Empty;
|
||||
[Export] public int Threshold;
|
||||
[Export] public bool PlayAnimation;
|
||||
[Export] public Array<AttackPattern> Patterns;
|
||||
|
|
|
|||
54
Scripts/UI/BossHud.cs
Normal file
54
Scripts/UI/BossHud.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.UI;
|
||||
|
||||
public partial class BossHud : CanvasLayer
|
||||
{
|
||||
[Export] public Label BossNameLabel { get; set; }
|
||||
[Export] public Label SpellCardNameLabel { get; set; }
|
||||
[Export] public Label SpellCardsCountLabel { get; set; }
|
||||
[Export] public Label SpellCardTimerLabel { get; set; }
|
||||
[Export] public ProgressBar BossHealthBar { get; set; }
|
||||
|
||||
public string BossName
|
||||
{
|
||||
get => BossNameLabel.Text;
|
||||
set => BossNameLabel.Text = value;
|
||||
}
|
||||
|
||||
public string SpellCardName
|
||||
{
|
||||
get => SpellCardNameLabel.Text;
|
||||
set => SpellCardNameLabel.Text = value;
|
||||
}
|
||||
|
||||
public string SpellCardsCount
|
||||
{
|
||||
get => SpellCardsCountLabel.Text;
|
||||
set => SpellCardsCountLabel.Text = value;
|
||||
}
|
||||
|
||||
public string SpellCardTimer
|
||||
{
|
||||
get => SpellCardTimerLabel.Text;
|
||||
set => SpellCardTimerLabel.Text = value;
|
||||
}
|
||||
|
||||
public double BossHealth
|
||||
{
|
||||
get => BossHealthBar.Value;
|
||||
set => BossHealthBar.Value = value;
|
||||
}
|
||||
|
||||
public double BossMaxHealth
|
||||
{
|
||||
get => BossHealthBar.MaxValue;
|
||||
set => BossHealthBar.MaxValue = value;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue