-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebris.js
67 lines (56 loc) · 1.4 KB
/
Debris.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
class Debris {
constructor(image) {
// this.r = 5;
// this.resetDebris();
this.r = 5;
this.a = 0;
this.rotationRate = random(-0.05, 0.05)
this.resetDebris();
this.image = image;
}
resetDebris() {
this.y = random(height - 10);
this.r = random(5, 10)
let spawnLeftSide = random(1) < 0.5;
if (spawnLeftSide) {
this.x = random(-width, 0);
this.isGoingLeft = false;
} else {
this.x = random(width, width * 2);
this.isGoingLeft = true;
}
}
update() {
if (this.isGoingLeft) {
this.x--;
} else {
this.x++;
}
if (this.isOffScreen()) {
this.resetDebris();
}
}
isOffScreen() {
if (this.isGoingLeft && this.x < -5) {
return true;
} else if (!this.isGoingLeft && this.x > width + 5) {
return true;
}
return false;
}
display() {
push();
translate(this.x, this.y);
rotate(this.a);
imageMode(CENTER);
image(this.image, 0, 0, this.r * 2, this.r * 2);
this.a = this.a + this.rotationRate;
pop();
}
hasHitPlayer(player) {
if (dist(this.x, this.y, player.x, player.y) < this.r + player.r) {
return true;
}
return false
}
}