diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd index 6c826ed..e0efd6b 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd @@ -1,7 +1,7 @@ extends Node -func instance_node(node: Object, parent: Object) -> Object: +func _instance_node(node: Object, parent: Object) -> Object: var node_instance = node.instance() parent.add_child(node_instance) return node_instance diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd index 7782a71..e3a25a8 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd @@ -5,6 +5,8 @@ const MAX_CLIENTS = 6 var server = null var client = null +var player_counter = 1 +var player = load("res://Player.tscn") var ip_address = "" var room_name = "" @@ -39,3 +41,13 @@ func _server_disconnected() -> void: func _set_server_info(name, password) -> void: room_name = name room_password = password + +func _instance_player(id, name) -> void: + var player_instance = Global._instance_node(player, Players) + player_instance.name = str(id) + player_instance._set_name(name) + #Using player_counter to determine the positioning of the player's name on the screen + #So that they aren't all overlapping + player_instance._set_name_position(player_counter) + player_instance.set_network_master(id) + player_counter += 1 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd deleted file mode 100644 index 1b2737d..0000000 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd +++ /dev/null @@ -1,55 +0,0 @@ -extends Control - - -#var playerCounter = 1 -#var player = load("res://Player.tscn") -# -#onready var multiplayer_config_ui = $Multiplayer_Configure -#onready var server_ip_address = $Multiplayer_Configure/Server_IP_Address -#onready var device_ip_address = $CanvasLayer/Device_IP_Address -# -# -# -## Called when the node enters the scene tree for the first time. -#func _ready(): -# get_tree().connect("network_peer_connected", self, "_player_connected") -# get_tree().connect("network_peer_disconnected", self, "_player_disconnected") -# get_tree().connect("connected_to_server", self, "_connected_to_server") -# -# device_ip_address.text = Network.ip_address -# -#func _player_connected(id) -> void: -# print("Player " + str(id) + "connected") -# instance_player(id) -# -#func _player_disconnected(id) -> void: -# print("Player " + str(id) + "disconnected") -# -# if Players.has_node(str(id)): -# Players.get_node(str(id)).queue_free() -# -#func _on_Create_Server_pressed(): -# multiplayer_config_ui.hide() -# Network._create_server() -# instance_player(get_tree().get_network_unique_id()) -# -#func _on_Join_Server_pressed(): -# if server_ip_address.text != "": -# multiplayer_config_ui.hide() -# Network.ip_address = server_ip_address.text -# Network._join_server() -# -#func _connected_to_server() -> void: -# yield(get_tree().create_timer(0.1), "timeout") -# instance_player(get_tree().get_network_unique_id()) -# -#func instance_player(id) -> void: -# var player_instance = Global.instance_node(player, Players) -# player_instance.name = str(id) -# var player_name = "Player " + str(playerCounter) -# player_instance._set_name(player_name) -# player_instance._set_name_position(playerCounter) -# player_instance.set_network_master(id) -# playerCounter += 1 - - diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn index 82e64be..b4b93c3 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn @@ -1,12 +1,10 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=2] -[ext_resource path="res://Network_Setup.gd" type="Script" id=1] [ext_resource path="res://But_ChangeScene.gd" type="Script" id=2] [node name="Network_Setup" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 -script = ExtResource( 1 ) [node name="Multiplayer_Configure" type="Control" parent="."] anchor_right = 1.0 @@ -36,8 +34,10 @@ margin_right = 125.0 margin_bottom = -29.0 text = "Join Server" script = ExtResource( 2 ) +next_scene_path = "res://Room_Join.tscn" [node name="Server_IP_Address" type="LineEdit" parent="Multiplayer_Configure"] +visible = false margin_left = 389.0 margin_top = 82.0 margin_right = 639.0 @@ -59,3 +59,4 @@ align = 1 valign = 1 [connection signal="button_up" from="Multiplayer_Configure/Create_Server" to="Multiplayer_Configure/Create_Server" method="_on_But_NewGame_button_up"] +[connection signal="button_up" from="Multiplayer_Configure/Join_Server" to="Multiplayer_Configure/Join_Server" method="_on_But_NewGame_button_up"] diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd index e2ac87e..dc7ba6f 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.gd @@ -24,7 +24,7 @@ func _ready(): func _player_connected(id) -> void: print("Player " + str(id) + "connected") - instance_player(id) + Network._instance_player(id, "New Player") func _player_disconnected(id) -> void: print("Player " + str(id) + "disconnected") @@ -35,7 +35,7 @@ func _player_disconnected(id) -> void: func _on_Create_Server_pressed(): multiplayer_config_ui.hide() Network._create_server() - instance_player(get_tree().get_network_unique_id()) + Network._instance_player(get_tree().get_network_unique_id(), player_name.text) Network._set_server_info(room_name.text, room_password.text) $Room_UI/Room_Name.text = room_name.text room_ui.show() @@ -48,12 +48,6 @@ func _on_Create_Server_pressed(): func _connected_to_server() -> void: yield(get_tree().create_timer(0.1), "timeout") - instance_player(get_tree().get_network_unique_id()) + Network._instance_player(get_tree().get_network_unique_id(), player_name.text) + -func instance_player(id) -> void: - var player_instance = Global.instance_node(player, Players) - player_instance.name = str(id) - player_instance._set_name(player_name.text) - player_instance._set_name_position(playerCounter) - player_instance.set_network_master(id) - playerCounter += 1 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn index 2543f5f..28c5aaf 100644 --- a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Creation.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://Room_Creation.gd" type="Script" id=1] +[ext_resource path="res://But_ChangeScene.gd" type="Script" id=2] [node name="Room_Creation" type="Control"] anchor_right = 1.0 @@ -13,6 +14,8 @@ margin_top = 419.0 margin_right = 474.0 margin_bottom = 493.0 text = "Back" +script = ExtResource( 2 ) +next_scene_path = "res://Network_Setup.tscn" [node name="Multiplayer_Configure" type="Control" parent="."] margin_right = 40.0 @@ -70,9 +73,10 @@ anchor_bottom = 1.0 [node name="Room_Name" type="Label" parent="Room_UI"] anchor_left = 0.5 anchor_right = 0.5 -margin_left = -20.0 -margin_right = 20.0 +margin_left = -80.5 +margin_right = 80.5 margin_bottom = 14.0 +align = 1 [node name="Players" type="Label" parent="Room_UI"] anchor_right = 1.0 @@ -83,4 +87,5 @@ text = "Players:" align = 1 valign = 1 +[connection signal="button_up" from="Back" to="Back" method="_on_But_NewGame_button_up"] [connection signal="pressed" from="Multiplayer_Configure/Create_Server" to="." method="_on_Create_Server_pressed"] diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.gd new file mode 100644 index 0000000..5202eea --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.gd @@ -0,0 +1,13 @@ +extends Control + +onready var multiplayer_config_ui = $Multiplayer_Configure +onready var server_ip_address = $Multiplayer_Configure/Server_IP_Address +onready var room_password = $Multiplayer_Configure/Room_Password +onready var player_name = $Multiplayer_Configure/Player_Name + +func _on_Join_Server_pressed(): + if server_ip_address.text != "": + multiplayer_config_ui.hide() + Network.ip_address = server_ip_address.text + Network._join_server() + Network._instance_player(get_tree().get_network_unique_id(), player_name.text) diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.tscn new file mode 100644 index 0000000..a2ca72a --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Room_Join.tscn @@ -0,0 +1,60 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Room_Join.gd" type="Script" id=1] +[ext_resource path="res://But_ChangeScene.gd" type="Script" id=2] + +[node name="Room_Join" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) + +[node name="Multiplayer_Configure" type="Control" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="Server_IP_Address" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 386.0 +margin_top = 236.0 +margin_right = 636.0 +margin_bottom = 286.0 +text = "Enter Room IP" +align = 1 + +[node name="Join_Server" type="Button" parent="Multiplayer_Configure"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = 21.0 +margin_top = 93.0 +margin_right = 271.0 +margin_bottom = 193.0 +text = "Join Server" + +[node name="Room_Password" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 388.0 +margin_top = 311.0 +margin_right = 638.0 +margin_bottom = 361.0 +text = "Room Password" +align = 1 + +[node name="Player_Name" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 387.0 +margin_top = 164.0 +margin_right = 637.0 +margin_bottom = 214.0 +text = "Player Name" +align = 1 + +[node name="Back" type="Button" parent="."] +margin_left = 235.0 +margin_top = 394.0 +margin_right = 485.0 +margin_bottom = 494.0 +text = "Back" +script = ExtResource( 2 ) +next_scene_path = "res://Network_Setup.tscn" + +[connection signal="pressed" from="Multiplayer_Configure/Join_Server" to="." method="_on_Join_Server_pressed"] +[connection signal="button_up" from="Back" to="Back" method="_on_But_NewGame_button_up"]