Added basic connection functionality

pull/1/head
Damien Watson 2020-02-04 16:38:02 +00:00
parent 3d66a68244
commit aaa928e660
6 changed files with 131 additions and 0 deletions

38
Scenes/RootNode.tscn Normal file
View File

@ -0,0 +1,38 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scripts/RootNode.gd" type="Script" id=1]
[node name="RootNode" type="Node"]
script = ExtResource( 1 )
[node name="Lobby" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="IPLineEdit" type="LineEdit" parent="Lobby"]
anchor_left = 0.5
anchor_top = 0.3
anchor_right = 0.5
anchor_bottom = 0.3
margin_left = -100.0
margin_right = 100.0
margin_bottom = 25.0
placeholder_text = "Enter IP Address of Server"
[node name="StartButton" type="Button" parent="Lobby"]
anchor_left = 0.5
anchor_top = 0.3
anchor_right = 0.5
anchor_bottom = 0.3
margin_left = -40.0
margin_top = 40.0
margin_right = 40.0
margin_bottom = 25.0
text = "Start"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="Lobby/StartButton" to="." method="_on_StartButton_pressed"]

28
Scripts/RootNode.gd Normal file
View File

@ -0,0 +1,28 @@
extends Node
const PORT : int = 9374
func _ready() -> void:
get_tree().connect("connected_to_server", self, "_connected_to_server")
get_tree().connect("server_disconnected", self, "_server_disconnected")
get_tree().connect("connection_failed", self, "_connection_failed")
func _connected_to_server() -> void:
print("Connected to server") # Let the server know all about us (eg name)
func _server_disconnected() -> void:
print("Disconnected from server") # Kick us out the game and bring back the lobby (if applicable)
func _connection_failed() -> void:
print("Connection Error")
func _on_StartButton_pressed() -> void:
var ip_addr : String = $Lobby/IPLineEdit.text
var peer : NetworkedMultiplayerENet = NetworkedMultiplayerENet.new()
peer.create_client(ip_addr, PORT)
get_tree().set_network_peer(peer)

7
default_env.tres Normal file
View File

@ -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 )

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

34
icon.png.import Normal file
View File

@ -0,0 +1,34 @@
[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
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

24
project.godot Normal file
View File

@ -0,0 +1,24 @@
; 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
_global_script_classes=[ ]
_global_script_class_icons={
}
[application]
config/name="Client"
run/main_scene="res://Scenes/RootNode.tscn"
config/icon="res://icon.png"
[rendering]
environment/default_environment="res://default_env.tres"