mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 07:25:54 +00:00
Fixed teleporters
This commit is contained in:
parent
9c3f22760b
commit
49cfb52d20
15 changed files with 102 additions and 84 deletions
|
|
@ -15,41 +15,41 @@ public partial class Teleporter : Activable
|
|||
|
||||
[Export]
|
||||
public bool Invisible { get; private set; } = false;
|
||||
|
||||
|
||||
public bool IsPrimed { get; private set; }
|
||||
|
||||
|
||||
[Export]
|
||||
public Teleporter Target { get; set; }
|
||||
|
||||
[Export] public float ParticleEmitTime { get; private set; } = 2f;
|
||||
|
||||
[Export] public float TeleportAnimationLength { get; private set; } = 0.5f;
|
||||
|
||||
[Export] public Vector2 TeleportOffset { get; private set; } = new Vector2(0,-4f);
|
||||
|
||||
|
||||
[Export] public float TeleportAnimationLength { get; private set; } = 0.5f;
|
||||
|
||||
[Export] public Vector2 TeleportOffset { get; private set; } = new Vector2(0, -4f);
|
||||
|
||||
private double _particleTimer;
|
||||
|
||||
|
||||
private AnimatedSprite2D _animatedSprite;
|
||||
|
||||
|
||||
// [Export]
|
||||
// public GpuParticles2D Particles { get; set; }
|
||||
|
||||
protected GpuParticles2D _particles;
|
||||
|
||||
private AudioStreamPlayer2D _teleportStartSound;
|
||||
private AudioStreamPlayer2D _teleportEndSound;
|
||||
|
||||
private AudioStreamPlayer2D _teleportStartSound;
|
||||
private AudioStreamPlayer2D _teleportEndSound;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_particles = GetNode<GpuParticles2D>("./Particles");
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
|
||||
|
||||
|
||||
IsPrimed = true;
|
||||
_particles.Emitting = false;
|
||||
_particleTimer = 0;
|
||||
|
||||
this.Visible = !Invisible;
|
||||
|
||||
|
||||
if (IsEnabled)
|
||||
{
|
||||
_animatedSprite.Play("Active");
|
||||
|
|
@ -66,7 +66,7 @@ private AudioStreamPlayer2D _teleportEndSound;
|
|||
public override void _Process(double delta)
|
||||
{
|
||||
if (!_particles.Emitting) return;
|
||||
|
||||
|
||||
_particleTimer += delta;
|
||||
|
||||
if (_particleTimer >= ParticleEmitTime)
|
||||
|
|
@ -75,7 +75,7 @@ private AudioStreamPlayer2D _teleportEndSound;
|
|||
_particles.Emitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
switch (activationType)
|
||||
|
|
@ -113,11 +113,13 @@ private AudioStreamPlayer2D _teleportEndSound;
|
|||
_particles.Emitting = true;
|
||||
_particleTimer = 0;
|
||||
}
|
||||
|
||||
|
||||
private void _on_area_entered(Area2D area)
|
||||
{
|
||||
GD.Print("Something entered the teleporter");
|
||||
if (!IsEnabled) return;
|
||||
if (area is not InteractionController interactionController) return;
|
||||
GD.Print("Player entered the teleporter");
|
||||
|
||||
if (!IsPrimed)
|
||||
{
|
||||
|
|
@ -125,11 +127,12 @@ private AudioStreamPlayer2D _teleportEndSound;
|
|||
//_particles.Emitting = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Teleport player to target if active
|
||||
if (!IsEnabled) return;
|
||||
|
||||
|
||||
|
||||
GD.Print("Teleporting...");
|
||||
|
||||
// Call Teleport here
|
||||
_ = Teleport(interactionController.StateMachine);
|
||||
}
|
||||
|
|
@ -141,7 +144,7 @@ private AudioStreamPlayer2D _teleportEndSound;
|
|||
player.SetState(PlayerState.Cutscene);
|
||||
|
||||
await TweenPlayer(player.MainObject);
|
||||
|
||||
|
||||
PlayTeleportStartSound();
|
||||
|
||||
//_particles.Emitting = true;
|
||||
|
|
@ -150,17 +153,17 @@ private AudioStreamPlayer2D _teleportEndSound;
|
|||
//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);
|
||||
}
|
||||
|
|
@ -178,7 +181,7 @@ private AudioStreamPlayer2D _teleportEndSound;
|
|||
protected async Task TweenPlayer(CharacterBody2D player)
|
||||
{
|
||||
await player.TweenGlobalPosition(GlobalPosition + new Vector2(0, -4f), TeleportAnimationLength).PlayAsync(CancellationToken.None);
|
||||
|
||||
|
||||
// Create a Tween for the teleport animation
|
||||
// Tween tween = GetTree().CreateTween();
|
||||
// tween.SetEase(Tween.EaseType.InOut);
|
||||
|
|
|
|||
1
Scripts/Components/FSM/Player/PlayerStateBase.cs.uid
Normal file
1
Scripts/Components/FSM/Player/PlayerStateBase.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://s5ok5qd2symf
|
||||
|
|
@ -4,11 +4,11 @@ namespace Cirno.Scripts.Components.FSM.Player;
|
|||
|
||||
public partial class Teleporting : PlayerStateBase
|
||||
{
|
||||
public override PlayerState StateId => PlayerState.Init;
|
||||
|
||||
public override PlayerState StateId => PlayerState.Teleporting;
|
||||
|
||||
[Export]
|
||||
private PlayerAnimationProvider _animationProvider;
|
||||
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
_animationProvider.PlayTeleportAnimation();
|
||||
|
|
@ -16,16 +16,16 @@ public partial class Teleporting : PlayerStateBase
|
|||
|
||||
public override void ExitState()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/FSM/PlayerArea2DModule.cs.uid
Normal file
1
Scripts/Components/FSM/PlayerArea2DModule.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bnerroq14m4ds
|
||||
10
Scripts/Components/FSM/PlayerFSMProxy.cs
Normal file
10
Scripts/Components/FSM/PlayerFSMProxy.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM;
|
||||
|
||||
public partial class PlayerFSMProxy : CharacterBody2D
|
||||
{
|
||||
[Export] public PlayerStateMachine PlayerFSM { get; private set; }
|
||||
[Export] public InteractionController InteractionController { get; private set; }
|
||||
}
|
||||
1
Scripts/Components/FSM/PlayerFSMProxy.cs.uid
Normal file
1
Scripts/Components/FSM/PlayerFSMProxy.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d2ubk5gucny6s
|
||||
|
|
@ -13,11 +13,11 @@ public partial class GameManager : Node2D
|
|||
public static GameManager Instance { get; private set; }
|
||||
private Hud _hud;
|
||||
|
||||
private PlayerStateMachine _player;
|
||||
private PlayerFSMProxy _player;
|
||||
|
||||
public GameState GameState { get; private set; }
|
||||
|
||||
public PlayerStateMachine Player => _player;
|
||||
public PlayerStateMachine Player => _player.PlayerFSM;
|
||||
|
||||
private Node2D _cameraTarget;
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ public partial class GameManager : Node2D
|
|||
|
||||
[Signal]
|
||||
public delegate void PlayerRespawnedEventHandler();
|
||||
|
||||
|
||||
public Vector2 LastCheckpointPosition { get; set; }
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
|
|
@ -110,7 +110,7 @@ public partial class GameManager : Node2D
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (GameState is GameState.Paused && Input.IsActionJustPressed(PauseActionName))
|
||||
|
|
@ -160,7 +160,7 @@ public partial class GameManager : Node2D
|
|||
if (_player != null) return;
|
||||
|
||||
//_player = this.CreateChild<PlayerMovement>(PlayerTemplate, PlayerSpawnMarker.Position );
|
||||
_player = PlayerTemplate.Instantiate<PlayerStateMachine>();
|
||||
_player = PlayerTemplate.Instantiate<PlayerFSMProxy>();
|
||||
|
||||
this.CallDeferred("add_child", _player);
|
||||
_player.Transform = this.GlobalTransform;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue