-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipe.js
33 lines (28 loc) · 788 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
function Pipe() {
this.w = 20;
this.x = width;
this.minT = 5; // minimum rect height
this.gap = 125; //gap for bird to fly through
this.t = random(this.minT, height - this.gap - this.minT); // height of top rectangle
this.speed = -1;
this.blink = false;
this.hits = function(Bird){
if(Bird.x+Bird.birdSize>this.x && Bird.x<this.x+this.w){
if(Bird.y<this.t || (Bird.y+Bird.birdSize)>(this.t+this.gap)){
this.blink = true;
return true;
}
}
this.blink = false;
return false
}
this.show = function(){
if(this.blink) fill(0,255,0);
else fill(255);
rect(this.x,0,this.w,this.t);
rect(this.x, this.gap + this.t,this.w,height-this.gap-this.t);
}
this.update = function(){
this.x += this.speed;
}
}