diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/.gdignore b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/.gdignore new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/.gdignore @@ -0,0 +1 @@ + diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 new file mode 100644 index 0000000..5328bc7 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 @@ -0,0 +1,3 @@ +source_md5="47313fa4c47a9963fddd764e1ec6e4a8" +dest_md5="26ea799ea0a3da9e753b3ebe822e0570" + diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex new file mode 100644 index 0000000..71f6913 Binary files /dev/null and b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex differ diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd new file mode 100644 index 0000000..6c826ed --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Global.gd @@ -0,0 +1,9 @@ +extends Node + + +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 new file mode 100644 index 0000000..052b427 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd @@ -0,0 +1,35 @@ +extends Node + +const DEFAULT_PORT = 28960 +const MAX_CLIENTS = 6 + +var server = null +var client = null + +var ip_address = "" + +func _ready() -> void: + ip_address = IP.get_local_addresses()[3] + + for ip in IP.get_local_addresses(): + if ip.begins_with("192.168.") and not ip.ends_with(".1"): + ip_address = ip + + get_tree().connect("connected_to_server", self, "_connected_to_server") + get_tree().connect("server_disconnected", self, "_server_disconnected") + +func _create_server() -> void: + server = NetworkedMultiplayerENet.new() + server.create_server(DEFAULT_PORT, MAX_CLIENTS) + get_tree().set_network_peer(server) + +func _join_server() -> void: + client = NetworkedMultiplayerENet.new() + client.create_client(ip_address, DEFAULT_PORT) + get_tree().set_network_peer(client) + +func _connected_to_server() -> void: + print("Successfully connected to the server") + +func _server_disconnected() -> void: + print("Disconnected from the server") 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 new file mode 100644 index 0000000..f1bee1b --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd @@ -0,0 +1,53 @@ +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 new file mode 100644 index 0000000..49caf72 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.tscn @@ -0,0 +1,58 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Network_Setup.gd" type="Script" id=1] + +[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 +anchor_bottom = 1.0 + +[node name="Create_Server" type="Button" parent="Multiplayer_Configure"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -125.0 +margin_top = 21.0 +margin_right = 125.0 +margin_bottom = 121.0 +text = "Create Server" + +[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 = -125.0 +margin_top = -129.0 +margin_right = 125.0 +margin_bottom = -29.0 +text = "Join Server" + +[node name="Server_IP_Address" type="LineEdit" parent="Multiplayer_Configure"] +margin_left = 389.0 +margin_top = 82.0 +margin_right = 639.0 +margin_bottom = 132.0 +text = "Enter IP Address" +align = 1 + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="Device_IP_Address" type="Label" parent="CanvasLayer"] +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = -1.0 +margin_top = -76.0 +margin_right = -1.0 +margin_bottom = -26.0 +align = 1 +valign = 1 + +[connection signal="pressed" from="Multiplayer_Configure/Create_Server" to="." method="_on_Create_Server_pressed"] +[connection signal="pressed" from="Multiplayer_Configure/Join_Server" to="." method="_on_Join_Server_pressed"] diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.gd new file mode 100644 index 0000000..d47114b --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.gd @@ -0,0 +1,7 @@ +extends Control + +func _set_name(name) -> void: + $Name.text = name + +func _set_name_position(counterVal) -> void: + $Name.rect_position.y = -225 + (50 * counterVal) diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.tscn new file mode 100644 index 0000000..ce42f2b --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Player.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Player.gd" type="Script" id=1] + +[node name="Player" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) + +[node name="Name" type="Label" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_top = -175.0 +margin_bottom = -175.0 +text = "Name" +align = 1 +valign = 1 + +[node name="Players" type="Label" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_top = -225.0 +margin_bottom = -225.0 +text = "Players:" +align = 1 +valign = 1 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Players.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Players.tscn new file mode 100644 index 0000000..2683f83 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Players.tscn @@ -0,0 +1,3 @@ +[gd_scene format=2] + +[node name="Players" type="Node"] diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/default_env.tres b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/default_env.tres new file mode 100644 index 0000000..20207a4 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/default_env.tres @@ -0,0 +1,7 @@ +[gd_resource type="Environment" load_steps=2 format=2] + +[sub_resource type="ProceduralSky" id=1] + +[resource] +background_mode = 2 +background_sky = SubResource( 1 ) diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png new file mode 100644 index 0000000..c98fbb6 Binary files /dev/null and b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png differ diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png.import b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png.import new file mode 100644 index 0000000..a4c02e6 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/icon.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.png" +dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/project.godot b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/project.godot new file mode 100644 index 0000000..7546d2a --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/project.godot @@ -0,0 +1,29 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=4 + +[application] + +config/name="Multiplayer Test" +run/main_scene="res://Network_Setup.tscn" +config/icon="res://icon.png" + +[autoload] + +Network="*res://Network.gd" +Global="*res://Global.gd" +Players="*res://Players.tscn" + +[physics] + +common/enable_pause_aware_picking=true + +[rendering] + +environment/default_environment="res://default_env.tres"