From cd9e6da4e9b57c054c2006eb677562d778b21cbc Mon Sep 17 00:00:00 2001 From: Minimata Date: Mon, 28 Jul 2025 18:51:51 +0200 Subject: [PATCH] trying with cooldown --- player_controller/PlayerController.tscn | 17 +++++- player_controller/Scripts/PlayerController.cs | 59 ++++++++++++------- 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index 3ab779e..0f8e42b 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -187,7 +187,7 @@ wait_time = 0.2 one_shot = true [node name="DashCooldown" type="Timer" parent="."] -wait_time = 0.2 +wait_time = 2.0 one_shot = true [node name="TimeScaleAimInAir" type="Timer" parent="."] @@ -246,20 +246,31 @@ custom_minimum_size = Vector2(1920, 1080) offset_right = 1919.0 offset_bottom = 1080.0 -[node name="CenterIcon" type="TextureRect" parent="UI/CenterContainer"] +[node name="VBoxContainer" type="VBoxContainer" parent="UI/CenterContainer"] +layout_mode = 2 + +[node name="Container" type="CenterContainer" parent="UI/CenterContainer/VBoxContainer"] +layout_mode = 2 + +[node name="CenterIcon" type="TextureRect" parent="UI/CenterContainer/VBoxContainer/Container"] material = SubResource("CanvasItemMaterial_2q0ik") custom_minimum_size = Vector2(5, 5) layout_mode = 2 texture = ExtResource("32_lgpc8") expand_mode = 1 -[node name="DashIndicator" type="TextureRect" parent="UI/CenterContainer"] +[node name="DashIndicator" type="TextureRect" parent="UI/CenterContainer/VBoxContainer/Container"] unique_name_in_owner = true material = SubResource("CanvasItemMaterial_2q0ik") layout_mode = 2 texture = ExtResource("32_lgpc8") expand_mode = 1 +[node name="DashCooldownIndicator" type="ColorRect" parent="UI/CenterContainer/VBoxContainer"] +unique_name_in_owner = true +custom_minimum_size = Vector2(100, 10) +layout_mode = 2 + [node name="StateChart" type="Node" parent="."] script = ExtResource("25_wv70j") metadata/_custom_type_script = "uid://couw105c3bde4" diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index 5a4285b..5456235 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -25,6 +25,7 @@ public partial class PlayerController : CharacterBody3D public WallHugSystem WallHugSystem; public PlayerUi PlayerUi; public TextureRect DashIndicator; + public ColorRect DashCooldownIndicator; private bool _movementEnabled = true; @@ -66,6 +67,7 @@ public partial class PlayerController : CharacterBody3D public Curve DashTimeDilationCurve { get; set; } private bool _canDash = true; + private bool _isDashOnCooldown = false; private int _empoweredActionsLeft; public int EmpoweredActionsLeft { @@ -113,6 +115,8 @@ public partial class PlayerController : CharacterBody3D TweenQueueSystem = GetNode("TweenQueueSystem"); PlayerUi = GetNode("UI"); DashIndicator = GetNode("%DashIndicator"); + DashCooldownIndicator = GetNode("%DashCooldownIndicator"); + DashCooldownIndicator.Visible = false; // Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D; @@ -249,32 +253,40 @@ public partial class PlayerController : CharacterBody3D _empowerOn.StateEntered += OnEmpowerStarted; _empowerOn.StateProcessing += HandleEmpower; - _empowerTimeDownscale.Timeout += EmpowerStopped; + _empowerTimeDownscale.Timeout += EmpowerTimerTimeout; + _dashCooldownTimer.Timeout += ResetDashes; + } + + public void ResetDashes() + { + _isDashOnCooldown = false; + DashCooldownIndicator.Visible = false; } public void OnEmpowerStarted() { _empowerTimeDownscale.Start(); - _isActionPerfectlyTimed = true; - Engine.SetTimeScale(0.1f); } public void HandleEmpower(float delta) { var progress = (float) (_empowerTimeDownscale.TimeLeft / _empowerTimeDownscale.WaitTime); - _isActionPerfectlyTimed = progress < PerfectlyTimedActionTimer; - var indicatorColor = _isActionPerfectlyTimed ? Colors.Green : Colors.White; DashIndicator.SetCustomMinimumSize(Vector2.One * DashIndicatorStartSize * progress); - DashIndicator.SetModulate(indicatorColor); DashIndicator.Visible = true; } + public void EmpowerTimerTimeout() + { + EmpowerStopped(); + _isDashOnCooldown = true; + _dashCooldownTimer.Start(); + } + public void EmpowerStopped() { DashIndicator.Visible = false; - ResetTimeScale(); - _isActionPerfectlyTimed = false; + _playerState.SendEvent("empower_released"); } /////////////////////////// @@ -354,10 +366,6 @@ public partial class PlayerController : CharacterBody3D { _playerState.SendEvent("dash"); PerformDash(_empowerOn.Active); - } - public void OnInputThrowPressed() - { - } public void OnInputEmpowerDown() { @@ -416,13 +424,12 @@ public partial class PlayerController : CharacterBody3D public bool CanPerformEmpoweredAction() { - return EmpoweredActionsLeft > 0; + return !_isDashOnCooldown; } public void PerformEmpoweredAction() { _isWallJumpAvailable = true; - _dashCooldownTimer.Start(); if (!_isActionPerfectlyTimed) { @@ -463,17 +470,17 @@ public partial class PlayerController : CharacterBody3D var effectiveJumpDirection = jumpDirection ?? Vector3.Up; var jumpVector = (effectiveJumpDirection.Normalized() + Vector3.Up).Normalized(); - var proportionOfTimeGone = _timeAfterDashingTimer.TimeLeft / _timeAfterDashingTimer.WaitTime; - var actualBoost = 1 + MaxJumpBoostAfterDashing * proportionOfTimeGone; - var makeItDouble = actualBoost > 1; - if (makeItDouble && jumpType == MoveSystem.JumpTypes.SimpleJump) - jumpType = MoveSystem.JumpTypes.DoubleJump; // convert simple jump to double if done right after a dash - _timeAfterDashingTimer.Stop(); + // var proportionOfTimeGone = _timeAfterDashingTimer.TimeLeft / _timeAfterDashingTimer.WaitTime; + // var actualBoost = 1 + MaxJumpBoostAfterDashing * proportionOfTimeGone; + // var makeItDouble = actualBoost > 1; + // if (makeItDouble && jumpType == MoveSystem.JumpTypes.SimpleJump) + // jumpType = MoveSystem.JumpTypes.DoubleJump; // convert simple jump to double if done right after a dash + // _timeAfterDashingTimer.Stop(); bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight(); bool isPlayerDead = HealthSystem.IsDead(); if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead) - MoveSystem.Jump(jumpType, jumpVector, (float) actualBoost); + MoveSystem.Jump(jumpType, jumpVector); } // Mantling @@ -539,7 +546,8 @@ public partial class PlayerController : CharacterBody3D } public void OnDashEnded() { - // _playerState.SendEvent("enable_double_jump"); // Allow for double jump after dash -- OP ? + _playerState.SendEvent("empower_down"); + // Regular dash if (WeaponSystem.InHandState.Active) { @@ -797,6 +805,13 @@ public partial class PlayerController : CharacterBody3D /////////////////////////// public override void _PhysicsProcess(double delta) { + if (_isDashOnCooldown) + { + var progress = (float) (_dashCooldownTimer.TimeLeft / _dashCooldownTimer.WaitTime); + DashCooldownIndicator.SetCustomMinimumSize(new Vector2(100 * progress, 10)); + DashCooldownIndicator.Visible = true; + } + TweenQueueSystem.ProcessTweens(); LookAround();