Ball myBall1; Paddle myPaddle; PcPaddle pcPaddle; float why = 0; float pos = height/2; float speed = 2; int string = 0; int ctr = 0; int string2 = 0; int padlng = 81; void setup() { size(640, 480); colorMode(RGB, 255, 255, 255, 100); myBall1 = new Ball(11, 11, 1, 1, 3); myPaddle = new Paddle(padlng); pcPaddle = new PcPaddle(padlng); noCursor(); PFont metaBold; // The font "Meta-Bold.vlw.gz" must be located in the // current sketch's "data" directory to load successfully metaBold = loadFont("Univers55.vlw.gz"); textFont(metaBold, 44); } void draw() { background(0); stroke(126); fill(255); text(string2, width/2-85, 50); text(string, width/2+58, 50); why = myBall1.bounce(); line(width/2, 0, width/2, height); pcPaddle.renderNEW(why, myBall1.x); myPaddle.renderNEW(); myBall1.render(); myBall1.bounce(); delay(5); } class Ball { int sizeOne; int sizeTwo; int reset = 0; float xspeed; float yspeed; int direction; float x = width/2; float y= height/2; //**CONSTRUCTOR**// Ball(int sz1_, int sz2_, float xspd, float yspd, int dir) { sizeOne = sz1_; sizeTwo = sz2_; xspeed = xspd; yspeed = yspd; direction = dir; } /*void render() { ellipseMode(CENTER); noStroke(); fill(255, 255, 255); ellipse(x, y, sizeOne, sizeOne); }*/ void render() { rectMode(CENTER); noStroke(); fill(255, 255, 255); rect(x, y, sizeOne, sizeTwo); } float bounce() { if (direction == 1) { x = x + xspeed; y = y + yspeed; if (x > width) { xspeed = xspeed/abs(xspeed) * -1;// = xspeed * -1; } if ((y > height) || (y < 0)) { yspeed = yspeed * -1; } if (x <15) { xspeed = 1; yspeed = yspeed/abs(yspeed); x=width/2; y=height/2; string++; } if (x>width-15) { xspeed = -1; yspeed = yspeed/abs(yspeed); x=width/2; y=height/2; string2++; } } if (direction == 2) { x = x + xspeed; y = y - yspeed; if (x > width) { xspeed = xspeed/abs(xspeed) * -1;// = xspeed * -1; } if ((y > height) || (y < 0)) { yspeed = yspeed * -1; } if (x <15) { xspeed = 1; yspeed = yspeed/abs(yspeed); x=width/2; y=height/2; string++; } if (x>width-15) { xspeed = -1; yspeed = yspeed/abs(yspeed); x=width/2; y=height/2; string2++; } } if (direction == 3) { x = x - xspeed; y = y - yspeed; if (x > width) { xspeed = xspeed/abs(xspeed) * -1;// = xspeed * -1; } if ((y > height) || (y < 0)) { yspeed = yspeed * -1; } if (x <15) { xspeed = 1; yspeed = yspeed/abs(yspeed); x=width/2; y=height/2; string++; } if (x>width-15) { xspeed = -1; yspeed = yspeed/abs(yspeed); x=width/2; y=height/2; string2++; } } if (direction == 4) { x = x - xspeed; y = y + yspeed; if (x > width) { xspeed = xspeed/abs(xspeed) * -1;// = xspeed * -1; } if ((y > height) || (y < 0)) { yspeed = yspeed * -1; } if (x <15) { xspeed = 1; yspeed = yspeed/abs(yspeed); x=width/2; y=height/2; string++; speed = speed * 1.1; } if (x>width-15) { xspeed = -1; yspeed = yspeed/abs(yspeed); x=width/2; y=height/2; string2++; } } if (((7 < x) && (x < 23)) && (((mouseY - (padlng/2))< y ) && (y < (mouseY + (padlng/2))))) { xspeed = xspeed * -1; if (myPaddle.dy != 0) { yspeed = -(myPaddle.dy/3); } if (yspeed == 0) { yspeed = .5; } else yspeed = yspeed; } if ((y == 0) || (y == height)) { yspeed = yspeed * -1; } if ((((width-7) > x) && (x > (width-23))) && (((y - (padlng/2))< pos ) && (pos < (y + (padlng/2))))) { if (xspeed > 0) { xspeed = (xspeed * -1) * 1.03; yspeed = yspeed * 1.02; speed = speed * 1.013; } if (xspeed < 0) { xspeed = (xspeed * -1) * 1.03; yspeed = yspeed * 1.02; speed = speed * 1.013; } else { xspeed = xspeed * -1; } } return y; } } class Paddle { int lngth; int dy; //**CONSTRUCTOR**// Paddle(int lngt_) { lngth = lngt_; } void renderNEW() { rectMode(CENTER); noStroke(); fill(255, 255, 255); rect(15, mouseY, 8, lngth); dy = mouseY - pmouseY; /*if (mouseY > pmouseY) { dy = pmouseY - mouseY; } if (mouseY < pmouseY) { dy = mouseY - pmouseY; } if (mouseY == pmouseY) { dy = 0; }*/ } } class PcPaddle { int lngth; //**CONSTRUCTOR**// PcPaddle(int lngt_) { lngth = lngt_; } void renderNEW(float ex, float ballX) { rectMode(CENTER); noStroke(); fill(255, 255, 255); if (ballX <= width/2) { if (pos > height/2) { pos = pos - speed; }//while (pos != height/2); if (pos < height/2) { pos = pos + speed; }//while (pos != height/2); if (pos == height/2) { // do nothing } } if (ballX > width/2) { if (pos > ex) { pos = pos - speed; } if (pos < ex) { pos = pos + speed; } else pos = pos; } rect(width-15, pos, 8, lngth); } }