egrading armor and universal veil
This commit is contained in:
parent
1692477176
commit
29254dbda0
22 changed files with 142 additions and 30 deletions
33
scripts/components/DegradingSprite.cs
Normal file
33
scripts/components/DegradingSprite.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Newlon.Components.Zombies;
|
||||
|
||||
public partial class DegradingSprite : Sprite2D
|
||||
{
|
||||
[Export] private Armor armor;
|
||||
[Export] private Array<Texture2D> degradationStages;
|
||||
[Export] private Array<float> thresholdPercentage;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
armor.ArmorDamaged += OnZombieHPChanged;
|
||||
}
|
||||
|
||||
private void OnZombieHPChanged(int hp)
|
||||
{
|
||||
float percent = (float)hp / (float)armor.MaxHP;
|
||||
for (int i = 0; i < degradationStages.Count; i++)
|
||||
{
|
||||
if (percent <= thresholdPercentage[i])
|
||||
{
|
||||
Texture = degradationStages[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue