First commit
This commit is contained in:
30
scripts/autos/multiplayer.gd
Normal file
30
scripts/autos/multiplayer.gd
Normal file
@@ -0,0 +1,30 @@
|
||||
extends Node
|
||||
|
||||
|
||||
const SERVER_PORT = 8080
|
||||
const SERVER_IP = "127.0.0.1"
|
||||
|
||||
func become_host() -> void:
|
||||
print("Starting host!")
|
||||
|
||||
var server_peer = ENetMultiplayerPeer.new()
|
||||
server_peer.create_server(SERVER_PORT)
|
||||
|
||||
multiplayer.multiplayer_peer = server_peer
|
||||
|
||||
multiplayer.peer_connected.connect(_add_player_to_game)
|
||||
multiplayer.peer_disconnected.connect(_remove_player_from_game)
|
||||
|
||||
|
||||
func join_game() -> void:
|
||||
print("Player 2 joining.")
|
||||
|
||||
var client_peer = ENetMultiplayerPeer.new()
|
||||
client_peer.create_client(SERVER_IP, SERVER_PORT)
|
||||
|
||||
|
||||
func _add_player_to_game(id : int) -> void:
|
||||
print("Player %s joined the game!" % id)
|
||||
|
||||
func _remove_player_from_game(id : int) -> void:
|
||||
print("Player %s left the game!" % id)
|
||||
Reference in New Issue
Block a user