godot-webrtc-mplayer-testing/global.gd

39 lines
870 B
GDScript

extends Node
const MultiplayerClient = preload("multiplayer_client.gd")
onready var client = MultiplayerClient.new()
const MULTIPLAYER_URL = "ws://localhost:9080"
func _ready():
client.connect("lobby_joined", self, "_lobby_joined")
client.connect("connected", self, "_connected")
add_child(client)
func start_singleplayer_game():
print("Starting singleplayer game...")
get_tree().change_scene("res://game.tscn")
func join_lobby():
get_tree().change_scene("res://join_lobby.tscn")
func create_lobby():
join_lobby_with_code("")
func _lobby_joined(_lobby):
print("Joined!")
goto_lobby()
func goto_lobby():
print("Going to lobby...")
get_tree().change_scene("res://lobby.tscn")
func leave_game():
client.stop()
print("Leaving game...")
get_tree().change_scene("res://main.tscn")
func join_lobby_with_code(code):
client.start(MULTIPLAYER_URL, code)