mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-19 18:33:48 +00:00
Level teleporter
This commit is contained in:
parent
2124701d49
commit
f6c7f1e3bc
2 changed files with 31 additions and 4 deletions
26
Scripts/Activables/LevelTeleporter.cs
Normal file
26
Scripts/Activables/LevelTeleporter.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Cirno.Scripts.Activables;
|
||||||
|
|
||||||
|
public partial class LevelTeleporter : Teleporter
|
||||||
|
{
|
||||||
|
[Export]
|
||||||
|
public new string Target {get; private set;}
|
||||||
|
|
||||||
|
protected override async Task Teleport(PlayerMovement player)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(Target)) return;
|
||||||
|
player.RequestMovementDisable(true);
|
||||||
|
|
||||||
|
await TweenPlayer(player);
|
||||||
|
|
||||||
|
_particles.Emitting = true;
|
||||||
|
|
||||||
|
await Task.Delay((int)(TeleportAnimationLength * 1000));
|
||||||
|
|
||||||
|
GlobalState.Instance.GotoScene(Target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -31,7 +31,7 @@ public partial class Teleporter : Activable
|
||||||
// [Export]
|
// [Export]
|
||||||
// public GpuParticles2D Particles { get; set; }
|
// public GpuParticles2D Particles { get; set; }
|
||||||
|
|
||||||
private GpuParticles2D _particles;
|
protected GpuParticles2D _particles;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
|
|
@ -118,14 +118,15 @@ public partial class Teleporter : Activable
|
||||||
|
|
||||||
// Teleport player to target if active
|
// Teleport player to target if active
|
||||||
if (!IsEnabled) return;
|
if (!IsEnabled) return;
|
||||||
if (Target is null) return;
|
|
||||||
|
|
||||||
// Call Teleport here
|
// Call Teleport here
|
||||||
_ = Teleport(player);
|
_ = Teleport(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Teleport(PlayerMovement player)
|
protected virtual async Task Teleport(PlayerMovement player)
|
||||||
{
|
{
|
||||||
|
if (Target is null) return;
|
||||||
player.RequestMovementDisable(true);
|
player.RequestMovementDisable(true);
|
||||||
|
|
||||||
await TweenPlayer(player);
|
await TweenPlayer(player);
|
||||||
|
|
@ -140,7 +141,7 @@ public partial class Teleporter : Activable
|
||||||
player.RequestMovementDisable(false);
|
player.RequestMovementDisable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TweenPlayer(PlayerMovement player)
|
protected async Task TweenPlayer(PlayerMovement player)
|
||||||
{
|
{
|
||||||
// Create a Tween for the teleport animation
|
// Create a Tween for the teleport animation
|
||||||
Tween tween = GetTree().CreateTween();
|
Tween tween = GetTree().CreateTween();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue