xxxxxxxxxx
28
class PopcornBall {
constructor(x, y) {
this.x = x;
this.y = y;
this.xvel = random(2, 4);
this.yvel = -3;
this.r = 15;
}
move() {
this.y -= this.yvel
this.x += this.xvel
this.yvel -= grav
}
bounce() {
if (this.x >= 500-this.r/2){
this.xvel = -this.xvel}
if(this.x <= this.r/2){
this.xvel = -this.xvel}
if (this.y >= 600-this.r/2){
this.yvel = -this.yvel-0.25}
if(this.y <= this.r/2){
this.yvel = -this.yvel}
}
display() {
fill(200, 34, 123);
ellipse(this.x, this.y, this.r, this.r);
}
}