mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Elevators
This commit is contained in:
parent
929d993f99
commit
4fc136e5d7
39 changed files with 4471 additions and 264 deletions
48
Scripts/Actors/Elevator3D.cs
Normal file
48
Scripts/Actors/Elevator3D.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Actors;
|
||||
|
||||
public partial class Elevator3D : PathFollow3D, IActivable
|
||||
{
|
||||
[Export] public float Speed { get; set; }
|
||||
|
||||
private bool _isMoving = false;
|
||||
private float _multiplier = 1f;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!_isMoving) return;
|
||||
|
||||
ProgressRatio += (Speed * (float)delta) * _multiplier;
|
||||
|
||||
if (ProgressRatio is >= 1 or <= 0)
|
||||
{
|
||||
_isMoving = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
if (_isMoving) return false;
|
||||
|
||||
StartMoving();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void StartMoving()
|
||||
{
|
||||
if (_isMoving) return;
|
||||
_isMoving = true;
|
||||
|
||||
if (ProgressRatio <= 0)
|
||||
{
|
||||
_multiplier = 1f;
|
||||
}
|
||||
else if (ProgressRatio >= 1)
|
||||
{
|
||||
_multiplier = -1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Scripts/Actors/Elevator3D.cs.uid
Normal file
1
Scripts/Actors/Elevator3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cyr7ypanl8drq
|
||||
53
Scripts/Components/FSM/3DPlayer/IsoInteractionController.cs
Normal file
53
Scripts/Components/FSM/3DPlayer/IsoInteractionController.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM._3DPlayer;
|
||||
|
||||
public partial class IsoInteractionController : Area3D, IModule<PlayerState, CharacterBody3D>
|
||||
{
|
||||
|
||||
private bool _enabled = false;
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get => _enabled;
|
||||
set
|
||||
{
|
||||
if (_enabled == value) return;
|
||||
_enabled = value;
|
||||
if (_enabled)
|
||||
{
|
||||
EmitSignal(SignalName.InteractionStarted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Signal]
|
||||
public delegate void InteractionStartedEventHandler();
|
||||
|
||||
public IStateMachine<PlayerState, CharacterBody3D> StateMachine { get; private set; }
|
||||
|
||||
public void EnterState(PlayerState state)
|
||||
{
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
public void ExitState(PlayerState state)
|
||||
{
|
||||
Enabled = false;
|
||||
}
|
||||
|
||||
public void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
|
||||
{
|
||||
StateMachine = machine;
|
||||
}
|
||||
|
||||
public void Process(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void PhysicsProcess(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bm73kgly8gv2i
|
||||
72
Scripts/Interactables/AreaTrigger3D.cs
Normal file
72
Scripts/Interactables/AreaTrigger3D.cs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
using Cirno.Scripts.Components.FSM._3DPlayer;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Interactables;
|
||||
|
||||
public partial class AreaTrigger3D : Area3D
|
||||
{
|
||||
[Export] public Node3D Target { get; set; }
|
||||
|
||||
[Export] public ActivationType ActivationType { get; set; } = Scripts.ActivationType.Toggle;
|
||||
|
||||
[Export] public bool OneTime { get; set; }
|
||||
[Export] public bool DoNotActivateOnFirst { get; set; }
|
||||
|
||||
private int _activations = 0;
|
||||
|
||||
[Signal]
|
||||
public delegate void ActivatedEventHandler();
|
||||
|
||||
private IsoInteractionController _cachedPlayer;
|
||||
|
||||
private bool Activate()
|
||||
{
|
||||
if (_activations == 0 && DoNotActivateOnFirst)
|
||||
{
|
||||
_activations++;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OneTime && _activations > 0) return false;
|
||||
|
||||
if (Target != null)
|
||||
{
|
||||
if (Target is not IActivable target)
|
||||
{
|
||||
GD.PrintErr($"Target {Target.Name} is not activable");
|
||||
return false;
|
||||
}
|
||||
target.Activate(ActivationType);
|
||||
}
|
||||
|
||||
EmitSignal(nameof(Activated));
|
||||
|
||||
_activations++;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private void _on_area_entered(Area3D area)
|
||||
{
|
||||
if (area is not IsoInteractionController player) return;
|
||||
if (player.Enabled)
|
||||
{
|
||||
Activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
_cachedPlayer = player;
|
||||
_cachedPlayer.InteractionStarted += PlayerOnInteractionStarted;
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayerOnInteractionStarted()
|
||||
{
|
||||
Activate();
|
||||
if (_cachedPlayer != null)
|
||||
{
|
||||
_cachedPlayer.InteractionStarted -= PlayerOnInteractionStarted;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Scripts/Interactables/AreaTrigger3D.cs.uid
Normal file
1
Scripts/Interactables/AreaTrigger3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://btyooucm1g70g
|
||||
Loading…
Add table
Add a link
Reference in a new issue