diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index 58b3bf4..47bcef0 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=44 format=3 uid="uid://bei4nhkf8lwdo"] +[gd_scene load_steps=45 format=3 uid="uid://bei4nhkf8lwdo"] [ext_resource type="Script" uid="uid://bbbrf5ckydfna" path="res://player_controller/Scripts/PlayerController.cs" id="1_poq2x"] [ext_resource type="Curve" uid="uid://c2a8soliruf35" path="res://systems/dash/dash_time_dilation.tres" id="2_2q0ik"] @@ -14,6 +14,7 @@ [ext_resource type="PackedScene" uid="uid://wq1okogkhc5l" path="res://systems/mantle/mantle_system.tscn" id="8_qu4wy"] [ext_resource type="Resource" uid="uid://7wm8ywvujwf" path="res://systems/inputs/base_mode/aim_cancel.tres" id="9_5p2qc"] [ext_resource type="Script" uid="uid://bt0xv2q8iv1vn" path="res://player_controller/Scripts/Gravity.cs" id="9_lsueh"] +[ext_resource type="Resource" uid="uid://bebstkm608wxx" path="res://systems/inputs/base_mode/aim_pressed.tres" id="9_nob5r"] [ext_resource type="Resource" uid="uid://bdit2jy5gbpts" path="res://systems/inputs/base_mode/jump.tres" id="10_4u7i3"] [ext_resource type="Script" uid="uid://g8idirw62qe0" path="res://player_controller/Scripts/Bobbing.cs" id="10_7wk1w"] [ext_resource type="Resource" uid="uid://b334rau1yxmm7" path="res://systems/inputs/base_mode/empower_down.tres" id="10_nodcl"] @@ -53,6 +54,7 @@ script = ExtResource("1_poq2x") TimeScaleAimInAir = 0.15 MaxJumpBoostAfterDashing = 0.7 MaxNumberOfDashActions = 2 +PerfectlyTimedActionTimer = 0.3 BasicDashStrength = 15.0 DashTimeDilationCurve = ExtResource("2_2q0ik") @@ -63,6 +65,7 @@ move = ExtResource("17_h6vvl") rotate_y = ExtResource("4_rxwoh") rotate_floorplane = ExtResource("5_4u7i3") aim_down = ExtResource("8_obsfv") +aim_pressed = ExtResource("9_nob5r") aim_released = ExtResource("8_lhb11") empower_down = ExtResource("10_nodcl") empower_released = ExtResource("11_ruloh") @@ -195,6 +198,10 @@ ignore_time_scale = true wait_time = 0.3 one_shot = true +[node name="EmpowerTimeDownscale" type="Timer" parent="."] +one_shot = true +ignore_time_scale = true + [node name="StateChartDebugger" parent="." instance=ExtResource("24_q5h8a")] offset_left = 1524.0 offset_top = 1.0 @@ -262,6 +269,12 @@ script = ExtResource("27_infe6") script = ExtResource("26_infe6") initial_state = NodePath("Off") +[node name="ToOff" type="Node" parent="StateChart/Root/Aim"] +script = ExtResource("28_n7qhm") +to = NodePath("../Off") +event = &"aim_released" +delay_in_seconds = "0.0" + [node name="Off" type="Node" parent="StateChart/Root/Aim"] script = ExtResource("27_34snm") @@ -274,12 +287,15 @@ delay_in_seconds = "0.0" [node name="On" type="Node" parent="StateChart/Root/Aim"] script = ExtResource("27_34snm") -[node name="ToOff" type="Node" parent="StateChart/Root/Aim/On"] +[node name="ToCancel" type="Node" parent="StateChart/Root/Aim/On"] script = ExtResource("28_n7qhm") -to = NodePath("../../Off") -event = &"aim_released" +to = NodePath("../../Canceled") +event = &"cancel_aim" delay_in_seconds = "0.0" +[node name="Canceled" type="Node" parent="StateChart/Root/Aim"] +script = ExtResource("27_34snm") + [node name="Empower" type="Node" parent="StateChart/Root"] script = ExtResource("26_infe6") initial_state = NodePath("Off") @@ -326,12 +342,36 @@ script = ExtResource("26_infe6") initial_state = NodePath("InHand") metadata/_custom_type_script = "uid://c1vp0ojjvaby1" +[node name="ToPlanted" type="Node" parent="StateChart/Root/WeaponState"] +script = ExtResource("28_n7qhm") +to = NodePath("../Planted") +event = &"plant_weapon" +delay_in_seconds = "0.0" + +[node name="ToHand" type="Node" parent="StateChart/Root/WeaponState"] +script = ExtResource("28_n7qhm") +to = NodePath("../InHand") +event = &"recover_weapond" +delay_in_seconds = "0.0" + [node name="InHand" type="Node" parent="StateChart/Root/WeaponState"] script = ExtResource("27_34snm") +[node name="ToThrown" type="Node" parent="StateChart/Root/WeaponState/InHand"] +script = ExtResource("28_n7qhm") +to = NodePath("../../Flying") +event = &"throw" +delay_in_seconds = "0.0" + [node name="Flying" type="Node" parent="StateChart/Root/WeaponState"] script = ExtResource("27_34snm") +[node name="ToPlanted" type="Node" parent="StateChart/Root/WeaponState/Flying"] +script = ExtResource("28_n7qhm") +to = NodePath("../../Planted") +event = &"plant_weapon" +delay_in_seconds = "0.0" + [node name="Planted" type="Node" parent="StateChart/Root/WeaponState"] script = ExtResource("27_34snm") @@ -517,6 +557,7 @@ delay_in_seconds = "0.0" [connection signal="input_aim_canceled" from="InputController" to="." method="OnInputAimCanceled"] [connection signal="input_aim_down" from="InputController" to="." method="OnInputAimDown"] +[connection signal="input_aim_pressed" from="InputController" to="." method="OnInputAimPressed"] [connection signal="input_aim_released" from="InputController" to="." method="OnInputAimReleased"] [connection signal="input_dash" from="InputController" to="." method="OnInputDashPressed"] [connection signal="input_empower_down" from="InputController" to="." method="OnInputEmpowerDown"] diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index 870bfd6..5a4285b 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -46,6 +46,7 @@ public partial class PlayerController : CharacterBody3D private Timer _timeScaleAimInAirTimer; private Timer _timeAfterDashingTimer; private Timer _dashCooldownTimer; + private Timer _empowerTimeDownscale; [Export(PropertyHint.Range, "0,1,0.01,or_greater")] public float TimeScaleAimInAir { get; set; } = 0.2f; @@ -57,25 +58,27 @@ public partial class PlayerController : CharacterBody3D [Export(PropertyHint.Range, "0,200,1,or_greater")] public int DashIndicatorStartSize { get; set; } = 100; [Export(PropertyHint.Range, "0,1,0.01")] - public float DashProgressAfterWhichToAct { get; set; } = 0.8f; + public float PerfectlyTimedActionTimer { get; set; } = 0.8f; [Export(PropertyHint.Range, "0,50,0.1")] public float BasicDashStrength { get; set; } = 10f; [Export] public Curve DashTimeDilationCurve { get; set; } + private bool _canDash = true; - private int _dashActionsLeft; - public int DashActionsLeft + private int _empoweredActionsLeft; + public int EmpoweredActionsLeft { - get => _dashActionsLeft; + get => _empoweredActionsLeft; set { - _dashActionsLeft = value; + _empoweredActionsLeft = value; PlayerUi.SetNumberOfDashesLeft(value); } } private bool _isWallJumpAvailable = true; + private bool _isActionPerfectlyTimed = false; private StateChart _playerState; @@ -176,6 +179,7 @@ public partial class PlayerController : CharacterBody3D _dashCooldownTimer = GetNode("DashCooldown"); _timeScaleAimInAirTimer = GetNode("TimeScaleAimInAir"); _timeAfterDashingTimer = GetNode("TimeAfterDashing"); + _empowerTimeDownscale = GetNode("EmpowerTimeDownscale"); /////////////////////////// // Initialize components // @@ -216,7 +220,7 @@ public partial class PlayerController : CharacterBody3D HealthSystem.Init(healthSystemParams); Stamina.SetSpeeds(MoveSystem.WalkSpeed, MoveSystem.SprintSpeed); - DashActionsLeft = MaxNumberOfDashActions; + EmpoweredActionsLeft = MaxNumberOfDashActions; /////////////////////////// // Signal setup /////////// @@ -229,9 +233,8 @@ public partial class PlayerController : CharacterBody3D _aiming.StateProcessing += HandleAiming; _aiming.StateEntered += OnAimingEntered; _aiming.StateExited += ResetTimeScale; + _aiming.StateExited += OnAimingExited; - /*_crouched.StatePhysicsProcessing += HandleGroundedCrouched; - _standing.StatePhysicsProcessing += HandleGroundedStanding;*/ _grounded.StateEntered += OnGrounded; _grounded.StatePhysicsProcessing += HandleGrounded; _airborne.StatePhysicsProcessing += HandleAirborne; @@ -242,7 +245,36 @@ public partial class PlayerController : CharacterBody3D _timeScaleAimInAirTimer.Timeout += ResetTimeScale; _dashing.StatePhysicsProcessing += Dashing; - _weaponThrown.StateEntered += OnWeaponThrown; + // _weaponThrown.StateEntered += OnWeaponThrown; + + _empowerOn.StateEntered += OnEmpowerStarted; + _empowerOn.StateProcessing += HandleEmpower; + _empowerTimeDownscale.Timeout += EmpowerStopped; + } + + 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 EmpowerStopped() + { + DashIndicator.Visible = false; + ResetTimeScale(); + _isActionPerfectlyTimed = false; } /////////////////////////// @@ -264,6 +296,10 @@ public partial class PlayerController : CharacterBody3D public void OnInputAimPressed() { _playerState.SendEvent("aim_pressed"); + if (!WeaponSystem.InHandState.Active) + { + OnDashStarted(); + } } public void OnInputAimDown() { @@ -280,7 +316,10 @@ public partial class PlayerController : CharacterBody3D } public void OnInputHitPressed() { - _playerState.SendEvent("hit_pressed"); + if (_aiming.Active) + { + OnWeaponThrown(); + } } public void OnInputJumpPressed() { @@ -290,15 +329,21 @@ public partial class PlayerController : CharacterBody3D return; } if (_grounded.Active || _coyoteEnabled.Active) - if (_empowerOn.Active) + if (_empowerOn.Active && CanPerformEmpoweredAction()) + { + PerformEmpoweredAction(); PerformJump(MoveSystem.JumpTypes.JumpFromDash); + } else - Jump(); + PerformJump(MoveSystem.JumpTypes.SimpleJump); else if (_doubleJumpEnabled.Active) - if (_empowerOn.Active) + if (_empowerOn.Active && CanPerformEmpoweredAction()) + { + PerformEmpoweredAction(); PerformJump(MoveSystem.JumpTypes.JumpFromDash); + } else - DoubleJump(); + PerformJump(MoveSystem.JumpTypes.DoubleJump); else if (_onWall.Active) JumpFromWall(_empowerOn.Active); @@ -312,7 +357,7 @@ public partial class PlayerController : CharacterBody3D } public void OnInputThrowPressed() { - _playerState.SendEvent("throw"); + } public void OnInputEmpowerDown() { @@ -325,9 +370,25 @@ public partial class PlayerController : CharacterBody3D public void PerformDash(bool isEmpowered) { + if (_aiming.Active) + { + OnDashStarted(); + return; + } + + if (!_canDash) + return; + + _canDash = false; + var dashStrength = BasicDashStrength; + if (isEmpowered && CanPerformEmpoweredAction()) + { + PerformEmpoweredAction(); + dashStrength *= 2.5f; + } + var direction = HeadSystem.Transform.Basis * _inputMove; var planarDirection = new Vector3(direction.X, 0, direction.Z).Normalized(); - var dashStrength = isEmpowered ? BasicDashStrength * 2.5f : BasicDashStrength; SetVelocity(planarDirection * dashStrength); } @@ -344,20 +405,31 @@ public partial class PlayerController : CharacterBody3D // Simple states public void OnGrounded() { - DashActionsLeft = MaxNumberOfDashActions; + RestoreEmpoweredActions(); + } + + private void RestoreEmpoweredActions() + { + EmpoweredActionsLeft = MaxNumberOfDashActions; _isWallJumpAvailable = true; } public bool CanPerformEmpoweredAction() { - return DashActionsLeft > 0 && _dashCooldownTimer.IsStopped(); + return EmpoweredActionsLeft > 0; } public void PerformEmpoweredAction() { _isWallJumpAvailable = true; _dashCooldownTimer.Start(); - DashActionsLeft--; + + if (!_isActionPerfectlyTimed) + { + EmpoweredActionsLeft--; + } + _empowerTimeDownscale.Stop(); + EmpowerStopped(); } // Jumping @@ -369,17 +441,6 @@ public partial class PlayerController : CharacterBody3D { _playerState.SendEvent("coyote_expired"); } - public void Jump() - { - if (_aiming.Active && CanPerformEmpoweredAction()) - { - _playerState.SendEvent("jump_from_dash"); - PerformEmpoweredAction(); - PerformJump(MoveSystem.JumpTypes.JumpFromDash); - return; - } - PerformJump(MoveSystem.JumpTypes.SimpleJump); - } public void JumpFromWall(bool isEmpowered) { if (!_isWallJumpAvailable) @@ -397,16 +458,6 @@ public partial class PlayerController : CharacterBody3D } PerformJump(MoveSystem.JumpTypes.JumpFromWall, jumpDirection); } - public void DoubleJump() - { - if (_aiming.Active && CanPerformEmpoweredAction()) - { - PerformEmpoweredAction(); - PerformJump(MoveSystem.JumpTypes.JumpFromDash); - return; - } - PerformJump(MoveSystem.JumpTypes.DoubleJump); - } private void PerformJump(MoveSystem.JumpTypes jumpType, Vector3? jumpDirection = null) { var effectiveJumpDirection = jumpDirection ?? Vector3.Up; @@ -478,10 +529,12 @@ public partial class PlayerController : CharacterBody3D public void OnDashProgress(float progress) { + return; + Engine.SetTimeScale(DashTimeDilationCurve.Sample(progress)); DashIndicator.SetCustomMinimumSize(Vector2.One * DashIndicatorStartSize * (1 - progress)); - var indicatorColor = progress < DashProgressAfterWhichToAct ? new Color(1, 1, 1) : new Color(0, 1, 0); + var indicatorColor = progress < PerfectlyTimedActionTimer ? new Color(1, 1, 1) : new Color(0, 1, 0); DashIndicator.SetModulate(indicatorColor); } public void OnDashEnded() @@ -522,15 +575,18 @@ public partial class PlayerController : CharacterBody3D // Weapon planted anywhere else _playerState.SendEvent("dash_ended"); + if (isOnFloorCustom()) + RestoreEmpoweredActions(); // Make sure to restore actions if we're still on the ground } public void OnWeaponThrown() { + DashSystem.CancelDash(); + _playerState.SendEvent("cancel_aim"); + RemoveChild(WeaponRoot); GetTree().GetRoot().AddChild(WeaponRoot); WeaponRoot.SetGlobalPosition(GlobalPosition); - DashSystem.CancelDash(); - var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.TargetLocation; WeaponSystem.ThrowWeapon( weaponTargetLocation, @@ -540,32 +596,38 @@ public partial class PlayerController : CharacterBody3D } public void OnAimingEntered() { + if (!WeaponSystem.InHandState.Active) + { + OnDashStarted(); + return; + } if (!isOnFloorCustom() && CanPerformEmpoweredAction()) ReduceTimeScaleWhileAiming(); } + + public void OnAimingExited() + { + DashSystem.CancelDash(); + } // Regular processes public void HandleWeaponInHand(float delta) { - RotateWeaponWithPlayer(); + if (WeaponSystem.InHandState.Active) + RotateWeaponWithPlayer(); } public void HandleAiming(float delta) { RotateWeaponWithPlayer(); - if (isOnFloorCustom()) - ResetTimeScale(); + if (CanPerformEmpoweredAction()) DashSystem.PrepareDash(); - else - { - _playerState.SendEvent("aim_canceled"); - DashSystem.CancelDash(); - } } // Physics processes public void HandleGrounded(float delta) { + _canDash = true; if (!isOnFloorCustom()) _playerState.SendEvent("start_falling"); } diff --git a/systems/inputs/base_mode/aim_pressed.tres b/systems/inputs/base_mode/aim_pressed.tres new file mode 100644 index 0000000..0617c46 --- /dev/null +++ b/systems/inputs/base_mode/aim_pressed.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" script_class="GUIDEAction" load_steps=2 format=3 uid="uid://bebstkm608wxx"] + +[ext_resource type="Script" uid="uid://cluhc11vixkf1" path="res://addons/guide/guide_action.gd" id="1_bvbvh"] + +[resource] +script = ExtResource("1_bvbvh") +name = &"" +action_value_type = 0 +block_lower_priority_actions = true +emit_as_godot_actions = false +is_remappable = false +display_name = "" +display_category = "" +metadata/_custom_type_script = "uid://cluhc11vixkf1" diff --git a/systems/inputs/base_mode/base_mode.tres b/systems/inputs/base_mode/base_mode.tres index 2163192..c33b2e2 100644 --- a/systems/inputs/base_mode/base_mode.tres +++ b/systems/inputs/base_mode/base_mode.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" script_class="GUIDEMappingContext" load_steps=81 format=3 uid="uid://bl5crtu1gkrtr"] +[gd_resource type="Resource" script_class="GUIDEMappingContext" load_steps=86 format=3 uid="uid://bl5crtu1gkrtr"] [ext_resource type="Script" uid="uid://cpplm41b5bt6m" path="res://addons/guide/guide_action_mapping.gd" id="1_qmhk6"] [ext_resource type="Resource" uid="uid://htqvokm8mufq" path="res://systems/inputs/base_mode/move.tres" id="2_g6bbx"] @@ -17,6 +17,7 @@ [ext_resource type="Script" uid="uid://b52rqq28tuqpg" path="res://addons/guide/triggers/guide_trigger_pressed.gd" id="15_fykw6"] [ext_resource type="Script" uid="uid://b4cdrn4paoj3i" path="res://addons/guide/triggers/guide_trigger_down.gd" id="15_g6bbx"] [ext_resource type="Resource" uid="uid://b334rau1yxmm7" path="res://systems/inputs/base_mode/empower_down.tres" id="16_0qat1"] +[ext_resource type="Resource" uid="uid://bebstkm608wxx" path="res://systems/inputs/base_mode/aim_pressed.tres" id="16_li5ak"] [ext_resource type="Resource" uid="uid://j1o5ud0plk4" path="res://systems/inputs/base_mode/aim_release.tres" id="16_rvpjj"] [ext_resource type="Script" uid="uid://biiggjw6tv4uq" path="res://addons/guide/triggers/guide_trigger_released.gd" id="17_s8kjn"] [ext_resource type="Resource" uid="uid://7wm8ywvujwf" path="res://systems/inputs/base_mode/aim_cancel.tres" id="18_vibkn"] @@ -156,6 +157,31 @@ triggers = Array[ExtResource("8_2tfaw")]([SubResource("Resource_2tfaw")]) script = ExtResource("1_qmhk6") action = ExtResource("14_yp12v") input_mappings = Array[ExtResource("3_yp12v")]([SubResource("Resource_q86qg")]) +metadata/_guide_input_mappings_collapsed = false + +[sub_resource type="Resource" id="Resource_llfhp"] +script = ExtResource("10_cvxqo") +axis = 4 +joy_index = -1 + +[sub_resource type="Resource" id="Resource_ib0yi"] +script = ExtResource("15_fykw6") +actuation_threshold = 0.5 + +[sub_resource type="Resource" id="Resource_r6kml"] +script = ExtResource("3_yp12v") +override_action_settings = false +is_remappable = false +display_name = "" +display_category = "" +input = SubResource("Resource_llfhp") +modifiers = Array[ExtResource("5_0qat1")]([]) +triggers = Array[ExtResource("8_2tfaw")]([SubResource("Resource_ib0yi")]) + +[sub_resource type="Resource" id="Resource_tb8ii"] +script = ExtResource("1_qmhk6") +action = ExtResource("16_li5ak") +input_mappings = Array[ExtResource("3_yp12v")]([SubResource("Resource_r6kml")]) [sub_resource type="Resource" id="Resource_fykw6"] script = ExtResource("10_cvxqo") @@ -355,5 +381,5 @@ input_mappings = Array[ExtResource("3_yp12v")]([SubResource("Resource_v2ywt")]) [resource] script = ExtResource("23_llfhp") display_name = "" -mappings = Array[ExtResource("1_qmhk6")]([SubResource("Resource_88x08"), SubResource("Resource_tgr2g"), SubResource("Resource_iarn8"), SubResource("Resource_cvxqo"), SubResource("Resource_vibkn"), SubResource("Resource_iihs4"), SubResource("Resource_2hs2y"), SubResource("Resource_0s4kt"), SubResource("Resource_xt1x5"), SubResource("Resource_ew1hw"), SubResource("Resource_0qat1"), SubResource("Resource_vtk18")]) +mappings = Array[ExtResource("1_qmhk6")]([SubResource("Resource_88x08"), SubResource("Resource_tgr2g"), SubResource("Resource_iarn8"), SubResource("Resource_cvxqo"), SubResource("Resource_tb8ii"), SubResource("Resource_vibkn"), SubResource("Resource_iihs4"), SubResource("Resource_2hs2y"), SubResource("Resource_0s4kt"), SubResource("Resource_xt1x5"), SubResource("Resource_ew1hw"), SubResource("Resource_0qat1"), SubResource("Resource_vtk18")]) metadata/_custom_type_script = "uid://dsa1dnifd6w32" diff --git a/systems/inputs/input_system.gd b/systems/inputs/input_system.gd index 81691eb..ec050f6 100644 --- a/systems/inputs/input_system.gd +++ b/systems/inputs/input_system.gd @@ -11,6 +11,7 @@ class_name InputController @export_group("Trigger actions") @export var aim_down:GUIDEAction +@export var aim_pressed:GUIDEAction @export var aim_released:GUIDEAction @export var empower_down:GUIDEAction @export var empower_released:GUIDEAction @@ -25,6 +26,7 @@ signal input_rotate_y(value: float) signal input_rotate_floorplane(value: float) signal input_aim_down +signal input_aim_pressed signal input_aim_released signal input_empower_down signal input_empower_released @@ -38,6 +40,7 @@ func _ready() -> void: GUIDE.enable_mapping_context(base_mode) aim_down.triggered.connect(on_input_aim_down) + aim_pressed.triggered.connect(on_input_aim_pressed) aim_released.triggered.connect(on_input_aim_released) empower_down.triggered.connect(on_input_empower_down) empower_released.triggered.connect(on_input_empower_released) @@ -61,6 +64,9 @@ func on_input_jump(): func on_input_aim_down(): input_aim_down.emit() + +func on_input_aim_pressed(): + input_aim_pressed.emit() func on_input_aim_released(): input_aim_released.emit() diff --git a/systems/weapon/WeaponSystem.cs b/systems/weapon/WeaponSystem.cs index 9a995a0..fb7f6e1 100644 --- a/systems/weapon/WeaponSystem.cs +++ b/systems/weapon/WeaponSystem.cs @@ -78,6 +78,7 @@ public partial class WeaponSystem : RigidBody3D public void OnThrownWeaponReachesGround(Node other) { + GD.Print(other.Name); PlantWeaponInWall(); }