UDP movement

This commit is contained in:
2020-05-04 06:42:47 -04:00
parent 45673816bf
commit cc443704f8
4 changed files with 42 additions and 20 deletions

View File

@ -107,19 +107,19 @@ func send_chat_message(msg : String):
var pckt : PoolByteArray = (msg + '\n').to_ascii()
send_packet(pckt, 1)
func send_packet(packet : PoolByteArray, channel = 0):
packetQueue.append({'channel':channel, 'packet' : packet})
func send_packet(packet : PoolByteArray, channel = 0, pck_type = GDNetMessage.RELIABLE):
packetQueue.append({'channel':channel, 'packet' : packet, 'type' : pck_type})
func move_player(x,y):
var pckt : PoolByteArray = ("3|" + str(x) + "," + str(y)).to_ascii()
send_packet(pckt)
send_packet(pckt, 0, GDNetMessage.SEQUENCED)
func _process(delta):
process_events()
if len(packetQueue) > 0 and connected:
peer.send_packet(packetQueue[0]['packet'], packetQueue[0]['channel'], GDNetMessage.RELIABLE)
peer.send_packet(packetQueue[0]['packet'], packetQueue[0]['channel'], packetQueue[0]['type'])
packetQueue.remove(0)