From 1113707125b5ffcac2ed74d1ce51aaa3f4e43e3e Mon Sep 17 00:00:00 2001 From: = mlm-games <=> Date: Wed, 28 Aug 2024 20:06:18 +0530 Subject: [PATCH] Fix touch 2 buttons problem, add WASD --- project.godot | 4 ++++ scenes/hud.gd | 8 +------- scenes/hud.tscn | 20 ++++++-------------- scenes/spring_laser.gd | 2 +- scenes/world.gd | 1 - 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/project.godot b/project.godot index 51b2939..6bfdbcd 100644 --- a/project.godot +++ b/project.godot @@ -47,21 +47,25 @@ import/blender/enabled=false down={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } up={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) ] } right={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) ] } left={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) ] } fire={ diff --git a/scenes/hud.gd b/scenes/hud.gd index 2da132d..20f25d7 100644 --- a/scenes/hud.gd +++ b/scenes/hud.gd @@ -17,8 +17,7 @@ func _ready() -> void: %"Virtual Joystick".process_mode = Node.PROCESS_MODE_DISABLED %"Virtual Joystick".hide() %FireButton.scale = Vector2(4,4) - # idk how this works but (width + size)/2 doesnt - %FireButton.global_position.x = ProjectSettings.get_setting("display/window/size/viewport_width")/2 - (%FireButton.size.x * %FireButton.scale.x)/2 + %FireButton.global_position.x = ProjectSettings.get_setting("display/window/size/viewport_width")/2 - (%FireButton.texture_normal.get_size().x * %FireButton.scale.x)/2 # Connect to player signals (for opening scene without player i.e debugging) if player: @@ -88,8 +87,3 @@ func _on_right_touch_screen_button_button_up() -> void: func _on_left_touch_screen_button_button_up() -> void: Input.action_release("left") - - -func _on_fire_button_button_down() -> void: - Input.action_press("fire") - Input.action_release("fire") diff --git a/scenes/hud.tscn b/scenes/hud.tscn index adc360c..676bb94 100644 --- a/scenes/hud.tscn +++ b/scenes/hud.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=3 uid="uid://dw1xhin6im8kv"] +[gd_scene load_steps=12 format=3 uid="uid://dw1xhin6im8kv"] [ext_resource type="Script" path="res://scenes/hud.gd" id="1_ocri0"] [ext_resource type="LabelSettings" uid="uid://bj4owgofe5ayt" path="res://resources/textstyle.tres" id="2_8bg75"] @@ -7,7 +7,6 @@ [ext_resource type="Texture2D" uid="uid://ceroyuqbhc4ys" path="res://art-and-sound/kenney_space-shooter-redux/PNG/Meteors/meteorBrown_med1.png" id="6_5rvp1"] [ext_resource type="Texture2D" uid="uid://b7fpmcg7ian2w" path="res://art-and-sound/missile/spr_missile.png" id="6_o465q"] [ext_resource type="Texture2D" uid="uid://c33xrciyt6ilb" path="res://art-and-sound/bg_1_1.png" id="7_2s6xh"] -[ext_resource type="Theme" uid="uid://bmy6kos4l110s" path="res://resources/button-theme.tres" id="7_oub31"] [sub_resource type="Animation" id="Animation_c728u"] length = 0.001 @@ -77,7 +76,7 @@ _data = { } [node name="HUD" type="CanvasLayer"] -layer = -3 +layer = -1 script = ExtResource("1_ocri0") [node name="Control" type="Control" parent="."] @@ -272,22 +271,15 @@ size_flags_horizontal = 3 layout_mode = 2 size_flags_vertical = 3 -[node name="FireButton" type="Button" parent="Control/TouchAltVBoxContainer/Control"] +[node name="FireButton" type="TouchScreenButton" parent="Control/TouchAltVBoxContainer/Control"] unique_name_in_owner = true modulate = Color(1, 1, 1, 0.52549) -layout_mode = 0 -offset_left = 399.0 -offset_top = 53.0001 -offset_right = 450.0 -offset_bottom = 104.0 +position = Vector2(394, 57) scale = Vector2(3.205, 3.205) -focus_mode = 0 -theme = ExtResource("7_oub31") -icon = ExtResource("6_5rvp1") -icon_alignment = 1 +texture_normal = ExtResource("6_5rvp1") +action = "fire" [connection signal="button_down" from="Control/TouchAltVBoxContainer/HBoxContainer/LeftTouchScreenButton" to="." method="_on_left_touch_screen_button_button_down"] [connection signal="button_up" from="Control/TouchAltVBoxContainer/HBoxContainer/LeftTouchScreenButton" to="." method="_on_left_touch_screen_button_button_up"] [connection signal="button_down" from="Control/TouchAltVBoxContainer/HBoxContainer/RightTouchScreenButton" to="." method="_on_right_touch_screen_button_button_down"] [connection signal="button_up" from="Control/TouchAltVBoxContainer/HBoxContainer/RightTouchScreenButton" to="." method="_on_right_touch_screen_button_button_up"] -[connection signal="button_down" from="Control/TouchAltVBoxContainer/Control/FireButton" to="." method="_on_fire_button_button_down"] diff --git a/scenes/spring_laser.gd b/scenes/spring_laser.gd index 2face27..1d37d75 100644 --- a/scenes/spring_laser.gd +++ b/scenes/spring_laser.gd @@ -1,6 +1,6 @@ extends CharacterBody2D -#HACK: moves in the direction of its movement +#HACK: looks in the direction of its movement # Enemy properties var amplitude = 150.0 # Adjust this for the size of the sine wave diff --git a/scenes/world.gd b/scenes/world.gd index 72a3b69..a9b6a93 100644 --- a/scenes/world.gd +++ b/scenes/world.gd @@ -1,5 +1,4 @@ extends Node2D -#FIXME: Convert audio files to check if they work (to .wav?), or find a solution to the poping of audio for fdroid files. #You are a spaceship travelling along an asteriod belt trying to find what seems to be an anomaly,You get switched up into an asteriod but can move like an spaceship, when you try to reach back to your spacemates, they cant hear you and uh oh, looks like a fleet is firing at your asteriod belt. Will you live to tell your tale another day?