trying with cooldown

This commit is contained in:
2025-07-28 18:51:51 +02:00
parent 77c62c74de
commit cd9e6da4e9
2 changed files with 51 additions and 25 deletions

View File

@ -187,7 +187,7 @@ wait_time = 0.2
one_shot = true one_shot = true
[node name="DashCooldown" type="Timer" parent="."] [node name="DashCooldown" type="Timer" parent="."]
wait_time = 0.2 wait_time = 2.0
one_shot = true one_shot = true
[node name="TimeScaleAimInAir" type="Timer" parent="."] [node name="TimeScaleAimInAir" type="Timer" parent="."]
@ -246,20 +246,31 @@ custom_minimum_size = Vector2(1920, 1080)
offset_right = 1919.0 offset_right = 1919.0
offset_bottom = 1080.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") material = SubResource("CanvasItemMaterial_2q0ik")
custom_minimum_size = Vector2(5, 5) custom_minimum_size = Vector2(5, 5)
layout_mode = 2 layout_mode = 2
texture = ExtResource("32_lgpc8") texture = ExtResource("32_lgpc8")
expand_mode = 1 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 unique_name_in_owner = true
material = SubResource("CanvasItemMaterial_2q0ik") material = SubResource("CanvasItemMaterial_2q0ik")
layout_mode = 2 layout_mode = 2
texture = ExtResource("32_lgpc8") texture = ExtResource("32_lgpc8")
expand_mode = 1 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="."] [node name="StateChart" type="Node" parent="."]
script = ExtResource("25_wv70j") script = ExtResource("25_wv70j")
metadata/_custom_type_script = "uid://couw105c3bde4" metadata/_custom_type_script = "uid://couw105c3bde4"

View File

