Spaces:
Running
Running
File size: 780 Bytes
b34b125 |
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 |
// Neuro-Evolution Flappy Bird with TensorFlow.js
class Pipe {
constructor() {
this.spacing = 125;
this.top = random(height / 6, (3 / 4) * height);
this.bottom = height - (this.top + this.spacing);
this.x = width;
this.w = 80;
this.speed = 6;
}
hits(bird) {
if (bird.y < this.top || bird.y > height - this.bottom) {
if (bird.x > this.x && bird.x < this.x + this.w) {
return true;
}
}
return false;
}
show() {
fill(75, 127, 83);
rectMode(CORNER);
rect(this.x, 0, this.w, this.top);
rect(this.x, height - this.bottom, this.w, this.bottom);
}
update() {
this.x -= this.speed;
}
offscreen() {
if (this.x < -this.w) {
return true;
} else {
return false;
}
}
}
|