Added counter script to count ducks (and other things)
This commit is contained in:
@@ -19,6 +19,7 @@ public partial class DialogicOverlayStarter : Node2D
|
||||
public void ToggleDialogue()
|
||||
{
|
||||
ToggleDialogue(_timelinesToPlay[_timelineIndex]);
|
||||
GD.Print("Toggling Dialogue");
|
||||
}
|
||||
|
||||
public void ToggleDialogue(int index)
|
||||
|
||||
@@ -13,6 +13,7 @@ public partial class MVPDuck : Node2D
|
||||
[Export] private AnimationPlayer _animationPlayer;
|
||||
[Export] private string _flapAnimationName = "flapFlap";
|
||||
|
||||
[Signal] public delegate void DuckCollectedEventHandler();
|
||||
|
||||
public void TransferToTargetAfterDelay()
|
||||
{
|
||||
@@ -29,7 +30,8 @@ public partial class MVPDuck : Node2D
|
||||
public async void MoveAfterDelay()
|
||||
{
|
||||
await ToSignal(GetTree().CreateTimer(1.0f), "timeout"); // 1.0f seconds
|
||||
Position = _penTarget.GlobalPosition; // Now this works!
|
||||
Position = _penTarget.GlobalPosition;
|
||||
EmitSignal(SignalName.DuckCollected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Util;
|
||||
|
||||
public partial class Counter : Node2D
|
||||
{
|
||||
[Export] private int _startFrom = 0;
|
||||
[Export] private int _goal = 0;
|
||||
|
||||
private int _counter;
|
||||
|
||||
[Signal] public delegate void CounterChangedEventHandler(int amount);
|
||||
[Signal] public delegate void GoalReachedEventHandler();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_counter = _startFrom;
|
||||
}
|
||||
|
||||
public void Increment()
|
||||
{
|
||||
_counter++;
|
||||
EmitSignal(SignalName.CounterChanged, _counter);
|
||||
|
||||
GD.Print(_counter);
|
||||
if (_counter == _goal)
|
||||
{
|
||||
GD.Print("Emitting goal reached signal");
|
||||
EmitSignal(SignalName.GoalReached);
|
||||
}
|
||||
}
|
||||
|
||||
public void Decrement()
|
||||
{
|
||||
_counter--;
|
||||
EmitSignal(SignalName.CounterChanged, _counter);
|
||||
|
||||
if (_counter == _goal)
|
||||
{
|
||||
EmitSignal(SignalName.GoalReached);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://l6iq8rpym5io
|
||||
Reference in New Issue
Block a user