Added jumping

Was annoying to add but it works.
This commit is contained in:
Puppet committed 2025-10-10 15:13:15 -07:00
1 parent 870ede5eab
commit 1b52cae9c5
2 files changed
+22 -1

No files matched your search

+17 -1
View File
@@ -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<Sprite2D>("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