Effect system and snowpea
This commit is contained in:
parent
9b89ae98a6
commit
e797918e23
18 changed files with 353 additions and 16 deletions
|
|
@ -1,8 +1,10 @@
|
|||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using Newlon.Systems.Effects;
|
||||
|
||||
namespace Newlon.Components.Zombies;
|
||||
|
||||
public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale
|
||||
public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffectHandler
|
||||
{
|
||||
[Signal]
|
||||
public delegate void OnHPChangedEventHandler(int deltaHP);
|
||||
|
|
@ -19,7 +21,7 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale
|
|||
private float _localTimescale = 1.0f;
|
||||
public int Hp => _hp;
|
||||
|
||||
public int MaxHp => _maxHP;
|
||||
public int MaxHp => _maxHP;
|
||||
|
||||
public int Line => _line;
|
||||
|
||||
|
|
@ -36,6 +38,15 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale
|
|||
public override void _Ready()
|
||||
{
|
||||
_hp = _maxHP;
|
||||
|
||||
// Effect timers setup
|
||||
for(int i = 0; i < Utility.EffectSlotCount; i++)
|
||||
{
|
||||
var timer = new Timer() {Autostart = false, OneShot = true};
|
||||
_effectSlotTimers[i] = timer;
|
||||
AddChild(timer);
|
||||
timer.Timeout += () => {EndEffectAtSlot(i);};
|
||||
}
|
||||
}
|
||||
|
||||
public void Heal(int amount)
|
||||
|
|
@ -59,4 +70,44 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale
|
|||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
#region Effects system
|
||||
private readonly Effect[] _activeEffectSlots = new Effect[Utility.EffectSlotCount];
|
||||
private readonly Timer[] _effectSlotTimers = new Timer[Utility.EffectSlotCount];
|
||||
|
||||
// Effect handling
|
||||
|
||||
public void GiveEffect(Effect what)
|
||||
{
|
||||
int slot = (int)what.Slot;
|
||||
if(_activeEffectSlots[slot] != null)
|
||||
{
|
||||
_effectSlotTimers[slot].Stop();
|
||||
_activeEffectSlots[slot].Exit(this);
|
||||
}
|
||||
_effectSlotTimers[slot].WaitTime = what.Duration;
|
||||
_effectSlotTimers[slot].Start();
|
||||
|
||||
what.Enter(this);
|
||||
_activeEffectSlots[slot] = what;
|
||||
}
|
||||
|
||||
public void EndEffect(Effect what)
|
||||
{
|
||||
what.Exit(this);
|
||||
_activeEffectSlots[(int)what.Slot] = null;
|
||||
}
|
||||
|
||||
public void ProcessEffects()
|
||||
{
|
||||
for(int i = 0; i < Utility.EffectSlotCount; i++)
|
||||
_activeEffectSlots[i].Process(this);
|
||||
}
|
||||
|
||||
private void EndEffectAtSlot(int slot)
|
||||
{
|
||||
_activeEffectSlots[slot].Exit(this);
|
||||
_activeEffectSlots[slot] = null;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue