-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipe.js
51 lines (45 loc) · 960 Bytes
/
Pipe.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
class Pipe {
static speed = 4;
static w = 80;
constructor() {
this.spacing = 200;
this.top = random(height / 12, (3 / 5) * height);
this.bottom = height - (this.top + this.spacing);
this.x = width;
}
draw() {
fill(100, 255, 100);
// Top pipe
push();
scale(1, -1);
image(
pipeImg,
this.x,
-this.top,
Pipe.w,
pipeImg.height / (pipeImg.width / Pipe.w)
);
pop();
// Bottom pipe
image(
pipeImg,
this.x,
height - this.bottom,
Pipe.w,
pipeImg.height / (pipeImg.width / Pipe.w)
);
}
update() {
this.x -= Pipe.speed;
}
hits(bird) {
return (
(bird.y < this.top || bird.y + 40 > height - this.bottom) && // Vertical check
bird.x > this.x &&
bird.x < this.x + Pipe.w
); // Horizontal check
}
isOffScreen() {
return this.x < -this.width;
}
}