-
Notifications
You must be signed in to change notification settings - Fork 1
/
MapA.gd
39 lines (33 loc) · 1.73 KB
/
MapA.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
extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready():
self.get_child(6).text = Global.TeamAName
self.get_child(7).text = Global.TeamBName
$HTTPRequest.connect("request_completed", self, "_http_request_completed")
func _http_request_completed(result, response_code, headers, body):
pass #print("rc: "+str(response_code)+", result: "+str(result),", body: "+body.get_string_from_utf8())
func _process(delta):
var projectiles = {}
var tankA = {}
var tankB = {}
for child in self.get_children():
if "TankA" in child.name:
var degreerotation = -int(child.rotation * 180 / PI)
tankA = {"x":str(int(child.position.x)), "y":str(int(child.position.y)), "r": str(degreerotation), "can_fire":Global.TeamACanFire}
if "TankB" in child.name:
var degreerotation = -int(child.rotation * 180 / PI)
tankB = {"x":str(int(child.position.x)), "y":str(int(child.position.y)), "r": str(degreerotation), "can_fire":Global.TeamBCanFire}
var projectile_n = 0
for child in get_tree().get_root().get_children():
if "Projectile" in child.name:
var projectile = {"x": str(int(child.position.x)), "y":str(int(child.position.y)), "vx":int(child.linear_velocity.x),"vy":int(child.linear_velocity.y)}
projectiles["p"+str(projectile_n)]=projectile
projectile_n += 1
var dataToSend = {"tankA": tankA, "tankB": tankB, "projectiles":projectiles}
_make_post_request("http://localhost:3000/", dataToSend, false)
func _make_post_request(url, data_to_send, use_ssl):
# Convert data to json string:
var query = JSON.print(data_to_send)
# Add 'Content-Type' header:
var headers = ["Content-Type: application/json", "Content-Length: "+str(query.length())]
$HTTPRequest.request(url, headers, use_ssl, HTTPClient.METHOD_POST, query)