Plants now based on entity class
This commit is contained in:
parent
6c9909df30
commit
08d593175b
14 changed files with 38 additions and 65 deletions
|
|
@ -84,6 +84,8 @@ graph_offset = Vector2(-78.082, -71.7578)
|
|||
size = Vector2(22, 32)
|
||||
|
||||
[node name="Aloe" instance=ExtResource("1_n25yi")]
|
||||
MaxHP = 30.0
|
||||
_effectImmunities = Array[Resource]([])
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
position = Vector2(9, -14)
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ blend_mode = 1
|
|||
size = Vector2(32, 29)
|
||||
|
||||
[node name="Garlic" instance=ExtResource("1_5i0e6")]
|
||||
_maxHP = 200
|
||||
MaxHP = 200.0
|
||||
_effectImmunities = Array[Resource]([])
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("2_w2jbi")
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ resource_local_to_scene = true
|
|||
size = Vector2(20, 44)
|
||||
|
||||
[node name="Peashooter" instance=ExtResource("1_pyk3o")]
|
||||
MaxHP = 30.0
|
||||
_effectImmunities = Array[Resource]([])
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("2_14qlx")
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ size = Vector2(15, 27)
|
|||
size = Vector2(34, 19)
|
||||
|
||||
[node name="Potato mine" instance=ExtResource("1_dj7ul")]
|
||||
_maxHP = 20
|
||||
MaxHP = 20.0
|
||||
_effectImmunities = Array[Resource]([])
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("2_sneas")
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ blend_mode = 1
|
|||
size = Vector2(49, 38)
|
||||
|
||||
[node name="Spikeweed" instance=ExtResource("1_vmbvr")]
|
||||
MaxHP = 30.0
|
||||
_effectImmunities = Array[Resource]([])
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("2_ffrjr")
|
||||
|
|
|
|||
|
|
@ -55,13 +55,14 @@ transitions = ["Start", "sunflower_idle", SubResource("AnimationNodeStateMachine
|
|||
size = Vector2(26, 48)
|
||||
|
||||
[node name="Sunflower" instance=ExtResource("1_bikjn")]
|
||||
_maxHP = 30
|
||||
MaxHP = 30.0
|
||||
_effectImmunities = Array[Resource]([])
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("2_fwcda")
|
||||
hframes = 9
|
||||
vframes = 2
|
||||
frame = 1
|
||||
frame = 4
|
||||
|
||||
[node name="AnimationPlayer" parent="." index="1"]
|
||||
libraries = {
|
||||
|
|
|
|||
|
|
@ -28,12 +28,14 @@ blend_mode = 1
|
|||
size = Vector2(33, 46)
|
||||
|
||||
[node name="Wallnut" instance=ExtResource("1_fluxn")]
|
||||
_maxHP = 600
|
||||
MaxHP = 600.0
|
||||
_effectImmunities = Array[Resource]([])
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("2_o5tda")
|
||||
hframes = 12
|
||||
vframes = 3
|
||||
frame = 3
|
||||
|
||||
[node name="AnimationPlayer" parent="." index="1"]
|
||||
libraries = {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public partial class Entity : Node2D
|
|||
EmitSignal(SignalName.OnDamaged);
|
||||
if (HP <= 0)
|
||||
{
|
||||
Kill();
|
||||
KillByDamage();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,6 +29,11 @@ public partial class Entity : Node2D
|
|||
HP += amount;
|
||||
}
|
||||
|
||||
public virtual void KillByDamage()
|
||||
{
|
||||
Kill();
|
||||
}
|
||||
|
||||
public virtual void Kill()
|
||||
{
|
||||
QueueFree();
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@ public partial class PoolContainer : Node2D
|
|||
|
||||
public static PoolContainer Instance { get; private set; }
|
||||
|
||||
public Dictionary<Vector2, IEntity>[] EntityField = { new(), new(), new() };
|
||||
public Dictionary<Vector2, Entity>[] EntityField = { new(), new(), new() };
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
public bool TryGetEntity(Vector2 key, out IEntity result, int layer = 1)
|
||||
public bool TryGetEntity(Vector2 key, out Entity result, int layer = 1)
|
||||
{
|
||||
if (EntityField[layer].ContainsKey(key))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ namespace Newlon.Components.Plants;
|
|||
|
||||
public partial class LoseZone : RuntimePlantData
|
||||
{
|
||||
public override void TakeDamage(int amount, Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL)
|
||||
{
|
||||
public override void TakeDamage(float amount, Node origin)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void Kill()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public partial class ReturnEffect : Node
|
|||
|
||||
public void OnDamageRecieved(int delta,Node origin)
|
||||
{
|
||||
if (delta >= 0) return;
|
||||
if (origin is RuntimeZombieData zombie)
|
||||
{
|
||||
zombie.GiveEffect(_effectToReturn);
|
||||
|
|
|
|||
|
|
@ -7,64 +7,19 @@ namespace Newlon.Components.Plants;
|
|||
// Data that plant stores during runtime
|
||||
//
|
||||
|
||||
public partial class RuntimePlantData : Node2D, IEntity
|
||||
public partial class RuntimePlantData : Entity
|
||||
{
|
||||
[Export]
|
||||
private int _maxHP;
|
||||
private int _hp;
|
||||
public int Hp => _hp;
|
||||
public int MaxHp => _maxHP;
|
||||
public int Line { get; set; }
|
||||
public PlantResource Resource;
|
||||
|
||||
private AudioStream eatenSound;
|
||||
|
||||
[Signal]
|
||||
public delegate void OnHPChangedEventHandler(int amount, Node origin);
|
||||
|
||||
public override void _Ready()
|
||||
private AudioStream eatenSound = ResourceLoader.Load<AudioStream>("res://assets/audio/sfx/gulp.mp3");
|
||||
public override void KillByDamage()
|
||||
{
|
||||
_hp = _maxHP;
|
||||
eatenSound = ResourceLoader.Load<AudioStream>("res://assets/audio/sfx/gulp.mp3");
|
||||
AudioSequencer.Play("plant_eaten", eatenSound);
|
||||
base.KillByDamage();
|
||||
}
|
||||
|
||||
public virtual void Heal(int amount, Node origin)
|
||||
{
|
||||
_hp += amount;
|
||||
|
||||
EmitSignal(SignalName.OnHPChanged, amount, origin);
|
||||
|
||||
if (MaxHp > 0)
|
||||
{
|
||||
_hp = MaxHp;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void TakeDamage(int amount, Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL)
|
||||
{
|
||||
_hp -= amount;
|
||||
|
||||
EmitSignal(SignalName.OnHPChanged, -amount, origin);
|
||||
|
||||
if (_hp <= 0)
|
||||
{
|
||||
Kill();
|
||||
AudioSequencer.Play("plant_eaten", eatenSound);
|
||||
}
|
||||
}
|
||||
public virtual void Kill()
|
||||
public override void Kill()
|
||||
{
|
||||
PoolContainer.Instance.EntityField[Resource.Layer].Remove(GlobalPosition);
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
public virtual void DisableBrain()
|
||||
{
|
||||
GetNode<Node>("Behaviour").ProcessMode = ProcessModeEnum.Disabled;
|
||||
}
|
||||
|
||||
public virtual void EnableBrain()
|
||||
{
|
||||
GetNode<Node>("Behaviour").ProcessMode = ProcessModeEnum.Inherit;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public partial class AloeBehaviour : BaseBehaviour
|
|||
var checkPos = GetParent<Node2D>().GlobalPosition + Vector2.Right * Utility.TileWidth;
|
||||
if(_charge && PoolContainer.Instance.TryGetEntity(checkPos, out RuntimePlantData plantData))
|
||||
{
|
||||
if((float)plantData.Hp / (float)plantData.MaxHp < _hpTreshold)
|
||||
if((float)plantData.HP / (float)plantData.MaxHP < _hpTreshold)
|
||||
{
|
||||
_charge = false;
|
||||
_tree.Set("parameters/conditions/heal",true);
|
||||
|
|
@ -36,7 +36,7 @@ public partial class AloeBehaviour : BaseBehaviour
|
|||
var checkPos = GetParent<Node2D>().GlobalPosition + Vector2.Right * Utility.TileWidth;
|
||||
if (PoolContainer.Instance.TryGetEntity(checkPos, out RuntimePlantData plantData))
|
||||
{
|
||||
plantData.Heal(3000 + 25 * plantData.MaxHp, GetParent());
|
||||
plantData.Heal(3000 + 25 * plantData.MaxHP, GetParent());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,6 @@ public partial class HpBasedBehaviour : BaseBehaviour
|
|||
|
||||
public void OnHPChanged(int amount,Node origin)
|
||||
{
|
||||
_tree.Set("parameters/blend_position",(float)_data.Hp/_data.MaxHp);
|
||||
_tree.Set("parameters/blend_position",(float)_data.HP/_data.MaxHP);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue