Added basic connection functionality

pull/1/head
Damien Watson 2020-02-04 16:46:32 +00:00
parent 94ac9482d9
commit a91e1b4f3c
6 changed files with 101 additions and 0 deletions

6
Scenes/RootNode.tscn Normal file
View File

@ -0,0 +1,6 @@
[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 )

30
Scripts/RootNode.gd Normal file
View File

@ -0,0 +1,30 @@
extends Node
const MAX_PLAYERS : int = 2
const PORT : int = 9374
var ids = []
func _ready() -> void:
var peer : NetworkedMultiplayerENet = NetworkedMultiplayerENet.new()
peer.create_server( PORT, MAX_PLAYERS )
get_tree().set_network_peer( peer )
get_tree().connect("network_peer_connected", self, "_peer_connected")
get_tree().connect("network_peer_disconnected", self, "_peer_disconnected")
func _peer_connected(id : int) -> void:
if not id:
return
ids.append(id)
print("Player has connected with id " + String(id))
# TODO: When we reach max players -> start the game
func _peer_disconnected(id : int) -> void:
ids.erase(id)
print("Player has disconnected with id " + String(id))
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

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="Server"
run/main_scene="res://Scenes/RootNode.tscn"
config/icon="res://icon.png"
[rendering]
environment/default_environment="res://default_env.tres"