Improved network code

This commit is contained in:
2024-01-15 17:08:26 +01:00
parent 9b47e374c7
commit b885d70625
17 changed files with 241 additions and 72 deletions

View File

@ -5,6 +5,23 @@ var udp := PacketPeerUDP.new()
func _ready():
udp.connect_to_host("127.0.0.1", 4242)
send_login()
func _process(_delta):
if Client.udp.get_available_packet_count() <= 0:
return
var packet := Client.udp.get_packet()
var type := packet.decode_u8(0)
print("Packet type %d data size %d" % [type, packet.size()-1])
func send_login():
var login_data = PackedByteArray()
login_data.push_back(2)
udp.put_packet(login_data)
print("Connecting...")
func spawn_player():
var player = PLAYER.instantiate()
add_child(player)
print("Ready.")