From 0fd0fa63f0f59ffae75f776b35d6f923dc564158 Mon Sep 17 00:00:00 2001 From: John Breaux Date: Thu, 21 Oct 2021 01:24:27 -0500 Subject: [PATCH] Improve menuing, and convert ships to RigidBody2D for accurate positioning. --- godot_ship/scenes/Gameplay.tscn | 46 ++++++++----------- godot_ship/scenes/ships/2Ship.tscn | 20 ++++++++ godot_ship/scenes/ships/3ShipB.tscn | 18 ++++++++ godot_ship/scenes/ships/3shipA.tscn | 18 ++++++++ godot_ship/scenes/ships/4Ship.tscn | 20 ++++++++ godot_ship/scenes/ships/5Ship.tscn | 18 ++++++++ godot_ship/script/debug/In.gd | 5 -- godot_ship/script/debug/Out.gd | 2 +- godot_ship/script/debug/debug_menu.gd | 2 +- godot_ship/script/game/Gameplay.gd | 2 + godot_ship/script/game/Main.gd | 9 +++- godot_ship/script/game/moveShip.gd | 29 ++++++++---- godot_ship/script/options/Options.gd | 13 +----- .../script/title screen/Title Screen.gd | 9 ++-- 14 files changed, 153 insertions(+), 58 deletions(-) create mode 100644 godot_ship/scenes/ships/2Ship.tscn create mode 100644 godot_ship/scenes/ships/3ShipB.tscn create mode 100644 godot_ship/scenes/ships/3shipA.tscn create mode 100644 godot_ship/scenes/ships/4Ship.tscn create mode 100644 godot_ship/scenes/ships/5Ship.tscn diff --git a/godot_ship/scenes/Gameplay.tscn b/godot_ship/scenes/Gameplay.tscn index 6496b08..bd3a10a 100644 --- a/godot_ship/scenes/Gameplay.tscn +++ b/godot_ship/scenes/Gameplay.tscn @@ -1,14 +1,13 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://assets/game/board_blue.png" type="Texture" id=1] [ext_resource path="res://script/title screen/Title-Screen-Background.png" type="Texture" id=2] [ext_resource path="res://script/game/Gameplay.gd" type="Script" id=3] -[ext_resource path="res://assets/game/2longShipS.png" type="Texture" id=4] -[ext_resource path="res://assets/game/5longShipS.png" type="Texture" id=5] -[ext_resource path="res://assets/game/3longShipBS.png" type="Texture" id=6] -[ext_resource path="res://assets/game/4longShipS.png" type="Texture" id=7] -[ext_resource path="res://assets/game/3longShipAS.png" type="Texture" id=8] -[ext_resource path="res://script/game/moveShip.gd" type="Script" id=9] +[ext_resource path="res://scenes/ships/2Ship.tscn" type="PackedScene" id=4] +[ext_resource path="res://scenes/ships/5Ship.tscn" type="PackedScene" id=5] +[ext_resource path="res://scenes/ships/3ShipB.tscn" type="PackedScene" id=6] +[ext_resource path="res://scenes/ships/3shipA.tscn" type="PackedScene" id=7] +[ext_resource path="res://scenes/ships/4Ship.tscn" type="PackedScene" id=8] [node name="Game" type="Control"] anchor_right = 1.0 @@ -23,8 +22,9 @@ __meta__ = { } [node name="board_blue" type="Sprite" parent="."] -position = Vector2( 187, 178 ) +position = Vector2( 18, 18 ) texture = ExtResource( 1 ) +centered = false [node name="Title-Screen-Background" type="Sprite" parent="."] show_behind_parent = true @@ -63,30 +63,20 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="2longShipS" type="Sprite" parent="."] -position = Vector2( 600.784, 51.419 ) -texture = ExtResource( 4 ) -script = ExtResource( 9 ) +[node name="2Ship" parent="." instance=ExtResource( 4 )] +position = Vector2( 529.802, 70.7151 ) -[node name="3longShipAS" type="Sprite" parent="."] -position = Vector2( 599.524, 261.826 ) -texture = ExtResource( 8 ) -script = ExtResource( 9 ) +[node name="3ShipA" parent="." instance=ExtResource( 7 )] +position = Vector2( 434.236, 114.21 ) -[node name="3longShipBS" type="Sprite" parent="."] -position = Vector2( 600.784, 146.543 ) -texture = ExtResource( 6 ) -script = ExtResource( 9 ) +[node name="3ShipB" parent="." instance=ExtResource( 6 )] +position = Vector2( 443.216, 266.865 ) -[node name="4longShipS" type="Sprite" parent="."] -position = Vector2( 543.458, 253.006 ) -texture = ExtResource( 7 ) -script = ExtResource( 9 ) +[node name="4Ship" parent="." instance=ExtResource( 8 )] +position = Vector2( 522.911, 218.599 ) -[node name="5longShipS" type="Sprite" parent="."] -position = Vector2( 541.568, 89.2166 ) -texture = ExtResource( 5 ) -script = ExtResource( 9 ) +[node name="5Ship" parent="." instance=ExtResource( 5 )] +position = Vector2( 607.096, 211.864 ) [connection signal="pressed" from="VBoxContainer/Forfeit" to="." method="_on_Forfeit_pressed"] [connection signal="about_to_show" from="ConfirmationDialog" to="." method="_on_ConfirmationDialog_about_to_show"] diff --git a/godot_ship/scenes/ships/2Ship.tscn b/godot_ship/scenes/ships/2Ship.tscn new file mode 100644 index 0000000..4f00023 --- /dev/null +++ b/godot_ship/scenes/ships/2Ship.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://script/game/moveShip.gd" type="Script" id=1] +[ext_resource path="res://assets/game/2longShipS.png" type="Texture" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 16, 32 ) + +[node name="2Ship" type="RigidBody2D"] +input_pickable = true +custom_integrator = true +script = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2( 0, 16 ) +shape = SubResource( 1 ) + +[node name="2longShipS" type="Sprite" parent="."] +position = Vector2( 0, 16 ) +texture = ExtResource( 2 ) diff --git a/godot_ship/scenes/ships/3ShipB.tscn b/godot_ship/scenes/ships/3ShipB.tscn new file mode 100644 index 0000000..980a4e5 --- /dev/null +++ b/godot_ship/scenes/ships/3ShipB.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://script/game/moveShip.gd" type="Script" id=1] +[ext_resource path="res://assets/game/3longShipBS.png" type="Texture" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 16, 48 ) + +[node name="3ShipB" type="RigidBody2D"] +input_pickable = true +custom_integrator = true +script = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) + +[node name="3longShipBS" type="Sprite" parent="."] +texture = ExtResource( 2 ) diff --git a/godot_ship/scenes/ships/3shipA.tscn b/godot_ship/scenes/ships/3shipA.tscn new file mode 100644 index 0000000..f3271a3 --- /dev/null +++ b/godot_ship/scenes/ships/3shipA.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://script/game/moveShip.gd" type="Script" id=1] +[ext_resource path="res://assets/game/3longShipAS.png" type="Texture" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 16, 48 ) + +[node name="3ShipA" type="RigidBody2D"] +input_pickable = true +custom_integrator = true +script = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) + +[node name="3longShipAS" type="Sprite" parent="."] +texture = ExtResource( 2 ) diff --git a/godot_ship/scenes/ships/4Ship.tscn b/godot_ship/scenes/ships/4Ship.tscn new file mode 100644 index 0000000..9961eb2 --- /dev/null +++ b/godot_ship/scenes/ships/4Ship.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://script/game/moveShip.gd" type="Script" id=1] +[ext_resource path="res://assets/game/4longShipS.png" type="Texture" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 16, 64 ) + +[node name="4Ship" type="RigidBody2D"] +input_pickable = true +custom_integrator = true +script = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2( 0, 16 ) +shape = SubResource( 1 ) + +[node name="4longShipS" type="Sprite" parent="."] +position = Vector2( 0, 16 ) +texture = ExtResource( 2 ) diff --git a/godot_ship/scenes/ships/5Ship.tscn b/godot_ship/scenes/ships/5Ship.tscn new file mode 100644 index 0000000..137db4a --- /dev/null +++ b/godot_ship/scenes/ships/5Ship.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://script/game/moveShip.gd" type="Script" id=1] +[ext_resource path="res://assets/game/5longShipS.png" type="Texture" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 16, 80 ) + +[node name="5Ship" type="RigidBody2D"] +input_pickable = true +custom_integrator = true +script = ExtResource( 1 ) + +[node name="5longShipS" type="Sprite" parent="."] +texture = ExtResource( 2 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) diff --git a/godot_ship/script/debug/In.gd b/godot_ship/script/debug/In.gd index 3e76043..4615a9a 100644 --- a/godot_ship/script/debug/In.gd +++ b/godot_ship/script/debug/In.gd @@ -1,9 +1,4 @@ extends LineEdit - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" - func _on_Debug_clear_in(): clear() diff --git a/godot_ship/script/debug/Out.gd b/godot_ship/script/debug/Out.gd index 7b1298f..caf6415 100644 --- a/godot_ship/script/debug/Out.gd +++ b/godot_ship/script/debug/Out.gd @@ -3,7 +3,7 @@ extends TextEdit # Called when the node enters the scene tree for the first time. func _ready(): var _errno = MessageBus.connect("print_console", self, "_on_Debug_print_text") - pass # Replace with function body. + grab_focus() func _on_Debug_print_text(text): diff --git a/godot_ship/script/debug/debug_menu.gd b/godot_ship/script/debug/debug_menu.gd index a928c56..6b33819 100644 --- a/godot_ship/script/debug/debug_menu.gd +++ b/godot_ship/script/debug/debug_menu.gd @@ -48,7 +48,7 @@ func _input(event): # open debug menu debug_active = !debug_active; # Hand the keyboard focus to the next valid focus - if (!debug_active): find_next_valid_focus().grab_focus() + if (!debug_active) && find_next_valid_focus(): find_next_valid_focus().grab_focus() func _on_LineEdit_text_entered(line): emit_signal("clear_in") diff --git a/godot_ship/script/game/Gameplay.gd b/godot_ship/script/game/Gameplay.gd index 0187a94..88e897e 100644 --- a/godot_ship/script/game/Gameplay.gd +++ b/godot_ship/script/game/Gameplay.gd @@ -8,6 +8,7 @@ extends Control # Called when the node enters the scene tree for the first time. func _ready(): + grab_focus() pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -17,3 +18,4 @@ func _ready(): func _on_Forfeit_pressed(): queue_free(); + MessageBus.emit_signal("change_scene", "Title") diff --git a/godot_ship/script/game/Main.gd b/godot_ship/script/game/Main.gd index 42c8c42..7a5995a 100644 --- a/godot_ship/script/game/Main.gd +++ b/godot_ship/script/game/Main.gd @@ -25,7 +25,14 @@ func _ready(): debug_menu = preload("res://scenes/Debug Menu.tscn") if debug_enabled: add_child(debug_menu.instance()) - _on_scene_start("Title") + +# Ensure the scene doesn't become empty +func _process(_delta): + # Make sure there's something running + # Debug counts as one child + if get_child_count() < 1 + int(debug_enabled): + MessageBus.emit_signal("change_scene", "Title") + pass # Creates a new instance of each menu scene func _on_scene_start(scene): diff --git a/godot_ship/script/game/moveShip.gd b/godot_ship/script/game/moveShip.gd index 264b78c..edbfa84 100644 --- a/godot_ship/script/game/moveShip.gd +++ b/godot_ship/script/game/moveShip.gd @@ -1,29 +1,30 @@ -extends Sprite +extends RigidBody2D # Declare member variables here. Examples: # var a = 2 # var b = "text" +var held = false # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. -var dragging = false; var click_radius = 32 var orient = 0; func _input(event): if event is InputEventMouseButton and event.button_index == BUTTON_LEFT: - if(event.position - position).length() < click_radius: - if not dragging and event.pressed: - dragging = true; + if (event.position - position).length() < click_radius: + if not held and event.pressed: + held = true; - if dragging and not event.pressed: - dragging = false; + if held and not event.pressed: + held = false; + position = position.snapped(Vector2(32, 32)) + Vector2(2, 2) - if event is InputEventMouseMotion and dragging: + if event is InputEventMouseMotion and held: position = event.position; if event.is_action_pressed("ui_rotate"): @@ -32,3 +33,15 @@ func _input(event): # Called every frame. 'delta' is the elapsed time since the previous frame. #func _process(delta): # pass + +func pickup(): + if held: + return + mode = RigidBody2D.MODE_STATIC + held = true + +func drop(impulse=Vector2.ZERO): + if held: + mode = RigidBody2D.MODE_RIGID + apply_central_impulse(impulse) + held = false diff --git a/godot_ship/script/options/Options.gd b/godot_ship/script/options/Options.gd index 37cd49f..5afc12f 100644 --- a/godot_ship/script/options/Options.gd +++ b/godot_ship/script/options/Options.gd @@ -1,19 +1,10 @@ extends Control - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" - - # Called when the node enters the scene tree for the first time. func _ready(): - pass # Replace with function body. + find_next_valid_focus().grab_focus() -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass - func _on_Button_pressed(): queue_free() + MessageBus.emit_signal("change_scene", "Title") diff --git a/godot_ship/script/title screen/Title Screen.gd b/godot_ship/script/title screen/Title Screen.gd index be52568..0412dc2 100644 --- a/godot_ship/script/title screen/Title Screen.gd +++ b/godot_ship/script/title screen/Title Screen.gd @@ -6,17 +6,20 @@ extends Control # Called when the node enters the scene tree for the first time. func _ready(): - #$VBoxContainer/Singleplayer.grab_focus() - pass + $VBoxContainer/Singleplayer.grab_focus() func _on_Singleplayer_pressed(): MessageBus.emit_signal("change_scene", "Singleplayer") - + queue_free() + func _on_Multiplayer_pressed(): MessageBus.emit_signal("change_scene", "Multiplayer") + queue_free() func _on_Options_pressed(): MessageBus.emit_signal("change_scene", "Options") + queue_free() func _on_Quit_pressed(): MessageBus.emit_signal("quit") + queue_free()