Interactions

This commit is contained in:
MaddoScientisto 2024-06-09 18:19:57 +02:00
commit abff2ea59e
19 changed files with 282 additions and 10 deletions

View file

@ -1,6 +1,7 @@
using Godot;
using System;
using System.Diagnostics;
using Cirno.Scripts;
public partial class PlayerMovement : CharacterBody2D
{
@ -12,6 +13,13 @@ public partial class PlayerMovement : CharacterBody2D
[Export]
public PackedScene BulletScene { get; set; }
[Export]
public PackedScene SelectorScene { get; set; }
private Node2D _selector;
private Interactable _lastInteractable;
[Export]
public Marker2D Muzzle { get; set; }
@ -31,6 +39,12 @@ public partial class PlayerMovement : CharacterBody2D
_movementDirection = Vector2.Zero;
_facingDirection = Vector2.Zero;
if (SelectorScene != null)
{
_selector = this.CreateChild<Node2D>(SelectorScene);
_selector.Visible = false;
}
}
/*public override _Process(float _delta)
@ -49,6 +63,20 @@ public partial class PlayerMovement : CharacterBody2D
{
HandleShoot();
SetAnimation();
FindInteractable();
}
private void FindInteractable()
{
if (Input.IsActionJustPressed("Use") && _lastInteractable != null)
{
_lastInteractable.Activate();
}
//var spaceState = GetWorld2D().DirectSpaceState;
//var query = PhysicsRayQueryParameters2D.Create(Vector2.Zero, )
}
private void HandleShoot()
@ -124,5 +152,23 @@ public partial class PlayerMovement : CharacterBody2D
_crosshair.Position = CalculateCrosshairPosition();
//FindInteractable();
}
private void _on_interaction_controller_area_entered(Area2D area)
{
// Replace with function body.
if (area.IsInGroup("Interactable") && area is Interactable interactable)
{
Debug.WriteLine("Interactable Entered");
if (_selector != null)
{
_selector.Position = interactable.Position;
_selector.Visible = true;
_lastInteractable = interactable;
}
}
}
}