// BALL import java.awt.geom.*; public class Ball { Rectangle rectangle; // BALL PROPERTIES -- int width = 5; int height = 5; boolean hasStroke = false; color strokeColor = #FFFFFF; boolean hasFill = true; color fillColor = #ffffff; // velocity int velX = 3; int velY = 3; // int x; int y; int ox; int oy; int xcentre; int ycentre; // Ball(int X, int Y) { x = X; y = Y; rectangle = new Rectangle(width, height, hasStroke, strokeColor, hasFill, fillColor); rectangle.setPosition(x, y); } void refresh(){ updatePosition(); rectangle.setPosition(x, y); rectangle.drawYourself(); } void updatePosition() { // add velocity to position x+=velX; y+=velY; // collision with limits if(x<=0 || x>=gameFrameWidth-width){ velX = -velX; x = constrain(x, 0, gameFrameWidth-width); } if(y<=0 || y>=gameFrameHeight-height){ velY = -velY; y = constrain(y, 0, gameFrameHeight-height); } xcentre = x+width/2; ycentre = y+height/2; // collision with paddle int result = checkCollisionWithRectangle(paddle.rectangle); // if collides on top, control direction of ball if (result == 1){ if(xcentre < paddle.rectangle.x1+paddle.rectangle.width/2){ if(velX>0){ velX = -velX; } }else{ if(velX<0){ velX = -velX; } } } // collision with bricks if (result == 0) { for (int i=0; i