mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 13:05:54 +00:00
Changed player to new one
This commit is contained in:
parent
60ab375572
commit
1c1436a539
27 changed files with 323 additions and 87 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Threading.Tasks;
|
||||
using Cirno.Scripts.Components.FSM;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Activables;
|
||||
|
|
@ -10,16 +11,19 @@ public partial class LevelTeleporter : Teleporter
|
|||
[Export]
|
||||
public string LevelPath {get; private set;}
|
||||
|
||||
protected override async Task Teleport(PlayerMovement player)
|
||||
protected override async Task Teleport(PlayerStateMachine player)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(LevelPath)) return;
|
||||
player.RequestMovementDisable(true);
|
||||
//player.RequestMovementDisable(true);
|
||||
player.SetState((int)PlayerState.Cutscene);
|
||||
|
||||
await TweenPlayer(player);
|
||||
|
||||
_particles.Emitting = true;
|
||||
|
||||
await player.Teleport();
|
||||
//await player.Teleport();
|
||||
player.SetState((int)PlayerState.UnTeleporting);
|
||||
await Task.Delay((int)(0.6f * 1000));
|
||||
|
||||
await Task.Delay((int)(TeleportAnimationLength * 1000));
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ public partial class PlayerMover : ChainActivable
|
|||
|
||||
private async Task MovePlayer()
|
||||
{
|
||||
_gameManager.Player.RequestMovementDisable(true);
|
||||
//_gameManager.Player.RequestMovementDisable(true);
|
||||
_gameManager.Player.SetState((int)PlayerState.Cutscene);
|
||||
|
||||
Tween tween = GetTree().CreateTween();
|
||||
tween.SetEase(EaseType);
|
||||
|
|
@ -46,7 +47,8 @@ public partial class PlayerMover : ChainActivable
|
|||
// Wait for the tween to finish
|
||||
await ToSignal(tween, "finished");
|
||||
|
||||
_gameManager.Player.RequestMovementDisable(false);
|
||||
//_gameManager.Player.RequestMovementDisable(false);
|
||||
_gameManager.Player.SetState((int)PlayerState.Cutscene);
|
||||
|
||||
ActivateTargets();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Cirno.Scripts.Components.FSM;
|
||||
using Godot;
|
||||
using GTweensGodot.Extensions;
|
||||
|
||||
|
|
@ -115,7 +116,7 @@ private AudioStreamPlayer2D _teleportEndSound;
|
|||
|
||||
private void _on_body_entered(CharacterBody2D area)
|
||||
{
|
||||
if (area is not PlayerMovement player) return;
|
||||
if (area is not PlayerStateMachine player) return;
|
||||
|
||||
if (!IsPrimed)
|
||||
{
|
||||
|
|
@ -132,10 +133,11 @@ private AudioStreamPlayer2D _teleportEndSound;
|
|||
_ = Teleport(player);
|
||||
}
|
||||
|
||||
protected virtual async Task Teleport(PlayerMovement player)
|
||||
protected virtual async Task Teleport(PlayerStateMachine player)
|
||||
{
|
||||
if (Target is null) return;
|
||||
player.RequestMovementDisable(true);
|
||||
//player.RequestMovementDisable(true);
|
||||
player.SetState((int)PlayerState.Cutscene);
|
||||
|
||||
await TweenPlayer(player);
|
||||
|
||||
|
|
@ -144,16 +146,22 @@ private AudioStreamPlayer2D _teleportEndSound;
|
|||
//_particles.Emitting = true;
|
||||
FireParticles();
|
||||
|
||||
await player.Teleport();
|
||||
//await player.Teleport();
|
||||
player.SetState((int)PlayerState.Teleporting);
|
||||
await Task.Delay((int)(0.6f * 1000));
|
||||
|
||||
await Task.Delay((int)(TeleportAnimationLength * 1000));
|
||||
|
||||
Target.PrepareForReceiving();
|
||||
player.GlobalPosition = Target.GlobalPosition + TeleportOffset;
|
||||
Target.PlayTeleportEndSound();
|
||||
await player.UnTeleport();
|
||||
//await player.UnTeleport();
|
||||
|
||||
player.RequestMovementDisable(false);
|
||||
player.SetState((int)PlayerState.UnTeleporting);
|
||||
await Task.Delay((int)(0.6f * 1000));
|
||||
|
||||
//player.RequestMovementDisable(false);
|
||||
player.SetState((int)PlayerState.Active);
|
||||
}
|
||||
|
||||
public void PlayTeleportStartSound()
|
||||
|
|
@ -166,7 +174,7 @@ private AudioStreamPlayer2D _teleportEndSound;
|
|||
_teleportEndSound?.Play();
|
||||
}
|
||||
|
||||
protected async Task TweenPlayer(PlayerMovement player)
|
||||
protected async Task TweenPlayer(PlayerStateMachine player)
|
||||
{
|
||||
await player.TweenGlobalPosition(GlobalPosition + new Vector2(0, -4f), TeleportAnimationLength).PlayAsync(CancellationToken.None);
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,8 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
|||
public void AssumeControl()
|
||||
{
|
||||
GameManager.Instance.CameraTargetObject(_parent);
|
||||
GameManager.Instance.Player.RequestMovementDisable(true);
|
||||
//GameManager.Instance.Player.RequestMovementDisable(true);
|
||||
GameManager.Instance.Player.SetState((int)PlayerState.Controlling);
|
||||
|
||||
_previousAiState = _actorAi.Ai;
|
||||
_actorAi.Ai = AiState.Controlled;
|
||||
|
|
@ -92,7 +93,8 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
|||
_actorAi.Ai = _previousAiState;
|
||||
|
||||
GameManager.Instance.CameraTargetPlayer();
|
||||
GameManager.Instance.Player.RequestMovementDisable(false);
|
||||
//GameManager.Instance.Player.RequestMovementDisable(false);
|
||||
GameManager.Instance.Player.SetState((int)PlayerState.Active);
|
||||
|
||||
DamageReceiver.BulletGroup = BulletOwner.Enemy;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,33 +6,33 @@ public partial class KeyboardInputProvider : InputProvider
|
|||
{
|
||||
[ExportCategory("Movement")]
|
||||
[Export]
|
||||
public string LeftAxisName { get; private set; } = "left";
|
||||
public StringName LeftAxisName { get; private set; } = "left";
|
||||
[Export]
|
||||
public string RightAxisName { get; private set; } = "right";
|
||||
public StringName RightAxisName { get; private set; } = "right";
|
||||
[Export]
|
||||
public string UpAxisName { get; private set; } = "up";
|
||||
public StringName UpAxisName { get; private set; } = "up";
|
||||
[Export]
|
||||
public string DownAxisName { get; private set; } = "down";
|
||||
public StringName DownAxisName { get; private set; } = "down";
|
||||
|
||||
[ExportCategory("Aiming")]
|
||||
[Export]
|
||||
public string LeftAimName { get; private set; } = "aim_left";
|
||||
public StringName LeftAimName { get; private set; } = "aim_left";
|
||||
[Export]
|
||||
public string RightAimName { get; private set; } = "aim_right";
|
||||
public StringName RightAimName { get; private set; } = "aim_right";
|
||||
[Export]
|
||||
public string UpAimName { get; private set; } = "aim_up";
|
||||
public StringName UpAimName { get; private set; } = "aim_up";
|
||||
[Export]
|
||||
public string DownAimName { get; private set; } = "aim_down";
|
||||
public StringName DownAimName { get; private set; } = "aim_down";
|
||||
|
||||
[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";
|
||||
[Export] private string _inventoryActionName = "inventory";
|
||||
[Export] private string _pauseActionName = "pause";
|
||||
[Export] private StringName _shootActionName = "shoot";
|
||||
[Export] private StringName _useActionName = "Use";
|
||||
[Export] private StringName _scanActionName = "scan";
|
||||
[Export] private StringName _strafeActionName = "strafe";
|
||||
[Export] private StringName _nextWeaponActionName = "next_weapon";
|
||||
[Export] private StringName _previousWeaponActionName = "previous_weapon";
|
||||
[Export] private StringName _inventoryActionName = "inventory";
|
||||
[Export] private StringName _pauseActionName = "pause";
|
||||
|
||||
public override Vector2 GetMovementInput()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,21 +16,33 @@ public partial class PlayerAnimationProvider : Node2D
|
|||
|
||||
[ExportCategory("Animation Names")]
|
||||
[Export]
|
||||
public string WalkRightAnimationName {get; private set;} = "walk_right";
|
||||
public StringName WalkRightAnimationName {get; private set;} = "walk_right";
|
||||
|
||||
[Export]
|
||||
public string WalkLeftAnimationName {get; private set;} = "walk_left";
|
||||
public StringName WalkLeftAnimationName {get; private set;} = "walk_left";
|
||||
[Export]
|
||||
public string WalkDownAnimationName {get; private set;} = "walk_down";
|
||||
public StringName WalkDownAnimationName {get; private set;} = "walk_down";
|
||||
[Export]
|
||||
public string WalkUpAnimationName {get; private set;} = "walk_up";
|
||||
public StringName WalkUpAnimationName {get; private set;} = "walk_up";
|
||||
|
||||
[ExportCategory("Shaders")]
|
||||
[Export] public ShaderMaterial BlinkMaterial {get; private set;}
|
||||
|
||||
[Export] public StringName BlinkShaderPropertyName { get; private set; } = new StringName("blink_intensity");
|
||||
[Export] public StringName BlinkShaderPropertyName { get; private set; } = new("blink_intensity");
|
||||
[Export] public StringName TeleportProgressPropertyName { get; private set; } = new("teleport_progress");
|
||||
[Export] public StringName ScanlineDensityPropertyName { get; private set; } = new("scanline_density");
|
||||
|
||||
private GTween _blinkTween;
|
||||
|
||||
public void ShowSprite()
|
||||
{
|
||||
_animatedSprite.Show();
|
||||
}
|
||||
|
||||
public void HideSprite()
|
||||
{
|
||||
_animatedSprite.Hide();
|
||||
}
|
||||
|
||||
public void SetAnimation(Vector2 velocity)
|
||||
{
|
||||
|
|
@ -78,6 +90,38 @@ public partial class PlayerAnimationProvider : Node2D
|
|||
_blinkTween.Play();
|
||||
}
|
||||
|
||||
public void PlayTeleportAnimation()
|
||||
{
|
||||
if (BlinkMaterial == null) return;
|
||||
_animatedSprite.Material = BlinkMaterial;
|
||||
var material = ((ShaderMaterial)_animatedSprite.Material);
|
||||
_blinkTween?.Kill();
|
||||
_blinkTween = GTweenSequenceBuilder.New()
|
||||
.Append(material.TweenPropertyFloat(TeleportProgressPropertyName, 0f, 0f))
|
||||
.Append(material.TweenPropertyFloat(ScanlineDensityPropertyName, 0f, 0f))
|
||||
.Append(material.TweenPropertyFloat(ScanlineDensityPropertyName,50f,0.5f))
|
||||
.Join(material.TweenPropertyFloat(TeleportProgressPropertyName, 1f,0.5f))
|
||||
.Build();
|
||||
|
||||
_blinkTween.Play();
|
||||
}
|
||||
|
||||
public void PlayUnteleportAnimation()
|
||||
{
|
||||
if (BlinkMaterial == null) return;
|
||||
_animatedSprite.Material = BlinkMaterial;
|
||||
var material = ((ShaderMaterial)_animatedSprite.Material);
|
||||
_blinkTween?.Kill();
|
||||
_blinkTween = GTweenSequenceBuilder.New()
|
||||
.Append(material.TweenPropertyFloat(TeleportProgressPropertyName, 1f, 0f))
|
||||
.Append(material.TweenPropertyFloat(ScanlineDensityPropertyName, 50f, 0f))
|
||||
.Append(material.TweenPropertyFloat(ScanlineDensityPropertyName,0f,0.5f))
|
||||
.Join(material.TweenPropertyFloat(TeleportProgressPropertyName, 0f,0.5f))
|
||||
.Build();
|
||||
|
||||
_blinkTween.Play();
|
||||
}
|
||||
|
||||
private void SetShaderTeleportProgress(float value)
|
||||
{
|
||||
((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("teleport_progress", value);
|
||||
|
|
@ -103,4 +147,6 @@ public partial class PlayerAnimationProvider : Node2D
|
|||
{
|
||||
_shieldParticles.Emitting = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -8,9 +8,21 @@ public partial class PlayerHitboxSpriteProvider : Node2D
|
|||
public AnimatedSprite2D Hitbox { get; private set; }
|
||||
[Export]
|
||||
public AnimatedSprite2D Circle { get; private set; }
|
||||
[Export]
|
||||
public AnimatedSprite2D Square { get; private set; }
|
||||
|
||||
[Export] public float RotationSpeed { get; private set; } = 10f;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!Visible) return;
|
||||
Circle.Rotate((float)(RotationSpeed * delta));
|
||||
Square.Rotate((float)(-RotationSpeed * delta));
|
||||
}
|
||||
|
||||
public void SetVisibility(bool isVisible)
|
||||
{
|
||||
if (isVisible == Visible) return;
|
||||
if (isVisible)
|
||||
{
|
||||
Show();
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public partial class Active : PlayerFSMState
|
|||
// enable sprite
|
||||
// enable crosshair
|
||||
_crosshairProvider.Show();
|
||||
|
||||
_animationProvider.ShowSprite();
|
||||
_damageReceiver.Enabled = true;
|
||||
_activationProvider.Enabled = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@ public partial class Cutscene : PlayerFSMState
|
|||
|
||||
public override void ExitState()
|
||||
{
|
||||
|
||||
_animationProvider.SetAnimation(Vector2.Zero);
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
|
||||
_animationProvider.SetAnimation(_stateMachine.Velocity);
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ public partial class Teleporting : PlayerFSMState
|
|||
|
||||
public override void EnterState()
|
||||
{
|
||||
|
||||
_animationProvider.PlayTeleportAnimation();
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
|
|
|
|||
29
Scripts/Components/FSM/Player/UnTeleporting.cs
Normal file
29
Scripts/Components/FSM/Player/UnTeleporting.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.FSM.Player;
|
||||
|
||||
public partial class UnTeleporting : PlayerFSMState
|
||||
{
|
||||
[Export]
|
||||
private PlayerAnimationProvider _animationProvider;
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
_animationProvider.PlayUnteleportAnimation();
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsProcessState(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
1
Scripts/Components/FSM/Player/UnTeleporting.cs.uid
Normal file
1
Scripts/Components/FSM/Player/UnTeleporting.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://br2ev58gwuvu4
|
||||
|
|
@ -3,6 +3,7 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Cirno.Scripts;
|
||||
using Cirno.Scripts.Components.FSM;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot.Collections;
|
||||
using Cirno.Scripts.Utils;
|
||||
|
|
@ -12,11 +13,11 @@ public partial class GameManager : Node2D
|
|||
public static GameManager Instance { get; private set; }
|
||||
private Hud _hud;
|
||||
|
||||
private PlayerMovement _player;
|
||||
private PlayerStateMachine _player;
|
||||
|
||||
public GameState GameState { get; private set; }
|
||||
|
||||
public PlayerMovement Player => _player;
|
||||
public PlayerStateMachine Player => _player;
|
||||
|
||||
private Node2D _cameraTarget;
|
||||
|
||||
|
|
@ -132,17 +133,17 @@ public partial class GameManager : Node2D
|
|||
|
||||
if (_player != null && _hud != null)
|
||||
{
|
||||
_player.HealthChanged += (newHealth, maxHealth) => _hud.UpdateHealth(newHealth, maxHealth);
|
||||
|
||||
_player.ShieldChanged += (newShield, maxShield) => _hud.UpdateShield(newShield, maxShield);
|
||||
|
||||
_player.InteractableAreaEntered += (interactable) => _hud.UpdateInteractable(interactable);
|
||||
|
||||
_player.Death += () =>
|
||||
{
|
||||
// Show Game Over
|
||||
_hud.ShowGameOver();
|
||||
};
|
||||
// _player.HealthChanged += (newHealth, maxHealth) => _hud.UpdateHealth(newHealth, maxHealth);
|
||||
//
|
||||
// _player.ShieldChanged += (newShield, maxShield) => _hud.UpdateShield(newShield, maxShield);
|
||||
//
|
||||
// _player.InteractableAreaEntered += (interactable) => _hud.UpdateInteractable(interactable);
|
||||
//
|
||||
// _player.Death += () =>
|
||||
// {
|
||||
// // Show Game Over
|
||||
// _hud.ShowGameOver();
|
||||
// };
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -159,7 +160,7 @@ public partial class GameManager : Node2D
|
|||
if (_player != null) return;
|
||||
|
||||
//_player = this.CreateChild<PlayerMovement>(PlayerTemplate, PlayerSpawnMarker.Position );
|
||||
_player = PlayerTemplate.Instantiate<PlayerMovement>();
|
||||
_player = PlayerTemplate.Instantiate<PlayerStateMachine>();
|
||||
|
||||
this.CallDeferred("add_child", _player);
|
||||
_player.Transform = this.GlobalTransform;
|
||||
|
|
|
|||
|
|
@ -88,7 +88,8 @@ public partial class Hud : CanvasLayer
|
|||
|
||||
public void HideGameOver()
|
||||
{
|
||||
|
||||
_gameOverPanel.Hide();
|
||||
_playerDead = false;
|
||||
}
|
||||
|
||||
public void UpdateHealth(float newHealth, float maxHealth)
|
||||
|
|
|
|||
|
|
@ -585,6 +585,7 @@ public enum PlayerState
|
|||
Active,
|
||||
Cutscene,
|
||||
Teleporting,
|
||||
UnTeleporting,
|
||||
Controlling,
|
||||
Dead,
|
||||
}
|
||||
|
|
@ -30,16 +30,18 @@ public partial class ControlEnemyEvent : EventResource
|
|||
if (_parent.GetNode<Node2D>(Target) is Enemy enemy)
|
||||
{
|
||||
_gameManager.CameraTargetObject(enemy);
|
||||
_gameManager.Player.RequestMovementDisable(true);
|
||||
GameManager.Instance.Player.SetState((int)PlayerState.Controlling);
|
||||
// _gameManager.Player.RequestMovementDisable(true);
|
||||
enemy.AssumeControl();
|
||||
if (_gameManager.Player.WingsSprite != null)
|
||||
{
|
||||
var sprite = new Sprite2D();
|
||||
sprite.SetTexture(_gameManager.Player.WingsSprite);
|
||||
//sprite.GlobalPosition = enemy.GlobalPosition;
|
||||
sprite.SetZIndex(1);
|
||||
enemy.CallDeferred("add_child", sprite);
|
||||
}
|
||||
// TODO: Do this on the enemy as a module instead
|
||||
// if (_gameManager.Player.WingsSprite != null)
|
||||
// {
|
||||
// var sprite = new Sprite2D();
|
||||
// sprite.SetTexture(_gameManager.Player.WingsSprite);
|
||||
// //sprite.GlobalPosition = enemy.GlobalPosition;
|
||||
// sprite.SetZIndex(1);
|
||||
// enemy.CallDeferred("add_child", sprite);
|
||||
// }
|
||||
}
|
||||
|
||||
_isComplete = true;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ public partial class MovePlayerEvent : EventResource
|
|||
|
||||
protected async Task MovePlayer()
|
||||
{
|
||||
_gameManager.Player.RequestMovementDisable(true);
|
||||
GameManager.Instance.Player.SetState((int)PlayerState.Cutscene);
|
||||
//_gameManager.Player.RequestMovementDisable(true);
|
||||
|
||||
Tween tween = _gameManager.GetTree().CreateTween();
|
||||
tween.SetEase(EaseType);
|
||||
|
|
@ -45,7 +46,8 @@ public partial class MovePlayerEvent : EventResource
|
|||
// Wait for the tween to finish
|
||||
await ToSignal(tween, "finished");
|
||||
|
||||
_gameManager.Player.RequestMovementDisable(false);
|
||||
GameManager.Instance.Player.SetState((int)PlayerState.Active);
|
||||
//_gameManager.Player.RequestMovementDisable(false);
|
||||
|
||||
_isComplete = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public partial class UpdateCheckPointEvent : EventResource
|
|||
public override void Start(Node2D parent)
|
||||
{
|
||||
_gameManager.LastCheckpointPosition = parent.GetNode<Node2D>(Target).GlobalPosition;
|
||||
_gameManager.Player.LastCheckPointPosition = parent.GetNode<Node2D>(Target).GlobalPosition;
|
||||
// _gameManager.Player.LastCheckPointPosition = parent.GetNode<Node2D>(Target).GlobalPosition;
|
||||
}
|
||||
|
||||
public override void UpdateEvent(double delta)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue