Wall-nut
This commit is contained in:
parent
f4caadad99
commit
2c8bb1d652
6 changed files with 199 additions and 15 deletions
|
|
@ -15,6 +15,9 @@ public partial class RuntimePlantData : Node2D, IEntity
|
|||
public int Line {get; set;}
|
||||
public PlantResource Resource;
|
||||
|
||||
[Signal]
|
||||
public delegate void OnHPChangedEventHandler(int amount);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_hp = _maxHP;
|
||||
|
|
@ -24,6 +27,8 @@ public partial class RuntimePlantData : Node2D, IEntity
|
|||
{
|
||||
_hp += amount;
|
||||
|
||||
EmitSignal(SignalName.OnHPChanged,amount);
|
||||
|
||||
if (MaxHp > 0)
|
||||
{
|
||||
_hp = MaxHp;
|
||||
|
|
@ -34,6 +39,8 @@ public partial class RuntimePlantData : Node2D, IEntity
|
|||
{
|
||||
_hp -= amount;
|
||||
|
||||
EmitSignal(SignalName.OnHPChanged,-amount);
|
||||
|
||||
if (_hp <= 0)
|
||||
{
|
||||
Kill();
|
||||
|
|
|
|||
25
scripts/components/plants/behaviours/WallnutBehaviour.cs
Normal file
25
scripts/components/plants/behaviours/WallnutBehaviour.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class WallnutBehaviour : Node
|
||||
{
|
||||
private AnimationPlayer _player;
|
||||
private RuntimePlantData _data;
|
||||
public override void _Ready()
|
||||
{
|
||||
_player = GetNode<AnimationPlayer>("../AnimationPlayer");
|
||||
_data = GetParent<RuntimePlantData>();
|
||||
}
|
||||
|
||||
public void OnHPChanged(int amount)
|
||||
{
|
||||
if(_data.Hp <= _data.MaxHp*2.0/3.0 && _data.Hp > _data.MaxHp/3.0)
|
||||
{
|
||||
_player.Play("idle_mid");
|
||||
}
|
||||
else if(_data.Hp < _data.MaxHp/3.0)
|
||||
{
|
||||
_player.Play("idle_low");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue