-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.gd
64 lines (47 loc) · 1.6 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
62
63
64
extends Node2D
var hostLobby = null
var pinged_server_with_info = false
func _ready():
get_tree().connect("network_peer_connected", self, "_player_connected")
$NotificationText.hide()
hostLobby = preload("res://HostLobby.tscn").instance()
get_tree().get_root().call_deferred("add_child",hostLobby)
hostLobby.hide()
func _player_connected(id):
if not get_tree().is_network_server() and not pinged_server_with_info:
print("Connected to server")
get_tree().get_root().get_node("HostLobby").rpc_id(1, "player_connected", get_tree().get_network_unique_id() , Helper.myName)
$NotificationText.set_text("Joined - Waiting for Host")
$NotificationText.show()
pinged_server_with_info = true
remote func set_as_player(id, team_colour):
Helper.opponent_id = id
Helper.myTeamColour = team_colour
Helper.isSpectator = false
func _on_hostButton_pressed():
Helper.myName = $nameTextEdit.get_text()
print("Hosting Network")
var host = NetworkedMultiplayerENet.new()
var res = host.create_server(4545, 20)
if res != OK:
print("Error creating server")
return
$joinButton.hide()
$hostButton.disabled = true
get_tree().set_network_peer(host)
hostLobby.show()
hide()
func _on_joinButton_pressed():
Helper.myName = $nameTextEdit.get_text()
var ip = $ipTextEdit.get_text()
var host = NetworkedMultiplayerENet.new()
print("Joining network at ", ip)
host.create_client(ip, 4545)
get_tree().set_network_peer(host)
$hostButton.hide()
$joinButton.disabled = true
#Game On!
remote func startgame():
var world = preload("res://Worlds/Ace.tscn").instance()
get_tree().get_root().add_child(world)
hide()