Debugging connection status

godot4-port
Jan 2020-06-14 15:58:05 +02:00
parent 5b21aedbad
commit e7e5f6b348
2 changed files with 32 additions and 8 deletions

38
Game.gd
View File

@ -9,26 +9,48 @@ export var MAX_PLAYERS = 10
# Called when the node enters the scene tree for the first time.
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
initialize()
if is_server:
initialize_server()
else:
initialize_client()
debug_connection_status()
func debug_connection_status():
if (get_tree().network_peer.get_connection_status() == NetworkedMultiplayerPeer.CONNECTION_CONNECTED):
print("We have connected succesfully")
#if (get_tree().network_peer.get_connection_status() == NetworkedMultiplayerPeer.CONNECTION_CONNECTED):
# print("We have connected succesfully")
if (get_tree().network_peer.get_connection_status() == NetworkedMultiplayerPeer.CONNECTION_CONNECTING):
print("We are trying to connect")
func initialize():
var peer
if is_server:
peer = initialize_server()
else:
peer = initialize_client()
get_tree().network_peer = peer
func initialize_server():
var peer = NetworkedMultiplayerENet.new()
peer.create_server(SERVER_PORT, MAX_PLAYERS)
get_tree().network_peer = peer
peer.connect("connected_to_server", self, "on_connection_established")
peer.connect("connection_failed", self, "on_connection_failed")
return peer
func initialize_client():
var peer = NetworkedMultiplayerENet.new()
peer.create_client(SERVER_IP, SERVER_PORT)
get_tree().network_peer = peer
peer.connect("network_peer_connected", self, "on_peer_connected")
return peer
func on_peer_connected(id):
print("Peer connected with id ", id)
func on_connection_established():
print("Connection has been established")
func on_connection_failed():
print("Connection has failed")

View File

@ -1,5 +1,7 @@
extends KinematicBody
export var is_me = false
const GRAVITY = 9.8
const JUMP_VELOCITY = 400
const WALK_VELOCITY = 550