From 50f31652f8ef2b1109aa0b324a93858958039d14 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Tue, 24 Feb 2026 14:48:24 -0700 Subject: [PATCH] Add mobile game player support --- Scenes/Game.tscn | 110 +++++++++++++++++++++++++ Scripts/Player.cs | 21 ++++- Textures/Buttons/ArrowLeft.svg | 37 +++++++++ Textures/Buttons/ArrowLeft.svg.import | 43 ++++++++++ Textures/Buttons/ArrowRight.svg | 37 +++++++++ Textures/Buttons/ArrowRight.svg.import | 43 ++++++++++ Textures/Buttons/CheveronUp.svg | 37 +++++++++ Textures/Buttons/CheveronUp.svg.import | 43 ++++++++++ Textures/Buttons/Circle.svg | 37 +++++++++ Textures/Buttons/Circle.svg.import | 43 ++++++++++ Textures/Buttons/Pause.svg | 37 +++++++++ Textures/Buttons/Pause.svg.import | 43 ++++++++++ 12 files changed, 527 insertions(+), 4 deletions(-) create mode 100644 Textures/Buttons/ArrowLeft.svg create mode 100644 Textures/Buttons/ArrowLeft.svg.import create mode 100644 Textures/Buttons/ArrowRight.svg create mode 100644 Textures/Buttons/ArrowRight.svg.import create mode 100644 Textures/Buttons/CheveronUp.svg create mode 100644 Textures/Buttons/CheveronUp.svg.import create mode 100644 Textures/Buttons/Circle.svg create mode 100644 Textures/Buttons/Circle.svg.import create mode 100644 Textures/Buttons/Pause.svg create mode 100644 Textures/Buttons/Pause.svg.import diff --git a/Scenes/Game.tscn b/Scenes/Game.tscn index 759bb53..5b4d445 100644 --- a/Scenes/Game.tscn +++ b/Scenes/Game.tscn @@ -10,8 +10,13 @@ [ext_resource type="AudioStream" uid="uid://btl7lrqmikaro" path="res://Audio/Music/Game/FluffingADuck.mp3" id="7_2irst"] [ext_resource type="Script" uid="uid://c6eb8owotqy45" path="res://Scripts/Fps.cs" id="7_acvyw"] [ext_resource type="AudioStream" uid="uid://js133askfgfd" path="res://Audio/Music/Game/AmazingPlan.mp3" id="8_3cx6b"] +[ext_resource type="Texture2D" uid="uid://dryavksejt84w" path="res://Textures/Buttons/Circle.svg" id="8_4q8tf"] +[ext_resource type="Texture2D" uid="uid://cdl6h5fqjke4f" path="res://Textures/Buttons/ArrowLeft.svg" id="8_alh3a"] +[ext_resource type="Texture2D" uid="uid://d2kxub8e1gl4x" path="res://Textures/Buttons/Pause.svg" id="9_tfod6"] [ext_resource type="AudioStream" uid="uid://dnnjkxgsh0vf6" path="res://Audio/Music/Game/Hyperfun.mp3" id="9_wxwew"] +[ext_resource type="Texture2D" uid="uid://cud8l2dwwi6y4" path="res://Textures/Buttons/ArrowRight.svg" id="9_x3xnh"] [ext_resource type="AudioStream" uid="uid://cds2k1ijtf5ol" path="res://Audio/Music/Game/QuirkyDog.mp3" id="10_acvyw"] +[ext_resource type="Texture2D" uid="uid://b54itl2db5w64" path="res://Textures/Buttons/CheveronUp.svg" id="11_8r6kd"] [ext_resource type="AudioStream" uid="uid://em0ro3lwpp0a" path="res://Audio/Music/Game/Wallpaper.mp3" id="11_alh3a"] [ext_resource type="AudioStream" uid="uid://c51he0x017y6d" path="res://Audio/Music/Game/WhoLikesToParty.mp3" id="12_4q8tf"] [ext_resource type="AudioStream" uid="uid://g432tiqm4b41" path="res://Audio/Music/Game/LatinIndustries.mp3" id="13_x3xnh"] @@ -132,6 +137,111 @@ theme_override_font_sizes/font_size = 109 text = "FPS: {}" script = ExtResource("7_acvyw") +[node name="MobileButtons" type="Node" parent="CanvasLayer" unique_id=1504154343] + +[node name="PauseButton" type="Button" parent="CanvasLayer/MobileButtons" unique_id=1375970461] +z_index = 10 +offset_left = 80.0 +offset_top = 80.0 +offset_right = 320.0002 +offset_bottom = 320.0 +icon_alignment = 1 +expand_icon = true + +[node name="Circle" type="Sprite2D" parent="CanvasLayer/MobileButtons/PauseButton" unique_id=32602554] +position = Vector2(120, 120) +scale = Vector2(0.35, 0.35) +texture = ExtResource("8_4q8tf") + +[node name="Texture" type="Sprite2D" parent="CanvasLayer/MobileButtons/PauseButton" unique_id=23048453] +position = Vector2(120, 120) +scale = Vector2(0.2, 0.2) +texture = ExtResource("9_tfod6") + +[node name="LeftMoveButton" type="Button" parent="CanvasLayer/MobileButtons" unique_id=1778119021] +z_index = 10 +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_left = 80.0 +offset_top = -320.0 +offset_right = 320.0002 +offset_bottom = -80.0 +grow_vertical = 0 +icon_alignment = 1 +expand_icon = true + +[node name="Circle" type="Sprite2D" parent="CanvasLayer/MobileButtons/LeftMoveButton" unique_id=549488896] +position = Vector2(120, 120) +scale = Vector2(0.35, 0.35) +texture = ExtResource("8_4q8tf") + +[node name="Texture" type="Sprite2D" parent="CanvasLayer/MobileButtons/LeftMoveButton" unique_id=934604812] +position = Vector2(120, 120) +scale = Vector2(0.2, 0.2) +texture = ExtResource("8_alh3a") + +[node name="RightMoveButton" type="Button" parent="CanvasLayer/MobileButtons" unique_id=2046843618] +z_index = 10 +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -320.0 +offset_top = -320.0 +offset_right = -80.0 +offset_bottom = -80.0 +grow_horizontal = 0 +grow_vertical = 0 +icon_alignment = 1 +expand_icon = true + +[node name="Circle" type="Sprite2D" parent="CanvasLayer/MobileButtons/RightMoveButton" unique_id=838628165] +position = Vector2(120, 120) +scale = Vector2(0.35, 0.35) +texture = ExtResource("8_4q8tf") + +[node name="Texture" type="Sprite2D" parent="CanvasLayer/MobileButtons/RightMoveButton" unique_id=1284265984] +position = Vector2(120, 120) +scale = Vector2(0.2, 0.2) +texture = ExtResource("9_x3xnh") + +[node name="JumpMoveButton" type="Button" parent="CanvasLayer/MobileButtons" unique_id=139483553] +z_index = 10 +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -320.0 +offset_top = -560.0 +offset_right = -80.0 +offset_bottom = -320.0 +grow_horizontal = 0 +grow_vertical = 0 +icon_alignment = 1 +expand_icon = true + +[node name="Circle" type="Sprite2D" parent="CanvasLayer/MobileButtons/JumpMoveButton" unique_id=1010572167] +position = Vector2(120, 120) +scale = Vector2(0.35, 0.35) +texture = ExtResource("8_4q8tf") + +[node name="Texture" type="Sprite2D" parent="CanvasLayer/MobileButtons/JumpMoveButton" unique_id=1571586741] +position = Vector2(120, 120) +scale = Vector2(0.2, 0.2) +texture = ExtResource("11_8r6kd") + [node name="MusicPlayer" type="AudioStreamPlayer" parent="." unique_id=1201627685] stream = SubResource("AudioStreamPlaylist_bf53h") autoplay = true + +[connection signal="button_down" from="CanvasLayer/MobileButtons/PauseButton" to="Player" method="MobilePauseDown"] +[connection signal="button_up" from="CanvasLayer/MobileButtons/PauseButton" to="Player" method="MobilePauseUp"] +[connection signal="button_down" from="CanvasLayer/MobileButtons/LeftMoveButton" to="Player" method="MobileLeftMoveDown"] +[connection signal="button_up" from="CanvasLayer/MobileButtons/LeftMoveButton" to="Player" method="MobileLeftMoveUp"] +[connection signal="button_down" from="CanvasLayer/MobileButtons/RightMoveButton" to="Player" method="MobileRightMoveDown"] +[connection signal="button_up" from="CanvasLayer/MobileButtons/RightMoveButton" to="Player" method="MobileRightMoveUp"] +[connection signal="button_down" from="CanvasLayer/MobileButtons/JumpMoveButton" to="Player" method="MobileJumpMoveDown"] +[connection signal="button_up" from="CanvasLayer/MobileButtons/JumpMoveButton" to="Player" method="MobileJumpMoveUp"] diff --git a/Scripts/Player.cs b/Scripts/Player.cs index f943acc..3ca0cd8 100644 --- a/Scripts/Player.cs +++ b/Scripts/Player.cs @@ -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("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("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("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("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; } diff --git a/Textures/Buttons/ArrowLeft.svg b/Textures/Buttons/ArrowLeft.svg new file mode 100644 index 0000000..c7ad5c0 --- /dev/null +++ b/Textures/Buttons/ArrowLeft.svg @@ -0,0 +1,37 @@ + + + + + + + diff --git a/Textures/Buttons/ArrowLeft.svg.import b/Textures/Buttons/ArrowLeft.svg.import new file mode 100644 index 0000000..1d23f4b --- /dev/null +++ b/Textures/Buttons/ArrowLeft.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cdl6h5fqjke4f" +path="res://.godot/imported/ArrowLeft.svg-4dfaccbf798c65e049f8e3cd4a3d0747.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Textures/Buttons/ArrowLeft.svg" +dest_files=["res://.godot/imported/ArrowLeft.svg-4dfaccbf798c65e049f8e3cd4a3d0747.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/Textures/Buttons/ArrowRight.svg b/Textures/Buttons/ArrowRight.svg new file mode 100644 index 0000000..52e079a --- /dev/null +++ b/Textures/Buttons/ArrowRight.svg @@ -0,0 +1,37 @@ + + + + + + + diff --git a/Textures/Buttons/ArrowRight.svg.import b/Textures/Buttons/ArrowRight.svg.import new file mode 100644 index 0000000..64f4df2 --- /dev/null +++ b/Textures/Buttons/ArrowRight.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cud8l2dwwi6y4" +path="res://.godot/imported/ArrowRight.svg-8d3e04814a9134af7ace3c7c22a319e2.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Textures/Buttons/ArrowRight.svg" +dest_files=["res://.godot/imported/ArrowRight.svg-8d3e04814a9134af7ace3c7c22a319e2.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/Textures/Buttons/CheveronUp.svg b/Textures/Buttons/CheveronUp.svg new file mode 100644 index 0000000..2fd6199 --- /dev/null +++ b/Textures/Buttons/CheveronUp.svg @@ -0,0 +1,37 @@ + + + + + + + diff --git a/Textures/Buttons/CheveronUp.svg.import b/Textures/Buttons/CheveronUp.svg.import new file mode 100644 index 0000000..6324b84 --- /dev/null +++ b/Textures/Buttons/CheveronUp.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b54itl2db5w64" +path="res://.godot/imported/CheveronUp.svg-37a0417511606868317e28db72e7533d.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Textures/Buttons/CheveronUp.svg" +dest_files=["res://.godot/imported/CheveronUp.svg-37a0417511606868317e28db72e7533d.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/Textures/Buttons/Circle.svg b/Textures/Buttons/Circle.svg new file mode 100644 index 0000000..51805f6 --- /dev/null +++ b/Textures/Buttons/Circle.svg @@ -0,0 +1,37 @@ + + + + + + + diff --git a/Textures/Buttons/Circle.svg.import b/Textures/Buttons/Circle.svg.import new file mode 100644 index 0000000..54bd80c --- /dev/null +++ b/Textures/Buttons/Circle.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dryavksejt84w" +path="res://.godot/imported/Circle.svg-53a3381bf2240bf268087c20933de2a2.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Textures/Buttons/Circle.svg" +dest_files=["res://.godot/imported/Circle.svg-53a3381bf2240bf268087c20933de2a2.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/Textures/Buttons/Pause.svg b/Textures/Buttons/Pause.svg new file mode 100644 index 0000000..5dff04a --- /dev/null +++ b/Textures/Buttons/Pause.svg @@ -0,0 +1,37 @@ + + + + + + + diff --git a/Textures/Buttons/Pause.svg.import b/Textures/Buttons/Pause.svg.import new file mode 100644 index 0000000..90cf8f4 --- /dev/null +++ b/Textures/Buttons/Pause.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d2kxub8e1gl4x" +path="res://.godot/imported/Pause.svg-5a73753987311e9e720e35d4f36618dc.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Textures/Buttons/Pause.svg" +dest_files=["res://.godot/imported/Pause.svg-5a73753987311e9e720e35d4f36618dc.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false