-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefence.js
45 lines (37 loc) · 902 Bytes
/
defence.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
function Defence() {
this.id = nextDefenceId++;
this.health = 600;
//
//
this.pos = rndVectorWithinCircle();
this.r = 25;
Defence.prototype.show = function() {
fill(0, 200, 120, 160);
stroke(255);
rectMode(CENTER);
rect(this.pos.x, this.pos.y, this.r*2, this.r*2, 20);
fill(0,0,0,255);
noStroke();
textSize(7);
text(round(this.health)+"", this.pos.x-4, this.pos.y+2);
}
Defence.prototype.update = function() {
this.checkHealth();
}
Defence.prototype.checkHealth = function() {
for (var i = 0; i < intruders.length; i++) {
var intr = intruders[i];
if (this.pos.dist(intr.pos) < this.r + intr.limbWidth) {
this.health = this.health - intr.dpf;
}
}
}
Defence.prototype.death = function() {
for (var i = 0; i < intruders.length; i++) {
var intr = intruders[i];
if (this.pos.dist(intr.pos) <= intr.limbWidth + this.r) {
intr.healToFull();
}
}
}
}