From e4880d42f99e7359aa7bd92e3f26e3b109a5d61a Mon Sep 17 00:00:00 2001 From: Minimata Date: Sun, 6 Jul 2025 15:11:25 +0200 Subject: [PATCH] feat: removed crouch and added a UI for available jumps --- player_controller/PlayerController.tscn | 41 +++++++++++++++++-- player_controller/PlayerUi.cs | 26 ++++++++++++ player_controller/PlayerUi.cs.uid | 1 + player_controller/Scripts/PlayerController.cs | 31 +++++++------- project.godot | 2 +- 5 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 player_controller/PlayerUi.cs create mode 100644 player_controller/PlayerUi.cs.uid diff --git a/player_controller/PlayerController.tscn b/player_controller/PlayerController.tscn index c9388cf..4b52ee2 100644 --- a/player_controller/PlayerController.tscn +++ b/player_controller/PlayerController.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=36 format=3 uid="uid://bei4nhkf8lwdo"] +[gd_scene load_steps=38 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="Resource" uid="uid://bl5crtu1gkrtr" path="res://systems/inputs/base_mode/base_mode.tres" id="3_cresl"] @@ -34,6 +34,8 @@ [ext_resource type="Script" uid="uid://tjiji63wlom5" path="res://systems/wall_hug/WallHugSystem.cs" id="27_n7qhm"] [ext_resource type="Script" uid="uid://cf1nsco3w0mf6" path="res://addons/godot_state_charts/transition.gd" id="28_n7qhm"] [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"] [sub_resource type="CapsuleMesh" id="CapsuleMesh_xc2g5"] height = 1.7 @@ -42,7 +44,7 @@ height = 1.7 script = ExtResource("1_poq2x") TimeScaleAimInAir = 0.15 MaxJumpBoostAfterDashing = 0.7 -MaxNumberOfDashActions = 3 +MaxNumberOfDashActions = 2 [node name="InputController" type="Node3D" parent="."] script = ExtResource("16_v31n3") @@ -181,12 +183,43 @@ wait_time = 0.3 one_shot = true [node name="StateChartDebugger" parent="." instance=ExtResource("24_q5h8a")] -offset_left = 1530.0 +offset_left = 1524.0 offset_top = 1.0 -offset_right = -2.0 +offset_right = -8.0 offset_bottom = 1.0 +enabled = false initial_node_to_watch = NodePath("../StateChart") +[node name="UI" type="CanvasLayer" parent="."] +script = ExtResource("30_2ghaa") + +[node name="VBoxContainer" type="VBoxContainer" parent="UI"] +offset_right = 128.0 +offset_bottom = 81.0 + +[node name="DashesLabel" type="Label" parent="UI/VBoxContainer"] +layout_mode = 2 +text = "Dashes" + +[node name="HBoxContainer" type="HBoxContainer" parent="UI/VBoxContainer"] +custom_minimum_size = Vector2(0, 30) +layout_mode = 2 + +[node name="Dash1" type="TextureRect" parent="UI/VBoxContainer/HBoxContainer"] +layout_mode = 2 +texture = ExtResource("30_h23go") +expand_mode = 2 + +[node name="Dash2" type="TextureRect" parent="UI/VBoxContainer/HBoxContainer"] +layout_mode = 2 +texture = ExtResource("30_h23go") +expand_mode = 2 + +[node name="Dash3" type="TextureRect" parent="UI/VBoxContainer/HBoxContainer"] +layout_mode = 2 +texture = ExtResource("30_h23go") +expand_mode = 2 + [node name="StateChart" type="Node" parent="."] script = ExtResource("25_wv70j") metadata/_custom_type_script = "uid://couw105c3bde4" diff --git a/player_controller/PlayerUi.cs b/player_controller/PlayerUi.cs new file mode 100644 index 0000000..85c876d --- /dev/null +++ b/player_controller/PlayerUi.cs @@ -0,0 +1,26 @@ +using Godot; +using System; + +public partial class PlayerUi : CanvasLayer +{ + private TextureRect[] _dashIcons = new TextureRect[3]; + + public override void _Ready() + { + base._Ready(); + + _dashIcons[0] = GetNode("VBoxContainer/HBoxContainer/Dash1"); + _dashIcons[1] = GetNode("VBoxContainer/HBoxContainer/Dash2"); + _dashIcons[2] = GetNode("VBoxContainer/HBoxContainer/Dash3"); + } + + public void SetNumberOfDashesLeft(int numberOfDashes) + { + int index = 1; + foreach (var dashIcon in _dashIcons) + { + dashIcon.SetVisible(index <= numberOfDashes); + index++; + } + } +} diff --git a/player_controller/PlayerUi.cs.uid b/player_controller/PlayerUi.cs.uid new file mode 100644 index 0000000..89ab48a --- /dev/null +++ b/player_controller/PlayerUi.cs.uid @@ -0,0 +1 @@ +uid://bhuwv2nlcrunt diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index bc11f65..445b4fe 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -23,6 +23,7 @@ public partial class PlayerController : CharacterBody3D public Node3D WeaponRoot; public WeaponSystem WeaponSystem; public WallHugSystem WallHugSystem; + public PlayerUi PlayerUi; private bool _movementEnabled = true; @@ -52,9 +53,18 @@ public partial class PlayerController : CharacterBody3D [Export(PropertyHint.Range, "0,5,1,or_greater")] public int MaxNumberOfDashActions { get; set; } = 1; - - public int DashActionsLeft { get; set; } + private int _dashActionsLeft; + public int DashActionsLeft + { + get => _dashActionsLeft; + set + { + _dashActionsLeft = value; + PlayerUi.SetNumberOfDashesLeft(value); + } + } + private bool _isWallJumpAvailable = true; private StateChart _playerState; @@ -87,6 +97,7 @@ public partial class PlayerController : CharacterBody3D // General use stuff TweenQueueSystem = GetNode("TweenQueueSystem"); + PlayerUi = GetNode("UI"); // Node3D mapNode = GetTree().Root.FindChild("Map", true, false) as Node3D; // Camera stuff @@ -204,8 +215,8 @@ public partial class PlayerController : CharacterBody3D _aiming.StateEntered += OnAimingEntered; _aiming.StateExited += ResetTimeScale; - _crouched.StatePhysicsProcessing += HandleGroundedCrouched; - _standing.StatePhysicsProcessing += HandleGroundedStanding; + /*_crouched.StatePhysicsProcessing += HandleGroundedCrouched; + _standing.StatePhysicsProcessing += HandleGroundedStanding;*/ _grounded.StateEntered += OnGrounded; _grounded.StatePhysicsProcessing += HandleGrounded; _airborne.StatePhysicsProcessing += HandleAirborne; @@ -286,16 +297,6 @@ public partial class PlayerController : CharacterBody3D _isWallJumpAvailable = true; } - public void OnStanding() - { - - } - - public void OnCrouched() - { - - } - public bool CanPerformDashAction() { return DashActionsLeft > 0 && _dashCooldownTimer.IsStopped(); @@ -303,7 +304,7 @@ public partial class PlayerController : CharacterBody3D public void PerformDashAction() { - _isWallJumpAvailable = true; + _isWallJumpAvailable = true; _dashCooldownTimer.Start(); DashActionsLeft--; } diff --git a/project.godot b/project.godot index 9ffebe9..8212338 100644 --- a/project.godot +++ b/project.godot @@ -29,7 +29,7 @@ ProjectUISoundController="*res://addons/maaacks_game_template/base/scenes/autolo [display] -window/size/viewport_width=1980 +window/size/viewport_width=1920 window/size/viewport_height=1080 [dotnet]