mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 12:25:55 +00:00
Teleporters
This commit is contained in:
parent
7e76edc153
commit
1907a38575
25 changed files with 616 additions and 4 deletions
197
Scripts/Activables/3D/Teleporter3D.cs
Normal file
197
Scripts/Activables/3D/Teleporter3D.cs
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Cirno.Scripts.Components.FSM;
|
||||
using Cirno.Scripts.Components.FSM._3DPlayer;
|
||||
using Godot;
|
||||
using GTweensGodot.Extensions;
|
||||
|
||||
namespace Cirno.Scripts.Activables._3D;
|
||||
|
||||
[Tool]
|
||||
public partial class Teleporter3D : StaticBody3D, IActivable
|
||||
{
|
||||
[Export] public bool IsEnabled { get; set; }
|
||||
|
||||
[Export] public bool Invisible { get; set; } = false;
|
||||
|
||||
public bool IsPrimed { get; private set; }
|
||||
|
||||
[Export] public Teleporter3D Target { get; set; }
|
||||
|
||||
[Export] public float ParticleEmitTime { get; private set; } = 2f;
|
||||
|
||||
[Export] public float TeleportAnimationLength { get; private set; } = 0.5f;
|
||||
[Export] public Vector3 TeleportOffset { get; private set; } = new Vector3(0, 4f, 0);
|
||||
|
||||
[ExportCategory("Animations")]
|
||||
[Export]
|
||||
public StringName ActiveAnimationName { get; private set; } = "Active";
|
||||
|
||||
[Export] public StringName DefaultAnimationName { get; private set; } = "Default";
|
||||
|
||||
private void PlayAnimation(StringName name)
|
||||
{
|
||||
}
|
||||
|
||||
private void StopParticles()
|
||||
{
|
||||
// _particles.Emitting = false;
|
||||
// _particleTimer = 0;
|
||||
}
|
||||
|
||||
private void EmitParticles()
|
||||
{
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
PlayAnimation(IsEnabled ? ActiveAnimationName : DefaultAnimationName);
|
||||
|
||||
if (Engine.IsEditorHint()) return;
|
||||
|
||||
|
||||
IsPrimed = true;
|
||||
StopParticles();
|
||||
|
||||
this.Visible = !Invisible;
|
||||
|
||||
// _teleportStartSound = GetNodeOrNull<AudioStreamPlayer2D>("TeleportStart");
|
||||
// _teleportEndSound = GetNodeOrNull<AudioStreamPlayer2D>("TeleportEnd");
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Engine.IsEditorHint()) return;
|
||||
// if (!_particles.Emitting) return;
|
||||
//
|
||||
// _particleTimer += delta;
|
||||
//
|
||||
// if (_particleTimer >= ParticleEmitTime)
|
||||
// {
|
||||
// _particleTimer = 0;
|
||||
// _particles.Emitting = false;
|
||||
// }
|
||||
}
|
||||
|
||||
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
switch (activationType)
|
||||
{
|
||||
case ActivationType.Toggle:
|
||||
// Enables/Disables teleporter
|
||||
break;
|
||||
case ActivationType.Enable:
|
||||
// Enables Teleporter
|
||||
IsEnabled = true;
|
||||
PlayAnimation(ActiveAnimationName);
|
||||
break;
|
||||
case ActivationType.Disable:
|
||||
IsEnabled = false;
|
||||
PlayAnimation(DefaultAnimationName);
|
||||
// Disables Teleporter
|
||||
break;
|
||||
case ActivationType.Use:
|
||||
// Teleports
|
||||
break;
|
||||
case ActivationType.Destroy:
|
||||
// Destroys
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void PrepareForReceiving()
|
||||
{
|
||||
IsPrimed = false;
|
||||
EmitParticles();
|
||||
}
|
||||
|
||||
public void FireParticles()
|
||||
{
|
||||
EmitParticles();
|
||||
}
|
||||
|
||||
private void _on_body_entered(Node3D body)
|
||||
{
|
||||
GD.Print("Something entered the teleporter");
|
||||
if (!IsEnabled) return;
|
||||
if (body is not IsoPlayerFSMProxy player) return;
|
||||
GD.Print("Player entered the teleporter");
|
||||
|
||||
if (!IsPrimed)
|
||||
{
|
||||
IsPrimed = true;
|
||||
//_particles.Emitting = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Teleport player to target if active
|
||||
if (!IsEnabled) return;
|
||||
|
||||
GD.Print("Teleporting...");
|
||||
|
||||
// Call Teleport here
|
||||
_ = Teleport(player.PlayerFSM);
|
||||
}
|
||||
|
||||
protected virtual async Task Teleport(IsoPlayerStateMachine player)
|
||||
{
|
||||
if (Target is null) return;
|
||||
//player.RequestMovementDisable(true);
|
||||
player.SetState(PlayerState.Cutscene);
|
||||
|
||||
await TweenPlayer(player.MainObject);
|
||||
|
||||
PlayTeleportStartSound();
|
||||
|
||||
//_particles.Emitting = true;
|
||||
FireParticles();
|
||||
|
||||
//await player.Teleport();
|
||||
player.SetState(PlayerState.Teleporting);
|
||||
await Task.Delay((int)(0.6f * 1000));
|
||||
|
||||
await Task.Delay((int)(TeleportAnimationLength * 1000));
|
||||
|
||||
Target.PrepareForReceiving();
|
||||
player.MainObject.GlobalPosition = Target.GlobalPosition + TeleportOffset;
|
||||
Target.PlayTeleportEndSound();
|
||||
//await player.UnTeleport();
|
||||
|
||||
player.SetState(PlayerState.UnTeleporting);
|
||||
await Task.Delay((int)(0.6f * 1000));
|
||||
|
||||
//player.RequestMovementDisable(false);
|
||||
player.SetState(PlayerState.Active);
|
||||
}
|
||||
|
||||
public void PlayTeleportStartSound()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void PlayTeleportEndSound()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected async Task TweenPlayer(CharacterBody3D player)
|
||||
{
|
||||
await player.TweenGlobalPosition(GlobalPosition + TeleportOffset, TeleportAnimationLength)
|
||||
.PlayAsync(CancellationToken.None);
|
||||
|
||||
// Create a Tween for the teleport animation
|
||||
// Tween tween = GetTree().CreateTween();
|
||||
// tween.SetEase(Tween.EaseType.InOut);
|
||||
// tween.SetTrans(Tween.TransitionType.Sine);
|
||||
// tween.TweenProperty(player, "global_position", GlobalPosition + new Vector2(0,-4f), TeleportAnimationLength);
|
||||
//
|
||||
// // Wait for the tween to finish
|
||||
// await ToSignal(tween, "finished");
|
||||
}
|
||||
|
||||
public void Toggle()
|
||||
{
|
||||
}
|
||||
}
|
||||
1
Scripts/Activables/3D/Teleporter3D.cs.uid
Normal file
1
Scripts/Activables/3D/Teleporter3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dmpd31aphufg7
|
||||
54
Scripts/Components/FSM/3DPlayer/Cutscene.cs
Normal file
54
Scripts/Components/FSM/3DPlayer/Cutscene.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using Cirno.Scripts.Components.Actors._3D;
|
||||
using Cirno.Scripts.Components.FSM.Player;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM._3DPlayer;
|
||||
|
||||
public partial class Cutscene : BaseState<PlayerState, CharacterBody3D>
|
||||
{
|
||||
public override PlayerState StateId => PlayerState.Cutscene;
|
||||
|
||||
[Export] public PlayerAnimationProvider3D AnimationProvider { get; set; }
|
||||
|
||||
[Export] public IsoPlayerStorageModule PlayerStorage { get; private set; }
|
||||
|
||||
public override void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
|
||||
{
|
||||
base.Init(machine);
|
||||
}
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
base.EnterState();
|
||||
MainObject.Show();
|
||||
MainObject.Velocity = Vector3.Zero;
|
||||
PlayerStorage.MovementDirection = Vector3.Zero;
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
base.ExitState();
|
||||
|
||||
AnimationProvider.SetAnimationSpeed(Vector2.Zero);
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
base.ProcessState(delta);
|
||||
AnimationProvider.SetAnimationSpeed(MainObject.Velocity.ToVector2());
|
||||
AnimationProvider.SetAnimation(MainObject.Velocity.ToVector2());
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
// Reset at start of frame
|
||||
//MainObject.Velocity = Vector2.Zero;
|
||||
|
||||
// Process modules
|
||||
base.PhysicsProcessState(delta);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
1
Scripts/Components/FSM/3DPlayer/Cutscene.cs.uid
Normal file
1
Scripts/Components/FSM/3DPlayer/Cutscene.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ci87ilsfrj1xh
|
||||
|
|
@ -74,7 +74,6 @@ public partial class IsoMovementModule : ModuleBase<PlayerState, CharacterBody3D
|
|||
|
||||
public override void PhysicsProcess(double delta)
|
||||
{
|
||||
|
||||
var frameVelocity = MainObject.Velocity;
|
||||
|
||||
if (_isStrafing)
|
||||
|
|
|
|||
46
Scripts/Components/FSM/3DPlayer/Teleporting.cs
Normal file
46
Scripts/Components/FSM/3DPlayer/Teleporting.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using Cirno.Scripts.Components.Actors._3D;
|
||||
using Cirno.Scripts.Components.FSM.Player;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM._3DPlayer;
|
||||
|
||||
public partial class Teleporting : BaseState<PlayerState, CharacterBody3D>
|
||||
{
|
||||
public override PlayerState StateId => PlayerState.Teleporting;
|
||||
|
||||
[Export] public PlayerAnimationProvider3D AnimationProvider { get; set; }
|
||||
|
||||
public override void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
|
||||
{
|
||||
base.Init(machine);
|
||||
}
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
base.EnterState();
|
||||
AnimationProvider.PlayTeleportAnimation();
|
||||
MainObject.Velocity = Vector3.Zero;
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
base.ExitState();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
base.ProcessState(delta);
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
// Process modules
|
||||
base.PhysicsProcessState(delta);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
1
Scripts/Components/FSM/3DPlayer/Teleporting.cs.uid
Normal file
1
Scripts/Components/FSM/3DPlayer/Teleporting.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dls68t7f8eoqb
|
||||
45
Scripts/Components/FSM/3DPlayer/UnTeleporting.cs
Normal file
45
Scripts/Components/FSM/3DPlayer/UnTeleporting.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using Cirno.Scripts.Components.Actors._3D;
|
||||
using Cirno.Scripts.Components.FSM.Player;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM._3DPlayer;
|
||||
|
||||
public partial class UnTeleporting : BaseState<PlayerState, CharacterBody3D>
|
||||
{
|
||||
public override PlayerState StateId => PlayerState.UnTeleporting;
|
||||
|
||||
[Export] public PlayerAnimationProvider3D AnimationProvider { get; set; }
|
||||
|
||||
public override void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
|
||||
{
|
||||
base.Init(machine);
|
||||
}
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
base.EnterState();
|
||||
AnimationProvider.PlayUnteleportAnimation();
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
base.ExitState();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
base.ProcessState(delta);
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
// Process modules
|
||||
base.PhysicsProcessState(delta);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
1
Scripts/Components/FSM/3DPlayer/UnTeleporting.cs.uid
Normal file
1
Scripts/Components/FSM/3DPlayer/UnTeleporting.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bayjsi428yx83
|
||||
Loading…
Add table
Add a link
Reference in a new issue