xxxxxxxxxx
66
class Bird {
constructor() {
this.x = 64;
this.y = height / 2;
this.gravity = 0.6;
this.lift = -15;
this.velocity = 1;
this.color = [255, 255, 255];
this.size = 32;
}
show() {
fill(this.color);
ellipse(this.x, this.y, this.size, this.size);
}
update() {
// this.x = mouseX;
// this.y = mouseY;
this.velocity += this.gravity;
this.velocity *= 0.9;
// print(this.velocity);
this.y += this.velocity;
if (this.y > height) {
this.y = height;
this.velocity = 0;
}
if (this.y < 0) {
this.y = 0;
this.velocity = 0;
}
}
up() {
this.velocity += this.lift;
}
upWithSound(soundLevel) {
print("upWithSound");
let liftPower = map(soundLevel, 0, 1, 0, -50);
this.velocity += liftPower;
}
hits(pipe) {
if (this.y < pipe.top || this.y + this.size > pipe.bottom) {
if (this.x > pipe.x && this.x < pipe.x + pipe.width) {
return true;
}
} else {
return false;
}
}
hurt() {
this.color = [255, 0, 0];
}
stable() {
this.color = [255, 255, 255];
}
}