//Game: BrickBreaker --- unfinished //Configuration variables int numBrickRows = 10; int brickWidth = 50; int brickHeight = 20; int paddleHeight = brickHeight; int paddleWidth = int(brickWidth*1.5); int ballDiameter = 10; //global variables Brick[] bricks = new Brick[10]; Paddle myPaddle; Ball myBall; //Setup function void setup(){ size(500, 400); smooth(); //place bricks for(int j = 0; j < numBrickRows; j++){ //location of each row int y = brickHeight/2 + j*brickHeight; //set the row offset int offset = 0; if(j%2 == 1){ offset = brickWidth/2; } //draw the row for(int i = offset; i width || xPosition < 0){ xSpeed *= -1; } } void bounce(){ ySpeed *= -1; } } class Brick{ int xPosition; int yPosition; color c; //Constructor Brick(int x, int y){ xPosition = x; yPosition = y; c = color(random(255), random(255),random(255)); } void draw(){ rectMode(CENTER); fill(c); rect(xPosition, yPosition, brickWidth, brickHeight); } /** Detect whether the ball b impacted the brick * b - the ball to test * returns true if there was an impact, false otherwise */ boolean impact(Ball b){ if(b.xPosition >= xPosition - brickWidth/2 && b.xPosition <= xPosition + brickWidth/2 && b.yPosition - ballDiameter/2 <= yPosition + brickHeight/2) return true; else return false; } } class Paddle{ int xPos = mouseX; int yPos = height - paddleHeight/2; int xPreviousPos; void display(){ fill(0); xPreviousPos = xPos; xPos = mouseX; rect(xPos, yPos, paddleWidth, paddleHeight); } boolean impact(Ball b){ if(xPos -paddleWidth/2 <= b.xPosition && b.xPosition <= xPos + paddleWidth/2 && yPos - paddleHeight/2 < b.yPosition + ballDiameter/2) return true; else return false; } void impartXVelocity(Ball b){ int xVector = xPos - xPreviousPos; b.xSpeed +=xVector; } }