parent
b1335d4b00
commit
0e55394699
@ -0,0 +1,23 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://pflu0uaig7vv"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ccc6m6c5khd2x" path="res://scripts/CSharp/Common/CharacterControls/DetectionCross.cs" id="1_va8tx"]
|
||||
[ext_resource type="PackedScene" uid="uid://dugr6ff1g7hi0" path="res://prefabs/interactions/detector.tscn" id="2_8hh05"]
|
||||
|
||||
[node name="DetectionCross" type="Node2D" node_paths=PackedStringArray("_left", "_right", "_up", "_down")]
|
||||
script = ExtResource("1_va8tx")
|
||||
_left = NodePath("detector_left")
|
||||
_right = NodePath("detector_right")
|
||||
_up = NodePath("detector_top")
|
||||
_down = NodePath("detector_bottom")
|
||||
|
||||
[node name="detector_right" parent="." instance=ExtResource("2_8hh05")]
|
||||
position = Vector2(300, 250)
|
||||
|
||||
[node name="detector_left" parent="." instance=ExtResource("2_8hh05")]
|
||||
position = Vector2(-300, 250)
|
||||
|
||||
[node name="detector_top" parent="." instance=ExtResource("2_8hh05")]
|
||||
position = Vector2(0, -200)
|
||||
|
||||
[node name="detector_bottom" parent="." instance=ExtResource("2_8hh05")]
|
||||
position = Vector2(0, 700)
|
||||
@ -0,0 +1,17 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://dugr6ff1g7hi0"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c3pd60biootsx" path="res://scripts/CSharp/Common/CharacterControls/Detector.cs" id="1_6pib0"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_qwv4c"]
|
||||
size = Vector2(300, 300)
|
||||
|
||||
[node name="right" type="Area2D"]
|
||||
collision_layer = 4
|
||||
script = ExtResource("1_6pib0")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_qwv4c")
|
||||
debug_color = Color(0.9459047, 7.2196126e-06, 0.5925879, 0.41960785)
|
||||
|
||||
[connection signal="InteractableEntered" from="." to="CollisionShape2D" method="hide"]
|
||||
[connection signal="InteractableExited" from="." to="CollisionShape2D" method="show"]
|
||||
@ -0,0 +1,14 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class DetectableInteractionArea : Area2D
|
||||
{
|
||||
[Export] private InteractionArea2D _interactionArea2D;
|
||||
|
||||
public void ActivateInteractionArea(bool activate)
|
||||
{
|
||||
_interactionArea2D.IsActive = activate;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://cp2q4k62sjo6h
|
||||
@ -0,0 +1,125 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
/// <summary>
|
||||
/// Tracks where an interactable object is with regards to the player.
|
||||
/// </summary>
|
||||
public partial class DetectionCross : Node2D
|
||||
{
|
||||
[Export] private Detector _left;
|
||||
[Export] private Detector _right;
|
||||
[Export] private Detector _up;
|
||||
[Export] private Detector _down;
|
||||
[Export] private bool _active = true;
|
||||
|
||||
[Signal] public delegate void InteractableDetectedLeftEventHandler(bool flag);
|
||||
[Signal] public delegate void InteractableDetectedRightEventHandler(bool flag);
|
||||
[Signal] public delegate void InteractableDetectedUpEventHandler(bool flag);
|
||||
[Signal] public delegate void InteractableDetectedDownEventHandler(bool flag);
|
||||
|
||||
private bool _leftOccupied;
|
||||
private bool _rightOccupied;
|
||||
private bool _upOccupied;
|
||||
private bool _downOccupied;
|
||||
public bool LeftOccupied {
|
||||
get
|
||||
{
|
||||
return _leftOccupied;
|
||||
}
|
||||
private set
|
||||
{
|
||||
EmitSignal(SignalName.InteractableDetectedLeft, value);
|
||||
_leftOccupied = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool RightOccupied
|
||||
{
|
||||
get
|
||||
{
|
||||
return _rightOccupied;
|
||||
}
|
||||
private set
|
||||
{
|
||||
EmitSignal(SignalName.InteractableDetectedRight, value);
|
||||
_rightOccupied = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpOccupied
|
||||
{
|
||||
get
|
||||
{
|
||||
return _upOccupied;
|
||||
}
|
||||
private set
|
||||
{
|
||||
EmitSignal(SignalName.InteractableDetectedUp, value);
|
||||
_upOccupied = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DownOccupied
|
||||
{
|
||||
get
|
||||
{
|
||||
return _downOccupied;
|
||||
}
|
||||
private set
|
||||
{
|
||||
EmitSignal(SignalName.InteractableDetectedDown, value);
|
||||
_downOccupied = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsActive
|
||||
{
|
||||
get => _active;
|
||||
set => _active = value;
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_right.InteractableEntered += () => RightOccupied = true;
|
||||
_right.InteractableExited += () => RightOccupied = false;
|
||||
_left.InteractableEntered += () => LeftOccupied = true;
|
||||
_left.InteractableExited += () => LeftOccupied = false;
|
||||
_up.InteractableEntered += () => UpOccupied = true;
|
||||
_up.InteractableExited += () => UpOccupied = false;
|
||||
_down.InteractableEntered += () => DownOccupied = true;
|
||||
_down.InteractableExited += () => DownOccupied = false;
|
||||
}
|
||||
|
||||
public void ActivateUp()
|
||||
{
|
||||
_up.IsActive = true;
|
||||
_down.IsActive = false;
|
||||
_left.IsActive = false;
|
||||
_right.IsActive = false;
|
||||
}
|
||||
|
||||
public void ActivateDown()
|
||||
{
|
||||
_up.IsActive = false;
|
||||
_down.IsActive = true;
|
||||
_left.IsActive = false;
|
||||
_right.IsActive = false;
|
||||
}
|
||||
|
||||
public void ActivateRight()
|
||||
{
|
||||
_up.IsActive = false;
|
||||
_down.IsActive = false;
|
||||
_left.IsActive = false;
|
||||
_right.IsActive = true;
|
||||
}
|
||||
|
||||
public void ActivateLeft()
|
||||
{
|
||||
_up.IsActive = false;
|
||||
_down.IsActive = false;
|
||||
_left.IsActive = true;
|
||||
_right.IsActive = false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://ccc6m6c5khd2x
|
||||
@ -0,0 +1,63 @@
|
||||
using Babushka.scripts.CSharp.Common.Services;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class Detector : Area2D
|
||||
{
|
||||
[Export] private bool _active = true;
|
||||
[Export] private bool _oneAtATime = true;
|
||||
|
||||
[Signal] public delegate void InteractableEnteredEventHandler();
|
||||
[Signal] public delegate void InteractableExitedEventHandler();
|
||||
|
||||
private DetectableInteractionArea? _currentInteractionArea;
|
||||
|
||||
public bool IsActive
|
||||
{
|
||||
get => _active;
|
||||
set => _active = value;
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
AreaEntered += OnEnteredInteractable;
|
||||
AreaExited += OnExitedInteractable;
|
||||
}
|
||||
|
||||
public void OnEnteredInteractable(Node body)
|
||||
{
|
||||
if (!_active || !InputService.Instance.InputEnabled)
|
||||
return;
|
||||
|
||||
GD.Print("Entered Node2D.");
|
||||
|
||||
if (body is DetectableInteractionArea interactionArea2D)
|
||||
{
|
||||
GD.Print("Entered interactable.");
|
||||
_currentInteractionArea = interactionArea2D;
|
||||
interactionArea2D.ActivateInteractionArea(true);
|
||||
EmitSignal(SignalName.InteractableEntered);
|
||||
if (_oneAtATime)
|
||||
_active = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnExitedInteractable(Node body)
|
||||
{
|
||||
GD.Print("Exited Node2D.");
|
||||
|
||||
if (body is DetectableInteractionArea interactionArea2D)
|
||||
{
|
||||
GD.Print("Exited interactable.");
|
||||
|
||||
if (_oneAtATime && _currentInteractionArea != interactionArea2D)
|
||||
return;
|
||||
|
||||
interactionArea2D.ActivateInteractionArea(false);
|
||||
_currentInteractionArea = null;
|
||||
EmitSignal(SignalName.InteractableExited);
|
||||
_active = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
uid://c3pd60biootsx
|
||||
Loading…
Reference in new issue