Networking code
parent
7c15467c31
commit
dcdea85c53
|
@ -0,0 +1,3 @@
|
||||||
|
source_md5="47313fa4c47a9963fddd764e1ec6e4a8"
|
||||||
|
dest_md5="2ded9e7f9060e2b530aab678b135fc5b"
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,30 @@
|
||||||
|
extends Spatial
|
||||||
|
|
||||||
|
export var is_server = false
|
||||||
|
|
||||||
|
export var SERVER_PORT = 9999
|
||||||
|
export var SERVER_IP = "172.28.162.191"
|
||||||
|
export var MAX_PLAYERS = 10
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
if is_server:
|
||||||
|
initialize_server()
|
||||||
|
else:
|
||||||
|
initialize_client()
|
||||||
|
|
||||||
|
func initialize_server():
|
||||||
|
var peer = NetworkedMultiplayerENet.new()
|
||||||
|
peer.create_server(SERVER_PORT, MAX_PLAYERS)
|
||||||
|
get_tree().network_peer = peer
|
||||||
|
|
||||||
|
func initialize_client():
|
||||||
|
var peer = NetworkedMultiplayerENet.new()
|
||||||
|
peer.create_client(SERVER_IP, SERVER_PORT)
|
||||||
|
get_tree().network_peer = peer
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
#func _process(delta):
|
||||||
|
# pass
|
|
@ -1,4 +1,6 @@
|
||||||
[gd_scene load_steps=5 format=2]
|
[gd_scene load_steps=6 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Game.gd" type="Script" id=1]
|
||||||
|
|
||||||
[sub_resource type="BoxShape" id=1]
|
[sub_resource type="BoxShape" id=1]
|
||||||
|
|
||||||
|
@ -9,6 +11,7 @@
|
||||||
[sub_resource type="CapsuleMesh" id=4]
|
[sub_resource type="CapsuleMesh" id=4]
|
||||||
|
|
||||||
[node name="Game" type="Spatial"]
|
[node name="Game" type="Spatial"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="Level" type="Spatial" parent="."]
|
[node name="Level" type="Spatial" parent="."]
|
||||||
|
|
||||||
|
|
Reference in New Issue