-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmultimap.js
90 lines (78 loc) · 2.87 KB
/
multimap.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
pc.script.create('multimap', function (context) {
var uri = new pc.URI(window.location.href);
var query = uri.getQuery();
var multi = !!query.multi;
var chosen = false;
var MultiMap = function (entity) {
this.entity = entity;
};
window.addEventListener('message', function (e) {
if (e.data === 'map.chosen') {
chosen = true;
}
});
MultiMap.prototype = {
initialize: function () {
if (!multi) {
return;
}
this.minimap = context.root.getChildren()[0].script.minimap;
this.bullets = context.root.findByName('bullets');
this.tanks = context.root.findByName('tanks');
this.pickables = context.root.findByName('pickables');
this.teams = context.root.getChildren()[0].script.teams;
this.level = this.minimap.level;
if (window.top !== window) {
window.top.postMessage({
type: 'level',
data: this.level
}, '*');
}
},
render: function () {
if (!chosen || !multi) {
return;
}
var state = {
bullets: [],
tanks: [],
items: [],
teams: []
};
var bullets = this.bullets.getChildren();
bullets.forEach(function (b) {
var pos = b.getPosition();
if (b.active) {
state.bullets.push([pos.x, pos.z, b.oldX, b.oldZ]);
}
b.oldX = pos.x;
b.oldZ = pos.z;
});
var pickables = this.pickables.getChildren();
pickables.forEach(function (p) {
var pos = p.getPosition();
state.items.push([pos.x, pos.z, p.type]);
});
var tanks = this.tanks.getChildren();
tanks.forEach(function (t) {
if (t.script.tank.dead || !t.script.tank.flashState) {
return;
}
var pos = t.getPosition();
var clr = t.script.tank.matBase.emissive;
state.tanks.push([pos.x, pos.z, -Math.atan2(t.forward.x, t.forward.z), '#' + ('00' + Math.floor(clr.r * 255).toString(16)).slice(-2) + ('00' + Math.floor(clr.g * 255).toString(16)).slice(-2) + ('00' + Math.floor(clr.b * 255).toString(16)).slice(-2)]);
});
for (var i = 0; i < 4; i++) {
state.teams.push([this.teams.colors[i], this.teams.scores[i]]);
}
// this.bullets.forEach(function (bullet) {
// console.log(bullet);
// });
window.top.postMessage({
type: 'state',
data: state
}, '*');
}
};
return MultiMap;
});