using Godot;
using static ld48.Extensions;

public class Heart : Node2D {
    [Export] private int index;

    private Sprite fillSprite;

    public override void _Ready() {
        base._Ready();

        fillSprite = GetNode<Sprite>("Fill");
        Position = V2(80f + index * 70f, 80f);
    }

    public override void _Process(float delta) {
        base._Process(delta);

        // Visible = Hero.hp >= index;
        var fill = (Hero.hp - index).Clamp(0f, 1f);
        var offset = Mathf.Lerp(0f, 32f, fill);
        fillSprite.RegionRect = new Rect2(0f, 32f-offset, 32f, offset);
        fillSprite.Position = V2(0f, (32f-offset)/2f);
    }
}

