xxxxxxxxxx
30
class Ball {
constructor() {
this.x = 300;
this.y = 200;
this.xspeed = 4;
this.yspeed = 5;
}
display() {
stroke(255);
strokeWeight(4);
fill(200, 0, 200);
ellipse(this.x, this.y, 24, 24);
}
bounce() {
if (this.x > width || this.x < 0) {
this.xspeed = this.xspeed * -1;
}
if (this.y > height || this.y < 0) {
this.yspeed = this.yspeed * -1;
}
}
move() {
this.x = this.x + this.xspeed;
this.y = this.y + this.yspeed;
}
}