From 5cfe3852912d128021ca83d793a71beae43c8dac Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Fri, 1 Dec 2023 16:25:20 +0100 Subject: [PATCH 1/4] Implement rudimentary controller support --- src/project.godot | 67 ++++++++++++++++++- .../destination_menu/DestinationMenu.tscn | 4 +- src/screens/destination_menu/TabContainer.gd | 13 ++++ src/screens/main_game/MainGame.gd | 2 +- src/screens/title/TitleScreen.gd | 5 +- src/spaceship/spaceship.gd | 8 +-- src/spaceship/spaceship.tscn | 4 +- src/tutorial/tutorial.gd | 6 +- 8 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 src/screens/destination_menu/TabContainer.gd diff --git a/src/project.godot b/src/project.godot index c53dc32..76ada46 100644 --- a/src/project.godot +++ b/src/project.godot @@ -24,7 +24,7 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://spaceship/modules/fuel_tank.gd" }, { -"base": "Reference", +"base": "CanvasLayer", "class": "GameOver", "language": "GDScript", "path": "res://screens/game_over/GameOver.gd" @@ -161,11 +161,22 @@ texture={ [input] +ui_focus_next={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777218,"unicode":0,"echo":false,"script":null) + ] +} +ui_focus_prev={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777218,"unicode":0,"echo":false,"script":null) + ] +} ui_left={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null) ] } ui_right={ @@ -173,6 +184,7 @@ ui_right={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null) ] } ui_up={ @@ -180,6 +192,7 @@ ui_up={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) ] } ui_down={ @@ -187,31 +200,83 @@ ui_down={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null) + ] +} +ui_next_tab={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777236,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":5,"pressure":0.0,"pressed":false,"script":null) + ] +} +ui_previous_tab={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777235,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":4,"pressure":0.0,"pressed":false,"script":null) + ] +} +ui_quit={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":10,"pressure":0.0,"pressed":false,"script":null) ] } zoom_in={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777235,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null) ] } zoom_out={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777236,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) ] } pause={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null) + ] +} +ship_accelerate={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":7,"axis_value":1.0,"script":null) + ] +} +ship_decelerate={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":6,"axis_value":1.0,"script":null) ] } ship_thrust_left={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":4,"pressure":0.0,"pressed":false,"script":null) ] } ship_thrust_right={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":69,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":5,"pressure":0.0,"pressed":false,"script":null) + ] +} +ship_turn_left={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null) + ] +} +ship_turn_right={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null) ] } diff --git a/src/screens/destination_menu/DestinationMenu.tscn b/src/screens/destination_menu/DestinationMenu.tscn index 09f4ac4..7b2beb1 100644 --- a/src/screens/destination_menu/DestinationMenu.tscn +++ b/src/screens/destination_menu/DestinationMenu.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://screens/destination_menu/DestinationMenu.gd" type="Script" id=1] [ext_resource path="res://screens/destination_menu/fuel_station/FuelStationContainer.tscn" type="PackedScene" id=2] [ext_resource path="res://screens/destination_menu/ship_repairs/RepairOption.tscn" type="PackedScene" id=3] [ext_resource path="res://assets/LeaveButtonHigherRes.png" type="Texture" id=4] [ext_resource path="res://screens/destination_menu/passenger_pickup/PassengerPickupOption.tscn" type="PackedScene" id=5] +[ext_resource path="res://screens/destination_menu/TabContainer.gd" type="Script" id=6] [node name="PlanetMenu" type="CanvasLayer"] layer = 3 @@ -57,6 +58,7 @@ margin_top = -0.262001 margin_right = -31.0 margin_bottom = 0.231995 tab_align = 0 +script = ExtResource( 6 ) __meta__ = { "_edit_use_anchors_": false } diff --git a/src/screens/destination_menu/TabContainer.gd b/src/screens/destination_menu/TabContainer.gd new file mode 100644 index 0000000..7adee1d --- /dev/null +++ b/src/screens/destination_menu/TabContainer.gd @@ -0,0 +1,13 @@ +extends TabContainer + + +func _input(event): + if event.is_action_pressed("ui_next_tab"): + current_tab = (get_child_count() + current_tab + 1) % get_child_count() + elif event.is_action_pressed("ui_previous_tab"): + current_tab = (get_child_count() + current_tab - 1) % get_child_count() + + +func cycle_tab(backwards = false): + var next_tab = current_tab + (-1 if backwards else 1) + current_tab = (get_child_count() + next_tab) % get_child_count() diff --git a/src/screens/main_game/MainGame.gd b/src/screens/main_game/MainGame.gd index 463a1b6..4b50f2b 100644 --- a/src/screens/main_game/MainGame.gd +++ b/src/screens/main_game/MainGame.gd @@ -48,7 +48,7 @@ func open_pause_menu(): # Called on input events func _unhandled_input(event): - if event.is_action_pressed("ui_cancel"): + if event.is_action_pressed("ui_quit"): # Change to pause menu open_pause_menu() diff --git a/src/screens/title/TitleScreen.gd b/src/screens/title/TitleScreen.gd index e2794f5..e079ba3 100644 --- a/src/screens/title/TitleScreen.gd +++ b/src/screens/title/TitleScreen.gd @@ -17,9 +17,12 @@ func _ready(): if is_pause_screen: $CanvasLayer/CenterContainer/ColorRect/StartGameButton.text = "Continue game" + # Set focus to start button to allow control via keyboard/controller + $CanvasLayer/CenterContainer/ColorRect/StartGameButton.grab_focus() + func _unhandled_input(event): - if event.is_action_pressed("ui_cancel"): + if event.is_action_pressed("ui_quit"): get_tree().quit() diff --git a/src/spaceship/spaceship.gd b/src/spaceship/spaceship.gd index 2407cb4..e008ef9 100644 --- a/src/spaceship/spaceship.gd +++ b/src/spaceship/spaceship.gd @@ -155,9 +155,9 @@ func _integrate_forces(state): # Thrust direction var move_forwards = 0 var move_sideways = 0 - if Input.is_action_pressed("ui_up"): + if Input.is_action_pressed("ship_accelerate"): move_forwards = 1 - if Input.is_action_pressed("ui_down"): + if Input.is_action_pressed("ship_decelerate"): move_forwards = -1 if Input.is_action_pressed("ship_thrust_left"): move_sideways = -1 @@ -193,9 +193,9 @@ func _integrate_forces(state): # Rotation var rotation_dir = 0 - if Input.is_action_pressed("ui_left"): + if Input.is_action_pressed("ship_turn_left"): rotation_dir -= 1 - if Input.is_action_pressed("ui_right"): + if Input.is_action_pressed("ship_turn_right"): rotation_dir += 1 if rotation_dir: diff --git a/src/spaceship/spaceship.tscn b/src/spaceship/spaceship.tscn index a9d0dd4..8d8d8d3 100644 --- a/src/spaceship/spaceship.tscn +++ b/src/spaceship/spaceship.tscn @@ -5,9 +5,7 @@ [ext_resource path="res://sound/exhaust.wav" type="AudioStream" id=3] [ext_resource path="res://sound/explosion.wav" type="AudioStream" id=4] -[node name="Spaceship" type="RigidBody2D" groups=[ -"Spaceship", -]] +[node name="Spaceship" type="RigidBody2D" groups=["Spaceship"]] gravity_scale = 0.0 contacts_reported = 100 contact_monitor = true diff --git a/src/tutorial/tutorial.gd b/src/tutorial/tutorial.gd index 1798163..6b81aa8 100644 --- a/src/tutorial/tutorial.gd +++ b/src/tutorial/tutorial.gd @@ -26,14 +26,14 @@ func _process(delta): if steps[current_step_index].auto_advance == 1: var input_index = steps[current_step_index].auto_advance_data # TODO: zoom events don't get caught for some reason, so fix that before using them - if (Input.is_action_pressed("ui_up") and input_index == 0) \ - or (Input.is_action_pressed("ui_down") and input_index == 1) \ + if (Input.is_action_pressed("ship_accelerate") and input_index == 0) \ + or (Input.is_action_pressed("ship_decelerate") and input_index == 1) \ or (Input.is_action_pressed("ship_thrust_left") and input_index == 2) \ or (Input.is_action_pressed("ship_thrust_right") and input_index == 3) \ or (Input.is_action_pressed("zoom_in") and input_index == 4) \ or (Input.is_action_pressed("zoom_out") and input_index == 5) \ or (Input.is_action_pressed("pause") and input_index == 6) \ - or (Input.is_action_pressed("ui_left") and input_index == 7): + or (Input.is_action_pressed("ship_turn_left") and input_index == 7): advance_tutorial_step() From ac59fbb04f70ab946708a59230d55c7c37530c79 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Sat, 2 Dec 2023 16:06:43 +0100 Subject: [PATCH 2/4] Improve ship rotation via left analog stick --- src/project.godot | 2 -- src/spaceship/spaceship.gd | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/project.godot b/src/project.godot index 76ada46..adefa47 100644 --- a/src/project.godot +++ b/src/project.godot @@ -269,14 +269,12 @@ ship_turn_left={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null) -, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null) ] } ship_turn_right={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null) -, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null) ] } diff --git a/src/spaceship/spaceship.gd b/src/spaceship/spaceship.gd index e008ef9..5b466fc 100644 --- a/src/spaceship/spaceship.gd +++ b/src/spaceship/spaceship.gd @@ -13,6 +13,8 @@ signal fuel_changed(total_capacity, current_fuel) const TORQUE_PER_THRUST = 35 const DISTANCE_AFTER_PLANET_MENU = 32 const VELOCITY_AFTER_PLANET_MENU = 200 +const ANALOG_STICK_DEADZONE = 0.5 +const ANALOG_ROTATION_DEADZONE = 0.2 # Define properties and internal variables export var current_passenger = {"name": "nobody"} @@ -198,6 +200,23 @@ func _integrate_forces(state): if Input.is_action_pressed("ship_turn_right"): rotation_dir += 1 + # Rotation via left analog stick + var left_stick_vector = Vector2( + -Input.get_joy_axis(0, JOY_AXIS_1), + Input.get_joy_axis(0, JOY_AXIS_0) + ) + + if left_stick_vector.length_squared() > ANALOG_STICK_DEADZONE: + var left_stick_angle = left_stick_vector.angle() + var rotation_delta = left_stick_angle - rotation + + # Find the shortest rotation (e.g. rotate -40° instead of +320° to get from 160° to -160°) + if abs(rotation_delta) > PI: + rotation_delta -= sign(rotation_delta) * 2 * PI + + if abs(rotation_delta) > ANALOG_ROTATION_DEADZONE: + rotation_dir = sign(rotation_delta) + if rotation_dir: var ship_total_torque = ship_total_thrust * TORQUE_PER_THRUST add_torque(rotation_dir * ship_total_torque) From 368da456d1cb225812113251f4e8d42eb1becc4c Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Sat, 2 Dec 2023 16:37:03 +0100 Subject: [PATCH 3/4] Show controller keys in tutorial if controller is connected --- src/tutorial/tutorial.gd | 88 +++++++++++++++++++++++++++++++++------- 1 file changed, 74 insertions(+), 14 deletions(-) diff --git a/src/tutorial/tutorial.gd b/src/tutorial/tutorial.gd index 6b81aa8..466e5c0 100644 --- a/src/tutorial/tutorial.gd +++ b/src/tutorial/tutorial.gd @@ -3,21 +3,74 @@ extends CanvasLayer var current_step_index = 0 -onready var steps = [ - TutorialStep.new('Welcome to space!', 'Your objective is to fly passengers from planet to planet.', 0, 3), - TutorialStep.new('However, you will need to watch out!\nHitting asteroids will damage your ship.', '(your ship is not that stable, sadly)', 0, 3.5), - TutorialStep.new('But first things first.', 'Press W to accelerate', 1, 0), - TutorialStep.new('Nicely done!\nIt almost looks like you played a video game before!', 'Press S to decellerate', 1, 1), - TutorialStep.new('You can also turn your ship!', 'To do so press A or D', 1, 7), - TutorialStep.new('Alright!\nDid you know you can also strave?', 'Press Q to strave left and E to strave right', 1, 2), - TutorialStep.new('You have access to a super advanced map.', 'Press [Space] to open it', 1, 6), - TutorialStep.new('If you hover on a planet, you can see info about it', 'You should be extra careful when getting close to hostile planets.', 0, 5), - TutorialStep.new('You can also click anywhere on the map\nIf you want to set a waypoint.', 'Press [Space] again to leave the map.', 1, 6), - TutorialStep.new('If you want to get some of that mappy feeling\nbut don\'t want to pause the game', 'Use the scroll wheel to zoom', 0, 5), - TutorialStep.new('Looks like you are ready to start you space adventure!', 'Have fun and remember that this game was made in a single weekend.', 0, 5) - ] +var steps = null func _ready(): + # Show either keyboard keys or controller keys depending on whether a controller is connected + var use_controller_layout = Input.get_connected_joypads().size() > 0 + + # Generate tutorial messages + steps = [ + TutorialStep.new( + 'Welcome to space!', + 'Your objective is to fly passengers from planet to planet.', + 0, 3 + ), + TutorialStep.new( + 'However, you will need to watch out!\nHitting asteroids will damage your ship.', + '(your ship is not that stable, sadly)', + 0, 3.5 + ), + TutorialStep.new( + 'But first things first.', + 'Press [%s] to accelerate.' % ('R2' if use_controller_layout else 'W'), + 1, 0 + ), + TutorialStep.new( + 'Nicely done!\nIt almost looks like you played a video game before!', + 'Press [%s] to decelerate.' % ('L2' if use_controller_layout else 'S'), + 1, 1 + ), + TutorialStep.new( + 'You can also turn your ship!', + 'To do so, use the left stick.' if use_controller_layout else 'To do so, press [A] or [D].', + 1, 7 + ), + TutorialStep.new( + 'Alright!\nDid you know you can also strafe?', + 'Press [%s] to strafe left and [%s] to strafe right.' % [ + 'L1' if use_controller_layout else 'Q', + 'R1' if use_controller_layout else 'E' + ], + 1, 2 + ), + TutorialStep.new( + 'You have access to a super advanced map.', + 'Press [%s] to open it' % ('Start' if use_controller_layout else 'Space'), + 1, 6 + ), + TutorialStep.new( + 'If you hover on a planet, you can see info about it', + 'You should be extra careful when getting close to hostile planets.', + 0, 5 + ), + TutorialStep.new( + 'You can also click anywhere on the map\nIf you want to set a waypoint.', + 'Press [%s] again to leave the map.' % ('Start' if use_controller_layout else 'Space'), + 1, 6 + ), + TutorialStep.new( + 'If you want to get some of that mappy feeling\nbut don\'t want to pause the game', + 'Use [Up] and [Down] to zoom.' if use_controller_layout else 'Use the scroll wheel to zoom.', + 0, 5 + ), + TutorialStep.new( + 'Looks like you are ready to start you space adventure!', + 'Have fun and remember that this game was made in a single weekend.', + 0, 5 + ) + ] + $NextInfoTimer.start(1) render_tutorial_step() @@ -26,6 +79,12 @@ func _process(delta): if steps[current_step_index].auto_advance == 1: var input_index = steps[current_step_index].auto_advance_data # TODO: zoom events don't get caught for some reason, so fix that before using them + + var left_stick_moved = Vector2( + -Input.get_joy_axis(0, JOY_AXIS_1), + Input.get_joy_axis(0, JOY_AXIS_0) + ).length_squared() > 0.5 + if (Input.is_action_pressed("ship_accelerate") and input_index == 0) \ or (Input.is_action_pressed("ship_decelerate") and input_index == 1) \ or (Input.is_action_pressed("ship_thrust_left") and input_index == 2) \ @@ -33,7 +92,8 @@ func _process(delta): or (Input.is_action_pressed("zoom_in") and input_index == 4) \ or (Input.is_action_pressed("zoom_out") and input_index == 5) \ or (Input.is_action_pressed("pause") and input_index == 6) \ - or (Input.is_action_pressed("ship_turn_left") and input_index == 7): + or (Input.is_action_pressed("ship_turn_left") and input_index == 7) \ + or (left_stick_moved and input_index == 7): advance_tutorial_step() From c7af3d262f1353a5392e51d7f5c9b2782d24b752 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Sat, 2 Dec 2023 16:50:41 +0100 Subject: [PATCH 4/4] Only use direction-based rotation with left stick if camera rotation is off --- src/spaceship/spaceship.gd | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/spaceship/spaceship.gd b/src/spaceship/spaceship.gd index 5b466fc..ba7ee3c 100644 --- a/src/spaceship/spaceship.gd +++ b/src/spaceship/spaceship.gd @@ -201,21 +201,29 @@ func _integrate_forces(state): rotation_dir += 1 # Rotation via left analog stick - var left_stick_vector = Vector2( - -Input.get_joy_axis(0, JOY_AXIS_1), - Input.get_joy_axis(0, JOY_AXIS_0) - ) + if settings.camera_rotation: + # When camera rotation is on, just turn left/right if the stick is pushed left/right (like with keyboard controls) + var left_stick_x = Input.get_joy_axis(0, JOY_AXIS_0) - if left_stick_vector.length_squared() > ANALOG_STICK_DEADZONE: - var left_stick_angle = left_stick_vector.angle() - var rotation_delta = left_stick_angle - rotation + if abs(left_stick_x) > ANALOG_STICK_DEADZONE: + rotation_dir = sign(left_stick_x) + else: + # When camera rotation is off, rotate ship into the current direction of the stick + var left_stick_vector = Vector2( + -Input.get_joy_axis(0, JOY_AXIS_1), + Input.get_joy_axis(0, JOY_AXIS_0) + ) + + if left_stick_vector.length_squared() > ANALOG_STICK_DEADZONE: + var left_stick_angle = left_stick_vector.angle() + var rotation_delta = left_stick_angle - rotation - # Find the shortest rotation (e.g. rotate -40° instead of +320° to get from 160° to -160°) - if abs(rotation_delta) > PI: - rotation_delta -= sign(rotation_delta) * 2 * PI + # Find the shortest rotation (e.g. rotate -40° instead of +320° to get from 160° to -160°) + if abs(rotation_delta) > PI: + rotation_delta -= sign(rotation_delta) * 2 * PI - if abs(rotation_delta) > ANALOG_ROTATION_DEADZONE: - rotation_dir = sign(rotation_delta) + if abs(rotation_delta) > ANALOG_ROTATION_DEADZONE: + rotation_dir = sign(rotation_delta) if rotation_dir: var ship_total_torque = ship_total_thrust * TORQUE_PER_THRUST