Animations improved
This commit is contained in:
parent
c89d93cf24
commit
ad18793543
35 changed files with 430 additions and 465 deletions
|
|
@ -21,9 +21,37 @@ public partial class PoolContainer : Node
|
|||
|
||||
public static PoolContainer Instance {get; private set;}
|
||||
|
||||
public Dictionary<Vector2, IEntity>[] EntityField = { new Dictionary<Vector2, IEntity>(), new Dictionary<Vector2, IEntity>(), new Dictionary<Vector2, IEntity>() };
|
||||
public Dictionary<Vector2, IEntity>[] EntityField = { new(), new(), new() };
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
public bool TryGetEntity(Vector2 key, out IEntity result, int layer = 1)
|
||||
{
|
||||
if (EntityField[layer].ContainsKey(key))
|
||||
{
|
||||
result = EntityField[layer][key];
|
||||
}
|
||||
else
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
return EntityField[layer].ContainsKey(key)
|
||||
&& EntityField[layer][key] != null;
|
||||
}
|
||||
|
||||
public bool TryGetEntity<T>(Vector2 key, out T result, int layer = 1) where T : class
|
||||
{
|
||||
if (EntityField[layer].ContainsKey(key))
|
||||
{
|
||||
result = EntityField[layer][key] as T;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
return EntityField[layer].ContainsKey(key)
|
||||
&& EntityField[layer][key] != null
|
||||
&& result != null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public partial class RuntimePlantData : Node2D, IEntity
|
|||
{
|
||||
[Export]
|
||||
private int _maxHP;
|
||||
[Export]private int _hp;
|
||||
private int _hp;
|
||||
public int Hp => _hp;
|
||||
public int MaxHp => _maxHP;
|
||||
public int Line {get; set;}
|
||||
|
|
|
|||
|
|
@ -3,40 +3,46 @@ using Newlon.Components.Level;
|
|||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
public partial class AloeBehaviour : Node
|
||||
public partial class AloeBehaviour : BaseBehaviour
|
||||
{
|
||||
[Export] private AnimationPlayer _player;
|
||||
[Export] private float _hpTreshold = 0.25f;
|
||||
private Timer _timer;
|
||||
private bool _charge = true;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_timer = GetNode<Timer>("Timer");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
_tree.Set("parameters/conditions/charged",_charge);
|
||||
|
||||
var checkPos = GetParent<Node2D>().GlobalPosition + Vector2.Right * Utility.TileWidth;
|
||||
if(_charge && PoolContainer.Instance.EntityField[1].ContainsKey(checkPos) && PoolContainer.Instance.EntityField[1][checkPos] is RuntimePlantData plantData)
|
||||
if(_charge && PoolContainer.Instance.TryGetEntity(checkPos, out RuntimePlantData plantData))
|
||||
{
|
||||
if((float)plantData.Hp / (float)plantData.MaxHp < _hpTreshold)
|
||||
{
|
||||
plantData.Heal(3000 + 25 * plantData.MaxHp,GetParent());
|
||||
_charge = false;
|
||||
_player.Play("aloe/heal");
|
||||
_player.Queue("aloe/idle_used");
|
||||
_timer.Start();
|
||||
_tree.Set("parameters/conditions/heal",true);
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Heal()
|
||||
{
|
||||
var checkPos = GetParent<Node2D>().GlobalPosition + Vector2.Right * Utility.TileWidth;
|
||||
if (PoolContainer.Instance.TryGetEntity(checkPos, out RuntimePlantData plantData))
|
||||
{
|
||||
plantData.Heal(3000 + 25 * plantData.MaxHp, GetParent());
|
||||
GD.Print("IM TRYING");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTimeout()
|
||||
{
|
||||
_charge = true;
|
||||
_player.Play("aloe/recharge");
|
||||
_player.Queue("aloe/idle");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
11
scripts/components/plants/behaviours/BaseBehaviour.cs
Normal file
11
scripts/components/plants/behaviours/BaseBehaviour.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public abstract partial class BaseBehaviour : Node
|
||||
{
|
||||
protected AnimationTree _tree;
|
||||
public override void _Ready()
|
||||
{
|
||||
_tree = GetNode<AnimationTree>("../AnimationTree");
|
||||
}
|
||||
}
|
||||
18
scripts/components/plants/behaviours/HpBasedBehaviour.cs
Normal file
18
scripts/components/plants/behaviours/HpBasedBehaviour.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
public partial class HpBasedBehaviour : BaseBehaviour
|
||||
{
|
||||
private RuntimePlantData _data;
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_data = GetParent<RuntimePlantData>();
|
||||
}
|
||||
|
||||
public void OnHPChanged(int amount,Node origin)
|
||||
{
|
||||
_tree.Set("parameters/blend_position",(float)_data.Hp/_data.MaxHp);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,21 +2,15 @@ using Godot;
|
|||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
public partial class PeashooterBehaviour : Node
|
||||
public partial class PeashooterBehaviour : BaseBehaviour
|
||||
{
|
||||
[Export] private AnimationPlayer _player;
|
||||
[Export] private Timer _shootTimer;
|
||||
[Export] private Eyesight _sight;
|
||||
[Export] private string _libName;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
bool readyToShoot = _sight.EnemyDetected && _shootTimer.TimeLeft <= 0;
|
||||
|
||||
if(readyToShoot)
|
||||
{
|
||||
_player.Play(_libName+"/shoot");
|
||||
_player.Queue(_libName+"/idle");
|
||||
}
|
||||
_tree.Set("parameters/conditions/ready",readyToShoot);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,18 +2,15 @@ using Godot;
|
|||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
public partial class PotatomineBehaviour : Node
|
||||
public partial class PotatomineBehaviour : BaseBehaviour
|
||||
{
|
||||
[Export] private AnimationPlayer _player;
|
||||
[Export] private Area2D _hitbox;
|
||||
[Export] private CollisionShape2D _unprimedShape;
|
||||
[Export] private CollisionShape2D _primedShape;
|
||||
|
||||
private bool _primed = false;
|
||||
public void Prime()
|
||||
{
|
||||
_player.Play("prime");
|
||||
_player.Queue("idle_primed");
|
||||
_tree.Set("parameters/conditions/primed",true);
|
||||
|
||||
_hitbox.Monitorable = false;
|
||||
|
||||
|
|
@ -25,6 +22,7 @@ public partial class PotatomineBehaviour : Node
|
|||
public void OnAreaEntered(Area2D area)
|
||||
{
|
||||
if (_primed == false) return;
|
||||
GetNode<Timer>("ExplosionTimer").Start();
|
||||
_tree.Set("parameters/conditions/explode",true);
|
||||
_primed = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,18 +4,18 @@ namespace Newlon.Components.Plants.Behaviours;
|
|||
|
||||
public partial class SpikeweedBehaviour : Node
|
||||
{
|
||||
[Export] private AnimationPlayer _player;
|
||||
[Export] private AnimationTree _tree;
|
||||
|
||||
private int _inCount = 0;
|
||||
public void OnHitboxEntered(Area2D _area)
|
||||
{
|
||||
if (_inCount++ == 0)
|
||||
_player.Play("attack");
|
||||
_tree.Set("parameters/blend_position",1);
|
||||
}
|
||||
|
||||
public void OnHitboxExited(Area2D _area)
|
||||
{
|
||||
if (--_inCount == 0)
|
||||
_player.Play("idle");
|
||||
_tree.Set("parameters/blend_position",0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,17 +4,16 @@ namespace Newlon.Components.Plants.Behaviours;
|
|||
|
||||
public partial class SunflowerBehaviour : Node
|
||||
{
|
||||
private AnimationPlayer _player;
|
||||
private AnimationTree _tree;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_player = GetNode<AnimationPlayer>("../AnimationPlayer");
|
||||
_tree = GetNode<AnimationTree>("../AnimationTree");
|
||||
}
|
||||
|
||||
public void Timeout()
|
||||
{
|
||||
_player.Play("produce");
|
||||
_player.Queue("idle");
|
||||
_tree.Set("parameters/conditions/produce",true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
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");
|
||||
}
|
||||
else
|
||||
{
|
||||
_player.Play("idle_full");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,8 +11,8 @@ public partial class PlantResource : Resource
|
|||
public PackedScene Scene;
|
||||
[Export]
|
||||
public float ReloadTime;
|
||||
[Export]
|
||||
public float StartReloadTime;
|
||||
[Export(PropertyHint.Range,"0,1,0.01")]
|
||||
public float ReloadProgress;
|
||||
[Export]
|
||||
public Texture2D Preview;
|
||||
[Export] public int Layer = 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue