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/Network.gd b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network.gd new file mode 100644 index 0000000..1fbc43d --- /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."): + 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..426b3d1 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Network_Setup.gd @@ -0,0 +1,32 @@ +extends Control + + +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") + +func _player_disconnected(id) -> void: + print("Player " + str(id) + "disconnected") + +func _on_Create_Server_pressed(): + multiplayer.config_ui.hide() + Network._create_server() + +func _on_Join_Server_pressed(): + if server_ip_address.text != "": + multiplayer_config_ui.hide() + Network.ip_address = server_ip_address.text + Network._join_server() 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/Test.tscn b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Test.tscn new file mode 100644 index 0000000..45a4ba7 --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/Test.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Network.gd" type="Script" id=1] + +[node name="Node" type="Node"] +script = ExtResource( 1 ) 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..aa2113f --- /dev/null +++ b/Phase2/Godot ===(Game Code)===/Experiments/Andrew_Multiplayer_Test/project.godot @@ -0,0 +1,26 @@ +; 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" +config/icon="res://icon.png" + +[autoload] + +Network="*res://Network.gd" + +[physics] + +common/enable_pause_aware_picking=true + +[rendering] + +environment/default_environment="res://default_env.tres"