init
This commit is contained in:
39
src/Gameplay/BuildGhost.cs
Normal file
39
src/Gameplay/BuildGhost.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Godot;
|
||||
|
||||
namespace Slimepire.Gameplay;
|
||||
|
||||
[SceneTree]
|
||||
public partial class BuildGhost : Node2D
|
||||
{
|
||||
public event Action<Vector2>? OnBuild;
|
||||
private Tube? _tube;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_tube = Instantiator.Instantiate<Tube>();
|
||||
_tube.Position = Position / 2; // TODO WHYYY????
|
||||
GetParent()?.AddChild(_tube);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
GlobalPosition = GetGlobalMousePosition();
|
||||
_tube?.SetTarget(GlobalPosition);
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
using (@event)
|
||||
{
|
||||
if (@event is InputEventMouseButton { Pressed: false, ButtonIndex: MouseButton.Left })
|
||||
{
|
||||
OnBuild?.Invoke(GlobalPosition);
|
||||
|
||||
_tube?.QueueFree();
|
||||
QueueFree();
|
||||
|
||||
GetViewport().SetInputAsHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user