xxxxxxxxxx
34
class Needle {
constructor(x, y) {
this.x1 = x;
this.x2 = this.x1+random(150,140);
this.y = y;
this.speed = 1;
}
display() {
stroke(0);
strokeWeight(2);
line(this.x1, this.y, 0, this.y);
line(this.x2, this.y, width, this.y);
}
win() {
fill(0);
textSize(32);
text('You Win!', this.x2-width/3, this.y - 100);
}
update() {
this.y += this.speed;
}
burst(xx, yy) {
let d1 = dist(xx, yy, this.x1, this.y);
let d2 = dist(xx,yy,this.x2,this.y);
if (d1 <= 30 || d2 <=30) {
console.log("burst");
burst = true;
}
}
}