-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipe.js
41 lines (35 loc) · 1.11 KB
/
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
function Pipe() {
this.gap = random(4 * bird.r + 4, 8 * bird.r);
this.top = random(0, height - 8 * bird.r);
this.bottom = height - (this.top + this.gap);
this.x = width;
this.w = 26;
this.highlight = false;
this.hits = function (bird) {
if (bird.y - bird.r < this.top || bird.y + bird.r > height - this.bottom) {
if (bird.x + bird.r > this.x && bird.x - bird.r < this.x + this.w) {
this.highlight = true;
return true;
}
}
return false;
}
this.show = function () {
fill(255);
if (this.highlight) {
}
// rect(this.x, 0, this.w, this.top);
//rect(this.x, height - this.bottom, this.w, this.bottom);
if (!this.highlight) {
image(downtree, this.x - this.w, 0, 3 * this.w, this.top);
image(uptree, this.x - this.w, height - this.bottom, 3 * this.w, this.bottom);
}
}
this.update = function () {
this.x -= speed;
this.highlight = false;
}
this.offscreen = function () {
return this.x < -this.w;
}
}