Added counter script to count ducks (and other things)

This commit is contained in:
2025-07-10 23:58:33 +02:00
parent 480d149ede
commit c7d56301fc
6 changed files with 72 additions and 4 deletions
+43
View File
@@ -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