So i am a begginer at coding. Ive watched a few vids of coding train about the p5.js library and now im trying to make a class named "Ball", that when it hits the wall, it changes direction. But it just gets blocked in a corner
I have tried making the position to change outside of the class, in the draw function, but then it doesnt even stop at the edges
class Ball {
constructor(x, y , size) {
this.x = x;
this.y = y;
this.size = size;
}
appear(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
fill(this.r, this.g, this.b);
noStroke();
ellipse(this.x, this.y, this.size, this.size);
}
move(xspeed, yspeed) {
this.speedx = xspeed;
this.speedy = yspeed;
if(this.x >= xlimit) {
this.speedx = -(this.speedx)
}
if (this.x <= this.size/2) {
this.speedx = -(this.speedx)
}
if (this.y >= ylimit) {
this.speedy = -(this.speedy)
}
if (this.y <= this.size/2) {
this.speedy = -(this.speedy)
}
this.x = this.x + this.speedx;
this.y = this.y + this.speedy;
}
}
I dont get any errors in the console.