-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy.js
48 lines (44 loc) · 1.06 KB
/
enemy.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
export default class Enemy {
constructor(x, y, health, speed) {
this.x = x;
this.y = y;
this.health = health;
this.maxHealth = health;
this.height;
this.width;
this.speed = speed;
}
get mid_x() {
return this.x + (this.width / 2)
}
get mid_y() {
return this.y + (this.height / 2)
}
static randomInWalls(walls, crow) {
let x, y;
for (; ;) {
x = random(walls.x1, walls.x2 - 25); //25 = width + strokeweight
y = random(walls.y1, walls.y2 - 45); //45 = height + strokeweight
if (dist(x, y, crow.mid_x, crow.mid_y) > 300) break;
}
return { x: x, y: y }
}
static upgrade_chance(diffuculty_gate, diffuculty) {
let random_seed = random() * diffuculty_gate;
if (random_seed <= diffuculty) {
return true
} else {
return false
}
}
crowCollision(crow) {
if (this.x + this.width >= crow.x &
this.x <= crow.x + crow.width &
this.y + this.height >= crow.y &
this.y <= crow.y + crow.height) {
return true;
} else {
return false
}
}
}