particles/Particle.cs

49 lines
1.1 KiB
C#
Raw Normal View History

2021-12-26 15:56:57 -05:00
using Godot;
public class Particle : Node2D
{
private Sprite _spriteNode;
2021-12-27 14:58:33 -05:00
private Label _labelNode;
2021-12-26 16:45:02 -05:00
private ParticleType _type;
2021-12-27 14:58:33 -05:00
private float _health = 0f;
private float _averageSpeed = 1f;
2021-12-26 21:16:28 -05:00
public Vector2 Velocity { get; set; }
2021-12-27 14:58:33 -05:00
public float AverageSpeed { get => _averageSpeed; }
public float Health
{
get => _health;
set
{
_health = Mathf.Clamp(value, 0f, 1f);
_spriteNode.Modulate = Color.FromHsv(_type.Hue, Health, 1);
}
}
2021-12-26 21:16:28 -05:00
2021-12-26 16:45:02 -05:00
public ParticleType Type
2021-12-26 15:56:57 -05:00
{
2021-12-26 16:45:02 -05:00
get => _type;
2021-12-26 15:56:57 -05:00
set
{
2021-12-26 16:45:02 -05:00
_type = value;
2021-12-27 14:58:33 -05:00
_spriteNode.Modulate = Color.FromHsv(_type.Hue, Health, 1);
2021-12-26 15:56:57 -05:00
}
}
public override void _Ready()
{
_spriteNode = GetNode<Sprite>("Sprite");
2021-12-27 14:58:33 -05:00
_labelNode = GetNode<Label>("Label");
}
public void AddAverageSpeedValue(float speed)
{
_averageSpeed = (0.99f * _averageSpeed) + (0.01f * speed);
}
public void SetLabelText(string text)
{
_labelNode.Text = text;
2021-12-26 15:56:57 -05:00
}
}