SupaLidlGame/Entities/Campfire.cs

56 lines
1.4 KiB
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;
2023-08-07 02:38:51 -07:00
using SupaLidlGame.Extensions;
2023-12-29 15:37:52 -08:00
using GodotUtilities.SourceGenerators;
2023-08-07 02:38:51 -07:00
using DialogueManagerRuntime;
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-12-29 15:37:52 -08:00
[Node("PointLight2D")]
2023-06-03 18:21:46 -07:00
private PointLight2D _light;
2023-05-30 01:35:29 -07:00
2023-12-29 15:37:52 -08:00
[Node("InteractionTrigger")]
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-08-07 02:38:51 -07:00
[Export(PropertyHint.File, "*.dialogue")]
public Resource DialogueResource { get; set; }
2023-12-29 15:37:52 -08:00
public override void _Notification(int what)
2023-06-03 18:21:46 -07:00
{
2023-12-29 15:37:52 -08:00
if (what == NotificationSceneInstantiated)
{
WireNodes();
}
}
2023-08-07 02:38:51 -07:00
2023-12-29 15:37:52 -08:00
public override void _Ready()
{
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);
2023-08-07 02:38:51 -07:00
var world = this.GetWorld();
// TODO: implement and use max health
world.CurrentPlayer.Health = 100;
//this.GetAncestor<Utils.World>().SetSpawn(GlobalPosition);
world.DialogueBalloon.Start(DialogueResource, "start");
2023-06-10 22:15:28 -07:00
};
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
}
}