From 1b52cae9c5eeb87a0ec46ba3198b3c5600ff0392 Mon Sep 17 00:00:00 2001 From: Thepuppetqueen57 Date: Fri, 10 Oct 2025 15:13:15 -0700 Subject: [PATCH] Added jumping Was annoying to add but it works. --- Scripts/Globals.cs | 5 +++++ Scripts/Player.cs | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Scripts/Globals.cs b/Scripts/Globals.cs index f7f55c2..0eb3c09 100644 --- a/Scripts/Globals.cs +++ b/Scripts/Globals.cs @@ -8,6 +8,11 @@ public partial class Globals : Node { public static float MovementSpeed = 800f; public static float DefaultMovementSpeed = MovementSpeed; + public static float JumpHeight = -0.5f; + public static float DefaultJumpHeight = JumpHeight; + public static float Gravity = 0.0005f; + public static float DefaultGravity = JumpHeight; + public static string ActiveEffect = "none"; public static float EffectTimer = 0f; diff --git a/Scripts/Player.cs b/Scripts/Player.cs index 210593f..748220f 100644 --- a/Scripts/Player.cs +++ b/Scripts/Player.cs @@ -3,6 +3,7 @@ using System; public partial class Player : Node2D { private float ScreenBorders = 120f; + private float VelocityY = 0f; public override void _Ready() { Position = new Vector2(x: DisplayServer.WindowGetSize().X / 2, y: 0); @@ -14,7 +15,7 @@ public partial class Player : Node2D { var WindowScale = WindowSize / ScreenSize; Vector2 Pos = Position; - Pos.Y = (WindowSize.Y / WindowScale.Y) - 100; + // Pos.Y = (WindowSize.Y / WindowScale.Y) - 100; if ((Input.IsKeyPressed((Key)Key.Left) || Input.IsKeyPressed((Key)Key.A)) && Pos.X > ScreenBorders) { GetNode("Texture").FlipH = false; @@ -27,6 +28,21 @@ public partial class Player : Node2D { Pos.X += Globals.MovementSpeed * (float)delta; } + if (Input.IsKeyPressed((Key)Key.Space) && Pos.Y >= 976) { + VelocityY = Globals.JumpHeight; + } + + if (VelocityY < 0.3f) { + VelocityY += Globals.Gravity; + } + + Pos.Y += VelocityY; + + if (Pos.Y > 976) { + Pos.Y = 976; + VelocityY = 0; + } + Position = Pos; // Effect handling