mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-06 19:25:54 +00:00
Interactions
This commit is contained in:
parent
e1d6afa512
commit
abff2ea59e
19 changed files with 282 additions and 10 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
17
Scripts/Tools.cs
Normal file
17
Scripts/Tools.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts;
|
||||
|
||||
public static class Tools
|
||||
{
|
||||
public static T CreateChild<T>(this Node2D node, PackedScene prefab) where T : Node2D
|
||||
{
|
||||
if (prefab == null) return null;
|
||||
var newInstance = prefab.Instantiate<T>();
|
||||
node.Owner.CallDeferred("add_child", newInstance);
|
||||
newInstance.Transform = node.GlobalTransform;
|
||||
newInstance.Position = node.Position;
|
||||
|
||||
return newInstance;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue