mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:05:34 +00:00
FSM Selector with sound
This commit is contained in:
parent
f6d159b9c4
commit
ee09c50dbd
20 changed files with 330 additions and 28 deletions
106
Scripts/Components/Actors/ActivationProvider.cs
Normal file
106
Scripts/Components/Actors/ActivationProvider.cs
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class ActivationProvider : Area2D
|
||||
{
|
||||
public bool Enabled { get; set; } = false;
|
||||
|
||||
private Selector _selector;
|
||||
|
||||
[Export]
|
||||
public PackedScene SelectorScene { get; set; }
|
||||
|
||||
[Export]
|
||||
private InputProvider _inputProvider;
|
||||
|
||||
[Export] private AudioStreamPlayer2D _errorSound;
|
||||
|
||||
[Signal]
|
||||
public delegate void InteractableAreaEnteredEventHandler(Interactable interactable);
|
||||
|
||||
[Signal]
|
||||
public delegate void InteractableAreaExitedEventHandler(Interactable interactable);
|
||||
|
||||
public void Init()
|
||||
{
|
||||
if (SelectorScene is not null && _selector is null)
|
||||
{
|
||||
_selector = this.CreateSibling<Selector>(SelectorScene, this.GlobalPosition);
|
||||
_selector.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleInteraction()
|
||||
{
|
||||
if (_inputProvider.GetUseJustPressed())
|
||||
{
|
||||
TrySelect();
|
||||
}
|
||||
|
||||
if (_inputProvider.GetScanJustPressed())
|
||||
{
|
||||
_selector.SelectNext();
|
||||
}
|
||||
}
|
||||
|
||||
private void TrySelect()
|
||||
{
|
||||
var selected = _selector.SelectedInteractable;
|
||||
if (selected is null)
|
||||
{
|
||||
_errorSound?.Play();
|
||||
return;
|
||||
};
|
||||
if (!selected.CanActivate())
|
||||
{
|
||||
_errorSound?.Play();
|
||||
return;
|
||||
};
|
||||
bool success = selected.Activate();
|
||||
|
||||
if (success)
|
||||
{
|
||||
// Deselect and scan for next
|
||||
_selector.RemoveInteractable(selected);
|
||||
//_selector.SelectedInteractable = null;
|
||||
//_selector.SelectNext();
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorSound?.Play();
|
||||
}
|
||||
|
||||
//var spaceState = GetWorld2D().DirectSpaceState;
|
||||
|
||||
//var query = PhysicsRayQueryParameters2D.Create(Vector2.Zero, )
|
||||
}
|
||||
|
||||
private void _on_interaction_controller_area_entered(Area2D area)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
if (area.IsInGroup("Interactable") && area is Interactable interactable && interactable.CanActivate())
|
||||
{
|
||||
EmitSignal(nameof(InteractableAreaEntered), interactable);
|
||||
|
||||
if (_selector == null) return;
|
||||
|
||||
_selector.AddInteractable(interactable);
|
||||
|
||||
//_selector.SelectedInteractable = interactable;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void _on_interaction_controller_area_exited(Area2D area)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
if (area.IsInGroup("Interactable") && area is Interactable interactable)
|
||||
{
|
||||
EmitSignal(nameof(InteractableAreaExited), interactable);
|
||||
|
||||
if (_selector == null) return;
|
||||
_selector.RemoveInteractable(interactable);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/Actors/ActivationProvider.cs.uid
Normal file
1
Scripts/Components/Actors/ActivationProvider.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dv205x8msohpv
|
||||
|
|
@ -12,6 +12,7 @@ public abstract partial class InputProvider : Node2D
|
|||
|
||||
public abstract bool GetShootPressed();
|
||||
public abstract bool GetUseJustPressed();
|
||||
public abstract bool GetScanJustPressed();
|
||||
public abstract bool GetStrafePressed();
|
||||
public abstract bool GetWeaponNextJustPressed();
|
||||
public abstract bool GetWeaponPreviousJustPressed();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
[ExportCategory("Action Names")]
|
||||
[Export] private string _shootActionName = "shoot";
|
||||
[Export] private string _useActionName = "Use";
|
||||
[Export] private string _scanActionName = "scan";
|
||||
[Export] private string _strafeActionName = "strafe";
|
||||
[Export] private string _nextWeaponActionName = "next_weapon";
|
||||
[Export] private string _previousWeaponActionName = "previous_weapon";
|
||||
|
|
@ -68,6 +69,10 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
{
|
||||
return GetActionJustPressed(_useActionName);
|
||||
}
|
||||
public override bool GetScanJustPressed()
|
||||
{
|
||||
return GetActionJustPressed(_scanActionName);
|
||||
}
|
||||
|
||||
public override bool GetStrafePressed()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ public partial class Active : PlayerFSMState
|
|||
private InputProvider _inputProvider;
|
||||
|
||||
[Export] private PlayerDamageReceiver _damageReceiver;
|
||||
[Export] private ActivationProvider _activationProvider;
|
||||
|
||||
private bool _isStrafing;
|
||||
|
||||
|
|
@ -58,6 +59,8 @@ public partial class Active : PlayerFSMState
|
|||
|
||||
_damageReceiver.Init();
|
||||
|
||||
_activationProvider.Init();
|
||||
|
||||
//_weaponProvider = stateMachine.GetNode<PlayerWeaponProvider>("WeaponProvider");
|
||||
//_animationProvider = stateMachine.GetNode<PlayerAnimationProvider>("AnimationProvider");
|
||||
|
||||
|
|
@ -71,6 +74,7 @@ public partial class Active : PlayerFSMState
|
|||
_crosshairProvider.Show();
|
||||
|
||||
_damageReceiver.Enabled = true;
|
||||
_activationProvider.Enabled = true;
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
|
|
@ -80,6 +84,7 @@ public partial class Active : PlayerFSMState
|
|||
_hitboxSpriteProvider.Hide();
|
||||
|
||||
_damageReceiver.Enabled = false;
|
||||
_activationProvider.Enabled = false;
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
|
|
@ -117,6 +122,8 @@ public partial class Active : PlayerFSMState
|
|||
_crosshairProvider.UpdatePosition(FacingDirection);
|
||||
|
||||
HandleShoot();
|
||||
|
||||
HandleInteraction();
|
||||
// FindInteractable();
|
||||
|
||||
// _crosshair.Position = CalculateCrosshairPosition();
|
||||
|
|
@ -129,5 +136,8 @@ public partial class Active : PlayerFSMState
|
|||
_weaponProvider.Shoot(this.FacingDirection);
|
||||
}
|
||||
|
||||
|
||||
private void HandleInteraction()
|
||||
{
|
||||
_activationProvider.HandleInteraction();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
29
Scripts/Components/FSM/Player/Controlling.cs
Normal file
29
Scripts/Components/FSM/Player/Controlling.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Player;
|
||||
|
||||
public partial class Controlling : PlayerFSMState
|
||||
{
|
||||
[Export]
|
||||
private PlayerAnimationProvider _animationProvider;
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/FSM/Player/Controlling.cs.uid
Normal file
1
Scripts/Components/FSM/Player/Controlling.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bwtcgcvfw8urt
|
||||
29
Scripts/Components/FSM/Player/Cutscene.cs
Normal file
29
Scripts/Components/FSM/Player/Cutscene.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Player;
|
||||
|
||||
public partial class Cutscene : PlayerFSMState
|
||||
{
|
||||
[Export]
|
||||
private PlayerAnimationProvider _animationProvider;
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/FSM/Player/Cutscene.cs.uid
Normal file
1
Scripts/Components/FSM/Player/Cutscene.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dn2rrgw3e027b
|
||||
|
|
@ -6,19 +6,28 @@ public partial class Dead : PlayerFSMState
|
|||
{
|
||||
[Export]
|
||||
private PlayerAnimationProvider _animationProvider;
|
||||
|
||||
public override void Init(ActorStateMachine stateMachine)
|
||||
{
|
||||
base.Init(stateMachine);
|
||||
// get hud?
|
||||
|
||||
}
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
_animationProvider.PlayDeathAnimation();
|
||||
// show game over
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
|
||||
// Hide game over
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
// wait for button
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
29
Scripts/Components/FSM/Player/Teleporting.cs
Normal file
29
Scripts/Components/FSM/Player/Teleporting.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Player;
|
||||
|
||||
public partial class Teleporting : PlayerFSMState
|
||||
{
|
||||
[Export]
|
||||
private PlayerAnimationProvider _animationProvider;
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/FSM/Player/Teleporting.cs.uid
Normal file
1
Scripts/Components/FSM/Player/Teleporting.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b0khv2fcrgm6t
|
||||
|
|
@ -584,6 +584,7 @@ public enum PlayerState
|
|||
Init,
|
||||
Active,
|
||||
Cutscene,
|
||||
Teleporting,
|
||||
Controlling,
|
||||
Dead,
|
||||
}
|
||||
|
|
@ -42,22 +42,22 @@ public partial class Selector : Node2D
|
|||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("scan"))
|
||||
{
|
||||
SelectNext();
|
||||
}
|
||||
|
||||
// if (SelectedInteractable is not null) {
|
||||
// this.Visible = true;
|
||||
// this.GlobalPosition = SelectedInteractable.GlobalPosition;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.Visible = false;
|
||||
// }
|
||||
}
|
||||
// public override void _Process(double delta)
|
||||
// {
|
||||
// if (Input.IsActionJustPressed("scan"))
|
||||
// {
|
||||
// SelectNext();
|
||||
// }
|
||||
//
|
||||
// // if (SelectedInteractable is not null) {
|
||||
// // this.Visible = true;
|
||||
// // this.GlobalPosition = SelectedInteractable.GlobalPosition;
|
||||
// // }
|
||||
// // else
|
||||
// // {
|
||||
// // this.Visible = false;
|
||||
// // }
|
||||
// }
|
||||
|
||||
public void SelectNext()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue