i want to move a ball in a square path. Right now it moves in a triangular like wave. I want it to behave like the image. What can i do to make this happen? thanks! I have tried many things so far (moving only one position and so on). I didn't want to split the screen but do it dynamic, if possible.
My code at the moment:
public void move(int widthScreen, int heightScreen) {
posX += velocityX;
posY += velocityY;
// Check for collisions with screen walls
if (posX <= 0 || posX >= widthScreen - size) {
velocityX *= -1; // Reverse horizontal velocity
}
if (posY <= 0 || posY >= heightScreen - size) {
velocityY *= -1; // Reverse vertical velocity
}
}```