-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpipe.js
31 lines (26 loc) · 1003 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
function CtPipe () {
this.x = canvasWidth;
this.y = 0;
this.gap = random(gapMargin, canvasHeight - pipeGap - gapMargin);
//Röhre anzeigen
this.show = function () {
stroke(80,61,72);
strokeWeight(3);
fill(130,168,65);
rect(this.x, this.y, pipeWidth, this.gap);
rect(this.x,this.gap + pipeGap, pipeWidth, canvasHeight);
//Röhre nach links bewegen
this.x -= 2;
}
//Prüfung der Kollision der Röhre mit dem Vogel
this.checkCollision = function(birdY) {
//prüfe, ob der Vogel mit dem oberen Abschnitt der Röhre kollidiert
if(collideRectCircle(this.x, this.y, pipeWidth, this.gap, birdX, birdY, birdSize)) {
ctScore.gameOver();
}
//prüfe, ob der Vogel mit dem unteren Abschnitt der Röhre kollidiert
if(collideRectCircle(this.x,this.gap + pipeGap, pipeWidth, canvasHeight, birdX, birdY, birdSize)) {
ctScore.gameOver();
}
}
}