feat: initial import
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using Godot;
|
||||
using GodotHostTest.GodotDI;
|
||||
using GodotHostTest.Interfaces;
|
||||
using R3;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
|
||||
public partial class Target : Node2D, ITarget
|
||||
{
|
||||
[Export] public double TimeOutDurationInSeconds;
|
||||
[Export] public required Timer TimeOutTimer;
|
||||
[Export] public required Sprite2D Image;
|
||||
[Export] public required Area2D CollisionArea;
|
||||
|
||||
private readonly Subject<Unit> _timedOut = new();
|
||||
private readonly Subject<Unit> _hit = new();
|
||||
|
||||
[Inject] private readonly ITargetCollector _targetCollector = null!;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_targetCollector.NewTarget(this);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
_timedOut.Dispose();
|
||||
_hit.Dispose();
|
||||
}
|
||||
|
||||
public Observable<Unit> TimedOut => _timedOut.AsObservable();
|
||||
|
||||
public Observable<Unit> Hit => _hit.AsObservable();
|
||||
|
||||
// todo: hook to collision
|
||||
private void OnHit()
|
||||
{
|
||||
Disable();
|
||||
TimeOutTimer.Stop();
|
||||
_hit.OnNext(Unit.Default);
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
Image.Visible = true;
|
||||
CollisionArea.Monitoring = true;
|
||||
TimeOutTimer.Start(TimeOutDurationInSeconds);
|
||||
}
|
||||
|
||||
private void Disable()
|
||||
{
|
||||
Image.Visible = false;
|
||||
CollisionArea.Monitoring = false;
|
||||
}
|
||||
|
||||
private void OnTimeout()
|
||||
{
|
||||
Disable();
|
||||
_timedOut.OnNext(Unit.Default);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user