Lab 7: Game
Bard College – Computer Science – Object-Oriented Programming

In this lab you will build upon a small game, refactoring it into classes and adding a score keeping system.

Warm-Up

Go through the draw function with a partner and add comments to describe what it is doing.

Refactoring Pong (or Breakout)

Make the following changes to the provided sketch:

  1. reorganize the sketch using classes (e.g. Ball, Paddle);
  1. create methods for moving, displaying, bouncing, etc.
  1. make a change in terms of the appearance of the game;
  1. a point tally should be displayed (you decide how points are awarded or deducted);
  1. create a third object: consider creating a second paddle, another ball and score.

All your methods should have a comment at the top describing what they do.

float paddle_x;
float paddle_step;
float paddle_h = 16;
float paddle_w = 5 * paddle_h;
float ball_x, ball_y;
float ball_x_step, ball_y_step;
float ball_r = 13;

void setup() {
  size(600, 300);
  paddle_x = width/2;
  paddle_step = 0;
  reset();
}

void reset() {
  ball_x = random(ball_r, width - ball_r);
  ball_y = random(ball_r, height/2 );
  ball_x_step = random(-3, 3);
  ball_y_step = random(1, 3);
}

void keyPressed() {
  if (key == CODED && keyCode == LEFT) {
    paddle_step = -3;
  } else if (key == CODED && keyCode == RIGHT) {
    paddle_step = 3;
  } else if (key == ' ') {
    reset();
  }
}

void keyReleased() {