added multiplayer connection. TODO: Sync Inventory values. Disable moving of other color tiles
This commit is contained in:
parent
e8cd148bc7
commit
3de181134d
13 changed files with 360 additions and 67 deletions
60
Multiplayer/Multiplayer.gd
Normal file
60
Multiplayer/Multiplayer.gd
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
extends Node
|
||||
|
||||
var has_opponent: bool = false
|
||||
@onready var start_game_button = $LobbyInfo/PanelContainer/VBoxContainer/StartGameButton
|
||||
@onready var game = $Game
|
||||
|
||||
func _ready():
|
||||
multiplayer.connected_to_server.connect(_mp_server_connected)
|
||||
multiplayer.connection_failed.connect(_mp_server_disconnect)
|
||||
multiplayer.server_disconnected.connect(_mp_server_disconnect)
|
||||
multiplayer.peer_connected.connect(_mp_peer_connected)
|
||||
multiplayer.peer_disconnected.connect(_mp_peer_disconnected)
|
||||
|
||||
func _mp_peer_disconnected(id: int) -> void:
|
||||
has_opponent = false
|
||||
start_game_button.disabled = true
|
||||
|
||||
if id == 1:
|
||||
# 1 is always the server
|
||||
# So we better get going back to the main menu?
|
||||
WSClient.close()
|
||||
get_tree().change_scene_to_file("res://main_menu.tscn")
|
||||
# Maybe just display a "server close
|
||||
return
|
||||
|
||||
func _log(msg):
|
||||
print(msg)
|
||||
|
||||
func _mp_server_connected():
|
||||
_log("[Multiplayer] Server connected (I am %d)" % WSClient.rtc_mp.get_unique_id())
|
||||
#pass_initial_playerdata.rpc_id(1, multiplayer.get_unique_id(), GameState.player_name)
|
||||
|
||||
func _mp_server_disconnect():
|
||||
_log("[Multiplayer] Server disconnected (I am %d)" % WSClient.rtc_mp.get_unique_id())
|
||||
get_tree().change_scene_to_file("res://main_menu.tscn")
|
||||
|
||||
func _mp_peer_connected(id: int):
|
||||
_log("[Multiplayer] Peer %d connected" % id)
|
||||
has_opponent = true
|
||||
start_game_button.disabled = false
|
||||
|
||||
@onready var lobby_info = $LobbyInfo
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
@rpc("any_peer", "call_local")
|
||||
func load_game() -> void:
|
||||
# Hide menu
|
||||
# load game scene
|
||||
lobby_info.visible = false
|
||||
var game_scene = preload("res://Game.tscn").instantiate()
|
||||
game.add_child(game_scene)
|
||||
|
||||
func _on_start_game_button_pressed():
|
||||
# tell other peer to now load the world via rpc
|
||||
load_game.rpc()
|
||||
pass # Replace with function body.
|
||||
Loading…
Add table
Add a link
Reference in a new issue