xxxxxxxxxx
30
class Ball {
//declaring and initializing objects DATA
constructor() {
this.x = 300;
this.y = 200;
this.xspeed = 4;
this.yspeed = -3;
}
//defning an object function
move() {
this.x = this.x + this.xspeed;
this.y = this.y + this.yspeed;
}
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;
}
}
display() {
stroke(255);
strokeWeight(4);
fill(200, 0, 200);
ellipse(this.x, this.y, 24, 24);
}
}