@ -25,6 +25,7 @@ public partial class PlayerController : CharacterBody3D
public WallHugSystem WallHugSystem; public WallHugSystem WallHugSystem;
public PlayerUi PlayerUi; public PlayerUi PlayerUi;
public TextureRect DashIndicator; public TextureRect DashIndicator;
public ColorRect DashCooldownIndicator;
private bool _movementEnabled = true; private bool _movementEnabled = true;
@ -66,6 +67,7 @@ public partial class PlayerController : CharacterBody3D
public Curve DashTimeDilationCurve { get; set; } public Curve DashTimeDilationCurve { get; set; }
private bool _canDash = true; private bool _canDash = true;
private bool _isDashOnCooldown = false;
private int _empoweredActionsLeft; private int _empoweredActionsLeft;
public int EmpoweredActionsLeft public int EmpoweredActionsLeft
{ {
@ -113,6 +115,8 @@ public partial class PlayerController : CharacterBody3D
TweenQueueSystem = GetNode<TweenQueueSystem>("TweenQueueSystem"); TweenQueueSystem = GetNode<TweenQueueSystem>("TweenQueueSystem");
PlayerUi = GetNode<PlayerUi>("UI"); PlayerUi = GetNode<PlayerUi>("UI");
DashIndicator = GetNode<TextureRect>("%DashIndicator"); DashIndicator = GetNode<TextureRect>("%DashIndicator");
DashCooldownIndicator = GetNode<ColorRect>("%DashCooldownIndicator");
DashCooldownIndicator.Visible = false;
// Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D; // Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D;
@ -249,32 +253,40 @@ public partial class PlayerController : CharacterBody3D
_empowerOn.StateEntered += OnEmpowerStarted; _empowerOn.StateEntered += OnEmpowerStarted;
_empowerOn.StateProcessing += HandleEmpower; _empowerOn.StateProcessing += HandleEmpower;
_empowerTimeDownscale.Timeout += EmpowerStopped; _empowerTimeDownscale.Timeout += EmpowerTimerTimeout;
_dashCooldownTimer.Timeout += ResetDashes;
}
public void ResetDashes()
{
_isDashOnCooldown = false;
DashCooldownIndicator.Visible = false;
} }
public void OnEmpowerStarted() public void OnEmpowerStarted()
{ {
_empowerTimeDownscale.Start(); _empowerTimeDownscale.Start();
_isActionPerfectlyTimed = true;
Engine.SetTimeScale(0.1f);
} }
public void HandleEmpower(float delta) public void HandleEmpower(float delta)
{ {
var progress = (float) (_empowerTimeDownscale.TimeLeft / _empowerTimeDownscale.WaitTime); var progress = (float) (_empowerTimeDownscale.TimeLeft / _empowerTimeDownscale.WaitTime);
_isActionPerfectlyTimed = progress < PerfectlyTimedActionTimer;
var indicatorColor = _isActionPerfectlyTimed ? Colors.Green : Colors.White;
DashIndicator.SetCustomMinimumSize(Vector2.One * DashIndicatorStartSize * progress); DashIndicator.SetCustomMinimumSize(Vector2.One * DashIndicatorStartSize * progress);
DashIndicator.SetModulate(indicatorColor);
DashIndicator.Visible = true; DashIndicator.Visible = true;
} }
public void EmpowerTimerTimeout()
{
EmpowerStopped();
_isDashOnCooldown = true;
_dashCooldownTimer.Start();
}
public void EmpowerStopped() public void EmpowerStopped()
{ {
DashIndicator.Visible = false; DashIndicator.Visible = false;
ResetTimeScale(); _playerState.SendEvent("empower_released");
_isActionPerfectlyTimed = false;
} }
/////////////////////////// ///////////////////////////
@ -354,10 +366,6 @@ public partial class PlayerController : CharacterBody3D
{ {
_playerState.SendEvent("dash"); _playerState.SendEvent("dash");
PerformDash(_empowerOn.Active); PerformDash(_empowerOn.Active);
}
public void OnInputThrowPressed()
{
} }
public void OnInputEmpowerDown() public void OnInputEmpowerDown()
{ {
@ -416,13 +424,12 @@ public partial class PlayerController : CharacterBody3D
public bool CanPerformEmpoweredAction() public bool CanPerformEmpoweredAction()
{ {
return EmpoweredActionsLeft > 0; return !_isDashOnCooldown;
} }
public void PerformEmpoweredAction() public void PerformEmpoweredAction()
{ {
_isWallJumpAvailable = true; _isWallJumpAvailable = true;
_dashCooldownTimer.Start();
if (!_isActionPerfectlyTimed) if (!_isActionPerfectlyTimed)
{ {
@ -463,17 +470,17 @@ public partial class PlayerController : CharacterBody3D
var effectiveJumpDirection = jumpDirection ?? Vector3.Up; var effectiveJumpDirection = jumpDirection ?? Vector3.Up;
var jumpVector = (effectiveJumpDirection.Normalized() + Vector3.Up).Normalized(); var jumpVector = (effectiveJumpDirection.Normalized() + Vector3.Up).Normalized();
var proportionOfTimeGone = _timeAfterDashingTimer.TimeLeft / _timeAfterDashingTimer.WaitTime; // var proportionOfTimeGone = _timeAfterDashingTimer.TimeLeft / _timeAfterDashingTimer.WaitTime;
var actualBoost = 1 + MaxJumpBoostAfterDashing * proportionOfTimeGone; // var actualBoost = 1 + MaxJumpBoostAfterDashing * proportionOfTimeGone;
var makeItDouble = actualBoost > 1; // var makeItDouble = actualBoost > 1;
if (makeItDouble && jumpType == MoveSystem.JumpTypes.SimpleJump) // if (makeItDouble && jumpType == MoveSystem.JumpTypes.SimpleJump)
jumpType = MoveSystem.JumpTypes.DoubleJump; // convert simple jump to double if done right after a dash // jumpType = MoveSystem.JumpTypes.DoubleJump; // convert simple jump to double if done right after a dash
_timeAfterDashingTimer.Stop(); // _timeAfterDashingTimer.Stop();
bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight(); bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight();
bool isPlayerDead = HealthSystem.IsDead(); bool isPlayerDead = HealthSystem.IsDead();
if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead) if (!doesCapsuleHaveCrouchingHeight && !isPlayerDead)
MoveSystem.Jump(jumpType, jumpVector, (float) actualBoost); MoveSystem.Jump(jumpType, jumpVector);
} }
// Mantling // Mantling
@ -539,7 +546,8 @@ public partial class PlayerController : CharacterBody3D
} }
public void OnDashEnded() public void OnDashEnded()
{ {
// _playerState.SendEvent("enable_double_jump"); // Allow for double jump after dash -- OP ? _playerState.SendEvent("empower_down");
// Regular dash // Regular dash
if (WeaponSystem.InHandState.Active) if (WeaponSystem.InHandState.Active)
{ {
@ -797,6 +805,13 @@ public partial class PlayerController : CharacterBody3D
/////////////////////////// ///////////////////////////
public override void _PhysicsProcess(double delta) 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(); TweenQueueSystem.ProcessTweens();
LookAround(); LookAround();