Zombie flash
This commit is contained in:
parent
b543631c86
commit
eb2159811e
4 changed files with 73 additions and 2 deletions
34
scripts/components/FlashComponent.cs
Normal file
34
scripts/components/FlashComponent.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class FlashComponent : CanvasGroup
|
||||
{
|
||||
[Export] private float _flashDuration = 0.1f;
|
||||
private Tween _tween;
|
||||
private ShaderMaterial _shaderMaterial;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_shaderMaterial = Material as ShaderMaterial;
|
||||
}
|
||||
|
||||
public void DamageFlash(int damage)
|
||||
{
|
||||
Flash();
|
||||
}
|
||||
|
||||
|
||||
public void Flash()
|
||||
{
|
||||
_tween?.Kill();
|
||||
_tween = CreateTween();
|
||||
|
||||
Action<float> action = SetAmount;
|
||||
_tween.TweenMethod(Callable.From(action),1.0f,0.0f,_flashDuration);
|
||||
}
|
||||
|
||||
private void SetAmount(float amount)
|
||||
{
|
||||
_shaderMaterial.SetShaderParameter("amount",amount);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,9 @@ using System;
|
|||
|
||||
public partial class RuntimeZombieData : Node2D, IEntity
|
||||
{
|
||||
[Signal]
|
||||
public delegate void OnHPChangedEventHandler(int deltaHP);
|
||||
|
||||
private int _hp;
|
||||
[Export]
|
||||
private int _maxHP;
|
||||
|
|
@ -22,6 +25,7 @@ public partial class RuntimeZombieData : Node2D, IEntity
|
|||
public void Heal(int amount)
|
||||
{
|
||||
_hp += amount;
|
||||
EmitSignal(SignalName.OnHPChanged,amount);
|
||||
|
||||
if (MaxHp > 0)
|
||||
{
|
||||
|
|
@ -32,10 +36,12 @@ public partial class RuntimeZombieData : Node2D, IEntity
|
|||
public void TakeDamage(int amount)
|
||||
{
|
||||
_hp -= amount;
|
||||
EmitSignal(SignalName.OnHPChanged,-amount);
|
||||
|
||||
if (_hp <= 0)
|
||||
{
|
||||
QueueFree();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue