//configuration variables float ballDiameter = 10; float brickWidth = 50; float brickHeight = 20; float paddleWidth = brickWidth*1.5; float paddleHeight = brickHeight; int numBrickRows = 10; Brick[] bricks = new Brick[0]; Paddle myPaddle; Ball myBall; void setup() { size(500, 400); smooth(); //place bricks for (int j=0; j height) { myBall = null; } //test and see if the player wins boolean weHaveWon=true; for (int i =0; iwidth || x<0) { vx *= -1; } } //bounce off the paddle void bounce(){ vy *= -1; //vy = vy*-1; } } class Brick { float x; float y; color c; Brick(float x, float y) { this.x = x; this.y = y; c = color(random(255), random(255), random(255)); } void draw() { rectMode(CENTER); fill(c); rect(x, y, brickWidth, brickHeight); } //Detect whether the ball impacts the brick boolean impact(Ball b) { if (x-brickWidth/2<=b.x && b.x<= x+brickWidth/2 && y+brickHeight/2>=b.y-ballDiameter/2) return true; else return false; } } class Paddle { float x = mouseX; float y = height - paddleHeight/2; //PVector v = new PVector(mouseX, height - paddleHeight/2); float xPrePos; void display() { fill(0); xPrePos = x; //xPrePos = v.x; x = mouseX; //v.x= mouseX; rect(x, y, paddleWidth, paddleHeight); //rect(v.x, v.y, paddleWidth, paddleHeight); } boolean impact(Ball b) { if (b.x>=x-paddleWidth/2 && b.x <= x + paddleWidth/2 && b.y+ballDiameter/2 >y-paddleHeight/2) return true; else return false; } void impartXVelocity(Ball b) { float xVector = x - xPrePos; b.vx += xVector; } }