Add mobile game player support
This commit is contained in:
12 files changed
+527
-4
No files matched your search
+17
-4
@@ -3,6 +3,10 @@ using Godot;
|
||||
public partial class Player : Node2D {
|
||||
private float ScreenBorders = 120f;
|
||||
private float VelocityY = 0f;
|
||||
private bool doLeft = false;
|
||||
private bool doRight = false;
|
||||
private bool doJump = false;
|
||||
private bool doPause = false;
|
||||
|
||||
public override void _Ready() {
|
||||
var ScreenSize = GetViewport().GetVisibleRect().Size;
|
||||
@@ -20,18 +24,18 @@ public partial class Player : Node2D {
|
||||
Vector2 Pos = Position;
|
||||
|
||||
if (!Globals.IsPaused) {
|
||||
if ((Input.IsKeyPressed(Key.Left) || Input.IsKeyPressed(Key.A)) && Pos.X > ScreenBorders) {
|
||||
if ((Input.IsKeyPressed(Key.Left) || Input.IsKeyPressed(Key.A) || doLeft) && Pos.X > ScreenBorders) {
|
||||
GetNode<Sprite2D>("Texture").FlipH = false;
|
||||
Pos.X -= Globals.MovementSpeed * (float)delta;
|
||||
}
|
||||
|
||||
float ScreenWidth = (WindowSize.X / WindowScale.X) - ScreenBorders;
|
||||
if ((Input.IsKeyPressed(Key.Right) || Input.IsKeyPressed(Key.D)) && Pos.X < ScreenWidth) {
|
||||
if ((Input.IsKeyPressed(Key.Right) || Input.IsKeyPressed(Key.D) || doRight) && Pos.X < ScreenWidth) {
|
||||
GetNode<Sprite2D>("Texture").FlipH = true;
|
||||
Pos.X += Globals.MovementSpeed * (float)delta;
|
||||
}
|
||||
|
||||
if (Input.IsKeyPressed(Key.Space) && Pos.Y >= 976) {
|
||||
if ((Input.IsKeyPressed(Key.Space) || doJump) && Pos.Y >= 976) {
|
||||
VelocityY = Globals.JumpHeight;
|
||||
GetNode<AudioStreamPlayer>("JumpSoundPlayer").Play();
|
||||
}
|
||||
@@ -76,7 +80,7 @@ public partial class Player : Node2D {
|
||||
Globals.BerrySpeed = Globals.DefaultBerrySpeed * 2f;
|
||||
}
|
||||
|
||||
if (Input.IsActionJustPressed("EscapeKey")) {
|
||||
if (Input.IsActionJustPressed("EscapeKey") || doPause) {
|
||||
if (!Globals.IsPaused) {
|
||||
PackedScene PauseMenu = GD.Load<PackedScene>("res://Prefabs/PauseMenu.tscn");
|
||||
|
||||
@@ -101,4 +105,13 @@ public partial class Player : Node2D {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MobileLeftMoveDown() => doLeft = true;
|
||||
private void MobileLeftMoveUp() => doLeft = false;
|
||||
private void MobileRightMoveDown() => doRight = true;
|
||||
private void MobileRightMoveUp() => doRight = false;
|
||||
private void MobileJumpMoveDown() => doJump = true;
|
||||
private void MobileJumpMoveUp() => doJump = false;
|
||||
private void MobilePauseDown() => doPause = true;
|
||||
private void MobilePauseUp() => doPause = false;
|
||||
}
|
||||
Reference in new issue
Block a user