SupaLidlGame/Entities/Campfire.cs

36 lines
971 B
C#
Raw Normal View History

2022-12-04 20:12:34 -08:00
using Godot;
2023-06-10 22:15:28 -07:00
using GodotUtilities;
using SupaLidlGame.BoundingBoxes;
2022-12-04 20:12:34 -08:00
2023-06-03 18:21:46 -07:00
namespace SupaLidlGame.Entities;
2023-06-10 22:15:28 -07:00
[Scene]
public partial class Campfire : StaticBody2D, Utils.IInteractive
2022-12-04 20:12:34 -08:00
{
2023-06-03 18:21:46 -07:00
private PointLight2D _light;
2023-05-30 01:35:29 -07:00
2023-06-10 22:15:28 -07:00
public InteractionTrigger InteractionTrigger { get; set; }
2023-06-03 18:21:46 -07:00
[Signal]
2023-06-10 22:15:28 -07:00
public delegate void UseEventHandler();
2023-05-30 01:35:29 -07:00
2023-06-03 18:21:46 -07:00
public override void _Ready()
{
2023-06-10 22:15:28 -07:00
InteractionTrigger = GetNode<InteractionTrigger>("InteractionTrigger");
2023-06-03 18:21:46 -07:00
_light = GetNode<PointLight2D>("PointLight2D");
2023-06-10 22:15:28 -07:00
InteractionTrigger.Interaction += () =>
{
// save the player's spawn position to be their position on interaction
EmitSignal(SignalName.Use);
this.GetAncestor<Utils.World>().SetSpawn(GlobalPosition);
};
2023-06-03 18:21:46 -07:00
}
2023-05-30 01:35:29 -07:00
2023-06-03 18:21:46 -07:00
public override void _Process(double delta)
{
_light.Energy += (GD.Randf() - 0.5f) * 8 * (float)delta;
2023-06-10 22:15:28 -07:00
_light.Energy = Mathf.Clamp(_light.Energy, 1.8f, 2f);
2022-12-04 20:12:34 -08:00
}
}