Added jumping
Was annoying to add but it works.
This commit is contained in:
1 parent
870ede5eab
commit
1b52cae9c5
2 files changed
+22
-1
No files matched your search
@@ -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;
|
||||
|
||||
|
||||
+17
-1
@@ -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
|
||||
|
||||
Reference in new issue
Block a user