xxxxxxxxxx
47
class Arrow {
constructor(x, y) {
this.x = x;
this.y = y;
this.dx = 0;
this.dy = 0;
this.speed = 0;
this.fired = false;
this.velx = 0;
this.vely = 0;
}
update(x, y) {
this.dx = x;
this.dy = y;
}
afterFire() {
translate(this.x, this.y);
this.x += this.velx;
this.y += this.vely;
}
fire() {
this.fired = true;
this.velx = this.dx / 300;
this.vely = this.dy / 300;
}
draw() {
if (this.fired) {
push();
strokeWeight(8);
stroke(255, 0, 0);
point(this.x, this.y);
stroke(255, 255, 0);
point(this.dx, this.dy);
pop();
} else {
push();
strokeWeight(8);
stroke(255,0,0);
point(0,0);
pop();
}
}
}