-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnit.js
More file actions
43 lines (38 loc) · 950 Bytes
/
Unit.js
File metadata and controls
43 lines (38 loc) · 950 Bytes
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
//Unit.js
function Unit(name, organization, x, y, map, skills = [], cars = []) {
this.name = name;
this.map = map;
this.organization = organization;
this.energy = 100;
this.skills = skills;
this.cars = cars;
this.x = x;
this.y = y;
this.timer = 0;
this.marker = null
}
Unit.prototype.update = function(dt) {
this.timer += dt;
if(this.energy < 100 && this.timer > TIME_TO_RECOVER_ENERGY_RATE) {
this.timer = 0;
this.energy += TIME_TO_RECOVER_ENERGY_RATE;
if(this.energy > 100)
this.energy = 100;
}
for(var i = 0; i < this.cars.length; i++) {
this.cars[i].update();
}
};
Unit.prototype.plot = function() {
var self = this;
this.marker = new google.maps.Marker({
position: {lat: self.x, lng: self.y},
map: self.map,
title: self.name,
icon: "assets\\gfx\\marker.png"
});
google.maps.event.addDomListener(this.marker, 'click', function() {
if(!unitDialogDisplayed)
unitDialog.show(self)
});
}