Add new components: BrickThrowComponent, BulletComponent, CageComponent, ChaseLevelComponent, CleanupComponent, and ThrowInputResource classes; implement game saving and loading logic in SaveSystem

This commit is contained in:
2025-08-12 13:12:16 +02:00
parent dfa8a17ba1
commit bf11d6a9cb
12 changed files with 399 additions and 6 deletions

View File

@@ -0,0 +1,47 @@
using System.Threading.Tasks;
using Godot;
namespace Mr.BrickAdventures.scripts.components;
public partial class CageComponent : Node
{
[Export] public LeverComponent Lever { get; set; }
[Export] public Vector2 MoveValue { get; set; } = new(0, -100f);
[Export] public float TweenDuration { get; set; } = 0.5f;
[Export] public bool ShouldFree { get; set; } = true;
private const string LeverGroupName = "levers";
public override async void _Ready()
{
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
if (Lever == null)
{
var leverNodes = GetTree().GetNodesInGroup(LeverGroupName);
foreach (var leverNode in leverNodes)
{
var lever = leverNode.GetNodeOrNull<LeverComponent>("LeverComponent");
if (lever != null) lever.Activated += OnLeverActivated;
}
}
}
private void OnLeverActivated()
{
var tween = CreateTween();
if (Owner is Node2D root)
{
var endPosition = root.Position + MoveValue;
tween.TweenProperty(root, "position", endPosition, TweenDuration);
}
tween.TweenCallback(Callable.From(OnTweenCompleted));
}
private void OnTweenCompleted()
{
if (!ShouldFree) return;
Owner.QueueFree();
}
}