45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using Godot;
|
|
using Newlon.Components.Plants;
|
|
|
|
|
|
namespace Newlon.Components.Zombies;
|
|
|
|
public partial class EatBox : Area2D
|
|
{
|
|
// Rewrite this class completely when field system will be introduced.
|
|
|
|
[Export] private int _damage;
|
|
[Export] private AnimationTree _animationTree;
|
|
private RuntimePlantData plant;
|
|
|
|
|
|
public void Bite()
|
|
{
|
|
if (GetParent<RuntimeZombieData>().AbleToEat)
|
|
plant?.TakeDamage(_damage,GetParent());
|
|
}
|
|
|
|
public void OnAreaEntered(Area2D area)
|
|
{
|
|
var parent = area.GetParent();
|
|
|
|
if (parent != null && parent is RuntimePlantData plantData)
|
|
{
|
|
plant = plantData;
|
|
_animationTree.Set("parameters/conditions/eat", true);
|
|
_animationTree.Set("parameters/conditions/end_eat", false);
|
|
}
|
|
}
|
|
|
|
public void OnAreaExited(Area2D area)
|
|
{
|
|
var parent = area.GetParent();
|
|
|
|
if (parent == plant)
|
|
{
|
|
plant = null;
|
|
_animationTree.Set("parameters/conditions/eat", false);
|
|
_animationTree.Set("parameters/conditions/end_eat", true);
|
|
}
|
|
}
|
|
}
|