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 == ' ') {
}
void keyReleased() {
Warm-Up
Refactoring Pong (or Breakout)
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() {