PFont LaneUpper; float zx = 50; //X position of playerOne, controlled by z + x keys float op = 450; //X position of playerTwo, controlled by o + p keys //initial X values of obstacles A, B, & C. float oAx = 30; float oBx = 120; float oCx = 180; //fixed speeds of obstacles A, B, & C. float directionAx = .7; float directionBx = 1.3; float directionCx = 1.8; //ball speed on X&Y axes. int xSpeed = 4; int ySpeed = 4; float radius = 10.0; //radius of ball //initial position of ball. float ballX = random (200,400); float ballY = random (200,400); //direction of ball's movement float xDirection = 1; float yDirection = -1; // float wavy1 = random(250,300); float wavy2 = random(300,350); void setup () { size (600,600); background (128,131,130); ellipseMode (RADIUS); } void draw () { playerOne (); playerTwo (); obstructions (); collision (); float bounds = constrain(zx, 0,width); if(keyPressed) { //playerOne controller. if (key == 'z') { zx = zx-10; } else if (key == 'x') { zx = zx+10; } //playerTwo controller. else if (key == 'o') { op = op-10; } else if (key == 'p') { op = op+10; } } } void collision () { smooth(); strokeWeight (0); stroke (229,207,55); fill (229,207,55); ellipse (ballX,ballY, radius,radius); //define motion ballX += xSpeed * xDirection; if ((ballX > width-radius) || (ballX < radius)) { xDirection = -xDirection; // Change direction } ballY += ySpeed * yDirection; if (ballY < radius) { yDirection = -yDirection; // Change direction } ballY += ySpeed * yDirection; // if ((ballX > wavy1) && (ballX < wavy2)) //in order to not make it impossible. // { if (ballY > height+100) { ySpeed =0; // Loss outcome. //print you lose. LaneUpper = loadFont ("LaneUpper48.vlw"); fill (255); textFont (LaneUpper); textSize (30); if (frameCount < 600) { text ("you lost!", 250,250); } if ((frameCount > 600) && (frameCount < 2000)) { text ("nice try!", 250,250); } if ((frameCount > 2000) && (frameCount < 5000)) { text ("great effort!", 250,250); } if (frameCount > 5000) { text ("are you a wizard?!", 250,250); } } //define playerOne strike if ((ballY < 560) && (ballY > 540)) { if ((ballX >= zx-15) && (ballX <= zx + 115)) { xDirection = -xDirection; // Change direction yDirection = -yDirection; // Change direction } } // } //define playerTwo strike if ((ballY < 560) && (ballY > 540)) { if ((ballX >= op-15) && (ballX <= op + 115)) { xDirection = -xDirection; // Change direction yDirection = -yDirection; // Change direction } } //define obstructionA strike if ((ballY < 60) && (ballY > 40)) { if ((ballX >= oAx-15) && (ballX <= oAx + 200) || (ballX >= oAx+340) && (ballX <= oAx + 555)) { yDirection = -yDirection; // Change direction } } //define obstructionB strike if ((ballY < 250) && (ballY > 230)) { if ((ballX >= oBx-15) && (ballX <= oBx + 140) || (ballX >= oBx+200) && (ballX <= oBx + 355)) { yDirection = -yDirection; // Change direction } } //define obstructionC strike if ((ballY < 400) && (ballY > 390)) { if ((ballX >= oCx-15) && (ballX <= oCx + 95) || (ballX >= oCx+145) && (ballX <= oCx + 255)) { yDirection = -yDirection; // Change direction } } } void playerOne () { background (128,131,130); smooth(); stroke (230); strokeWeight(15); strokeJoin (ROUND); rect (zx,550, 100,2); } void playerTwo () { smooth(); stroke (30); strokeWeight(15); strokeJoin (ROUND); rect (op,550, 100,2); } void obstructions () { smooth(); stroke (167,188,0); strokeWeight(15); strokeJoin (ROUND); rect (oAx,50, 200,10); rect (oAx+340,50, 200,10); //level A obstructions motion oAx += directionAx; if ((oAx > 170) || (oAx < -30)) { directionAx = -directionAx; } //level B obstructions stroke (77,109,111); rect (oBx,220, 140,10); rect (oBx+220,220, 140,10); //level B obstructions motion oBx += directionBx; if ((oBx > 240) || (oBx < 0)) { directionBx = -directionBx; } //level C obstructions stroke (204,76,0); rect (oCx,390, 80,10); rect (oCx+160,390, 80,10); //level C obstructions motion oCx += directionCx; if ((oCx > 370) || (oCx < 0)) { directionCx = -directionCx; } }