From a1e0c19ff7908284fee89170cd0462857d9c4a5e Mon Sep 17 00:00:00 2001 From: qwsdcvghyu89 <61093706+qwsdcvghyu89@users.noreply.github.com> Date: Thu, 18 Jun 2026 22:05:44 +1000 Subject: [PATCH] Added combo counter --- objects/l18n/english.tres | 3 +++ src/components/PlayerPhysicsController.cs | 10 ++++++++++ src/components/combo_counter.gd | 18 ++++++++++++++++++ src/components/combo_counter.gd.uid | 1 + 4 files changed, 32 insertions(+) create mode 100644 objects/l18n/english.tres create mode 100644 src/components/combo_counter.gd create mode 100644 src/components/combo_counter.gd.uid diff --git a/objects/l18n/english.tres b/objects/l18n/english.tres new file mode 100644 index 0000000..1d6efd3 --- /dev/null +++ b/objects/l18n/english.tres @@ -0,0 +1,3 @@ +[gd_resource type="Translation" format=3 uid="uid://vs4pl3jum6hp"] + +[resource] diff --git a/src/components/PlayerPhysicsController.cs b/src/components/PlayerPhysicsController.cs index 1168ead..5e2c637 100644 --- a/src/components/PlayerPhysicsController.cs +++ b/src/components/PlayerPhysicsController.cs @@ -20,6 +20,9 @@ public partial class PlayerPhysicsController : CharacterBody2D { [Signal] public delegate void OnJumpEventHandler(JumpKind kind, bool isOnGround, bool isOnWall); + [Signal] + public delegate void OnJumpFailEventHandler(); + [ExportCategory("Accelerations and Impulses")] [Export] @@ -139,6 +142,7 @@ public partial class PlayerPhysicsController : CharacterBody2D { float velx = (Velocity.X / UnitToPx); float vely = (Velocity.Y / UnitToPx) + Gravity * (float)delta; + var jumped = false; var grounded = this.IsOnFloor(); var coyoteGrounded = _timeOffGround < CoyoteTiming; if (grounded || coyoteGrounded) { @@ -147,6 +151,7 @@ public partial class PlayerPhysicsController : CharacterBody2D { if (Input.IsActionJustPressed("jump")) { EmitSignal(SignalName.OnJump, (int)JumpKind.Ground, this.IsOnFloor(), this.IsOnWall()); + jumped = true; vely = -_lv; } @@ -194,6 +199,7 @@ public partial class PlayerPhysicsController : CharacterBody2D { GD.Print($"Theta: {theta * (180 / Mathf.Pi)}, turnjump: {turnjump}"); velx = turnjump.X; vely = turnjump.Y; + jumped = true; } else { // does not have jump point // float theta = Mathf.Atan2(-yAxis, Mathf.Abs(xAxis)); @@ -209,6 +215,7 @@ public partial class PlayerPhysicsController : CharacterBody2D { if (Input.IsActionJustPressed("jump") && Mathf.Abs(vely) < MaxDoubleJumpFallSpeed) { EmitSignal(SignalName.OnJump, (int)JumpKind.Midair, this.IsOnFloor(), this.IsOnWall()); + jumped = true; vely = -_lv; } @@ -221,6 +228,9 @@ public partial class PlayerPhysicsController : CharacterBody2D { else velx += autostop; } + if (Input.IsActionJustPressed("jump") && !jumped) + EmitSignal(SignalName.OnJumpFail); + var maxXSpeed = grounded ? Input.IsActionPressed("run") ? MaxRunSpeed : MaxWalkSpeed : MaxAirSpeed; var maxYSpeed = vely > 0 ? MaxFallSpeed : MaxRiseSpeed; var (absvelx, absvely) = (Mathf.Abs(velx), Mathf.Abs(vely)); diff --git a/src/components/combo_counter.gd b/src/components/combo_counter.gd new file mode 100644 index 0000000..3a75f88 --- /dev/null +++ b/src/components/combo_counter.gd @@ -0,0 +1,18 @@ +extends Label + +var combo: int = 0; +@onready var playerBody: CharacterBody2D = %Player/CharacterBody2D + +func _ready(): + playerBody.connect("OnJump", onJump) + playerBody.connect("OnJumpFail", onJumpFail) + +func onJump(kind: int, isOnGround: bool, isOnWall: bool): + combo += 1; + updateLabel() +func onJumpFail(): + combo = 0; + updateLabel() + +func updateLabel(): + text = "Combo: %d" % combo diff --git a/src/components/combo_counter.gd.uid b/src/components/combo_counter.gd.uid new file mode 100644 index 0000000..d7cd0eb --- /dev/null +++ b/src/components/combo_counter.gd.uid @@ -0,0 +1 @@ +uid://dct1kelhyy04v