From 98b6537fdd7cef6313557767e8c12e9032781844 Mon Sep 17 00:00:00 2001 From: Minimata Date: Fri, 11 Jul 2025 10:34:20 +0200 Subject: [PATCH] feat: time dilation and indicator --- player_controller/PlayerController.tscn | 28 +++++++++++++++++-- player_controller/Scripts/PlayerController.cs | 20 +++++++++++++ systems/dash/DashSystem.cs | 25 +++++++++++++---- systems/tween_queue/TweenQueueSystem.cs | 1 + 4 files changed, 67 insertions(+), 7 deletions(-) diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index 86cf940..4959c61 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=38 format=3 uid="uid://bei4nhkf8lwdo"] +[gd_scene load_steps=41 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"] [ext_resource type="Resource" uid="uid://bl5crtu1gkrtr" path="res://systems/inputs/base_mode/base_mode.tres" id="3_cresl"] [ext_resource type="Resource" uid="uid://cpdaw41ah5gic" path="res://systems/inputs/base_mode/rotate_y.tres" id="4_rxwoh"] [ext_resource type="Resource" uid="uid://ccrb5xsnphc8" path="res://systems/inputs/base_mode/rotate_floorplane.tres" id="5_4u7i3"] @@ -36,15 +37,20 @@ [ext_resource type="PackedScene" uid="uid://ckm3d6k08a72u" path="res://systems/weapon/weapon.tscn" id="29_wv70j"] [ext_resource type="Script" uid="uid://bhuwv2nlcrunt" path="res://player_controller/PlayerUi.cs" id="30_2ghaa"] [ext_resource type="Texture2D" uid="uid://bnwj7ltdfximr" path="res://icon.svg" id="30_h23go"] +[ext_resource type="Texture2D" uid="uid://chvt6g0xn5c2m" path="res://systems/dash/light-ring.jpg" id="32_lgpc8"] [sub_resource type="CapsuleMesh" id="CapsuleMesh_xc2g5"] height = 1.7 +[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_2q0ik"] +blend_mode = 1 + [node name="Player" type="CharacterBody3D"] script = ExtResource("1_poq2x") TimeScaleAimInAir = 0.15 MaxJumpBoostAfterDashing = 0.7 MaxNumberOfDashActions = 2 +DashTimeDilationCurve = ExtResource("2_2q0ik") [node name="InputController" type="Node3D" parent="."] script = ExtResource("16_v31n3") @@ -187,7 +193,6 @@ offset_left = 1524.0 offset_top = 1.0 offset_right = -8.0 offset_bottom = 1.0 -enabled = false initial_node_to_watch = NodePath("../StateChart") [node name="UI" type="CanvasLayer" parent="."] @@ -220,6 +225,25 @@ layout_mode = 2 texture = ExtResource("30_h23go") expand_mode = 2 +[node name="CenterContainer" type="CenterContainer" parent="UI"] +custom_minimum_size = Vector2(1920, 1080) +offset_right = 1919.0 +offset_bottom = 1080.0 + +[node name="CenterIcon" type="TextureRect" parent="UI/CenterContainer"] +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"] +unique_name_in_owner = true +material = SubResource("CanvasItemMaterial_2q0ik") +layout_mode = 2 +texture = ExtResource("32_lgpc8") +expand_mode = 1 + [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 445b4fe..e5e89fd 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -24,6 +24,7 @@ public partial class PlayerController : CharacterBody3D public WeaponSystem WeaponSystem; public WallHugSystem WallHugSystem; public PlayerUi PlayerUi; + public TextureRect DashIndicator; private bool _movementEnabled = true; @@ -53,6 +54,13 @@ public partial class PlayerController : CharacterBody3D [Export(PropertyHint.Range, "0,5,1,or_greater")] public int MaxNumberOfDashActions { get; set; } = 1; + [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; + + [Export] + public Curve DashTimeDilationCurve { get; set; } private int _dashActionsLeft; public int DashActionsLeft @@ -98,6 +106,8 @@ public partial class PlayerController : CharacterBody3D // General use stuff TweenQueueSystem = GetNode("TweenQueueSystem"); PlayerUi = GetNode("UI"); + DashIndicator = GetNode("%DashIndicator"); + // Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D; // Camera stuff @@ -209,6 +219,7 @@ public partial class PlayerController : CharacterBody3D /////////////////////////// DashSystem.DashEnded += OnDashEnded; + DashSystem.DashProgress += OnDashProgress; _weaponInHand.StateProcessing += HandleWeaponInHand; _aiming.StateProcessing += HandleAiming; @@ -427,6 +438,15 @@ public partial class PlayerController : CharacterBody3D _dashDirection = (DashSystem.PlannedPlayerLocation - GlobalPosition).Normalized(); DashSystem.Dash(); } + + public void OnDashProgress(float progress) + { + 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); + DashIndicator.SetModulate(indicatorColor); + } public void OnDashEnded() { // _playerState.SendEvent("enable_double_jump"); // Allow for double jump after dash -- OP ? diff --git a/systems/dash/DashSystem.cs b/systems/dash/DashSystem.cs index 5528e3c..59934cc 100644 --- a/systems/dash/DashSystem.cs +++ b/systems/dash/DashSystem.cs @@ -37,6 +37,10 @@ public partial class DashSystem: Node3D public delegate void DashStartedEventHandler(); [Signal] public delegate void DashEndedEventHandler(); + [Signal] + public delegate void DashProgressEventHandler(float progress); + + private Vector3 _globalDashPosition = Vector3.Zero; public void Init(Node3D head, Camera3D camera, TweenQueueSystem tweenQueueSystem) { @@ -121,14 +125,18 @@ public partial class DashSystem: Node3D public void DashTweenEnded() { EmitSignal(SignalName.DashEnded); + _dashTarget.SetVisible(false); } public void Dash() { EmitSignal(SignalName.DashStarted); - _dashTarget.SetVisible(false); + var dashTweenInputs = new TweenQueueSystem.TweenInputs(PlannedPlayerLocation, DashSpeed); var dashTween = _tweenQueueSystem.TweenToLocation(dashTweenInputs); + // dashTween.SetTrans(Tween.TransitionType.Cubic); + // dashTween.SetEase(Tween.EaseType.Out); + dashTween.TweenMethod(Callable.From(Dashing), 0.0f, 1.0f, DashSpeed); dashTween.Finished += DashTweenEnded; if (ShouldMantle) { @@ -136,10 +144,17 @@ public partial class DashSystem: Node3D return; } - var dashIndicator = (CpuParticles3D) DashIndicatorScene.Instantiate(); - GetTree().GetRoot().AddChild(dashIndicator); - dashIndicator.GlobalPosition = _dashTarget.GlobalPosition; - dashIndicator.SetEmitting(true); + // var dashIndicator = (CpuParticles3D) DashIndicatorScene.Instantiate(); + // GetTree().GetRoot().AddChild(dashIndicator); + // _globalDashPosition = _dashTarget.GlobalPosition + 1.5f*Vector3.Up; + // dashIndicator.GlobalPosition = _globalDashPosition; + // dashIndicator.SetEmitting(true); + } + + public void Dashing(float proportion) + { + _dashTarget.SetGlobalPosition(_globalDashPosition); + EmitSignalDashProgress(proportion); } public void DashToThrownWeapon() diff --git a/systems/tween_queue/TweenQueueSystem.cs b/systems/tween_queue/TweenQueueSystem.cs index 9d0deb6..2f17f3e 100644 --- a/systems/tween_queue/TweenQueueSystem.cs +++ b/systems/tween_queue/TweenQueueSystem.cs @@ -28,6 +28,7 @@ public partial class TweenQueueSystem : Node3D var (location, duration) = inputs; var tween = GetTree().CreateTween(); + tween.SetParallel(true); tween.TweenProperty(_tweenObject, "global_position", location, duration); tween.TweenCallback(_tweenEndedCallback); _isTweening = true;