-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.gd
61 lines (50 loc) · 1.8 KB
/
game.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
extends Node
var map_scene = preload("res://maps/test_map.tscn")
# Called when the node enters the scene tree for the first time.
func _ready():
print("Players: ", GlobalCrap.players)
print("I am: ", multiplayer.get_unique_id())
multiplayer.peer_connected.connect(_on_player_connected)
multiplayer.peer_disconnected.connect(_on_player_disconnected)
multiplayer.connected_to_server.connect(_on_connected_ok)
multiplayer.connection_failed.connect(_on_connected_fail)
multiplayer.server_disconnected.connect(_on_server_disconnected)
var map_instance = map_scene.instantiate()
add_child(map_instance)
func _on_player_connected(id):
if multiplayer.is_server():
print("Player ", id, " connected")
GlobalCrap.players.push_back(id)
update_players.rpc(GlobalCrap.players)
func _on_player_disconnected(id):
if multiplayer.is_server():
print("Player ", id, " disconnected")
GlobalCrap.players = GlobalCrap.players.filter(func(player): return player != id)
update_players.rpc(GlobalCrap.players)
@rpc("authority", "call_local")
func update_players(new_players):
print("update_players ", new_players)
GlobalCrap.players = new_players
func _on_connected_ok():
print("Connected ok")
func _on_connected_fail():
print("Connected fail")
func _on_server_disconnected():
print("Server disconnected")
multiplayer.multiplayer_peer = null
GlobalCrap.players = [1]
get_tree().change_scene_to_file("start.tscn")
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if multiplayer.is_server():
var time = str(Time.get_ticks_msec())
update_game.rpc(time)
@rpc
func update_game(data):
pass
# ?????????????????? Why da fok do i need this? This is needed to match with
# start.gd, do not touch.
@rpc("call_local")
func load_game():
pass