mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-12 07:25:53 +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
|
||||
Loading…
Add table
Add a link
Reference in a new issue