extends Node2D var _ids := 0 remote func ping(): var id := get_tree().get_rpc_sender_id() print("PING from ", id) rpc_id(id, "pong") remote func pong(): var id := get_tree().get_rpc_sender_id() print("PONG from ", id) remote func move(id, x, y): print("id is ", id) for child in $"pieces".get_children(): if child.id == id: child.position = Vector2(x, y) return print("piece ", id, " not found!") remote func setup() -> void: print("was ordered to set up!") _place(false) func _onmoving(id, x, y): rpc_unreliable("move", id, x, y) func _onmoved(id, x, y): rpc("move", id, x, y) func _addpiece(kind: String, black: bool, off: int) -> void: _ids += 1 var piece := preload("res://src/piece/piece.tscn").instance() piece.setup(_ids, kind, black) piece.connect("moving", self, "_onmoving") piece.connect("moved", self, "_onmoved") $"pieces".add_child(piece) var y := 70 if not black: y = 520 if kind == "pawn": if not black: y -= 70 else: y += 70 piece.position = Vector2(off, y) func _on_setup_click() -> void: _place(true) func _place(send: bool) -> void: if send: rpc("setup") # remove and re-place (pun intended) all the pieces _ids = 0 for child in $"pieces".get_children(): $"pieces".remove_child(child) child.queue_free() var off := 300 for i in 8: # the pawns _addpiece("pawn", true, off) _addpiece("pawn", false, off) off += 63 var row := ["rook", "knight", "bishop", "queen", "king", "bishop", "knight", "rook"] off = 300 for p in row: _addpiece(p, true, off) _addpiece(p, false, off) off += 63 func _fai_cose() -> void: rpc("ping")