Blob


1 extends Node2D
3 var _ids := 0
6 remote func ping():
7 var id := get_tree().get_rpc_sender_id()
8 print("PING from ", id)
9 rpc_id(id, "pong")
11 remote func pong():
12 var id := get_tree().get_rpc_sender_id()
13 print("PONG from ", id)
15 remote func move(id, x, y):
16 print("id is ", id)
17 for child in $"pieces".get_children():
18 if child.id == id:
19 child.position = Vector2(x, y)
20 return
21 print("piece ", id, " not found!")
24 remote func setup() -> void:
25 print("was ordered to set up!")
26 _place(false)
29 func _onmoving(id, x, y):
30 rpc_unreliable("move", id, x, y)
33 func _onmoved(id, x, y):
34 rpc("move", id, x, y)
37 func _addpiece(kind: String, black: bool, off: int) -> void:
38 _ids += 1
39 var piece := preload("res://src/piece/piece.tscn").instance()
40 piece.setup(_ids, kind, black)
41 piece.connect("moving", self, "_onmoving")
42 piece.connect("moved", self, "_onmoved")
43 $"pieces".add_child(piece)
44 var y := 70
45 if not black:
46 y = 520
47 if kind == "pawn":
48 if not black:
49 y -= 70
50 else:
51 y += 70
52 piece.position = Vector2(off, y)
55 func _on_setup_click() -> void:
56 _place(true)
59 func _place(send: bool) -> void:
60 if send:
61 rpc("setup")
63 # remove and re-place (pun intended) all the pieces
64 _ids = 0
65 for child in $"pieces".get_children():
66 $"pieces".remove_child(child)
67 child.queue_free()
69 var off := 300
70 for i in 8: # the pawns
71 _addpiece("pawn", true, off)
72 _addpiece("pawn", false, off)
73 off += 63
75 var row := ["rook", "knight", "bishop", "queen", "king", "bishop", "knight", "rook"]
76 off = 300
77 for p in row:
78 _addpiece(p, true, off)
79 _addpiece(p, false, off)
80 off += 63
83 func _fai_cose() -> void:
84 rpc("ping")
87 func _on_dropqueen_pressed() -> void:
88 pass