PImage i; PFont font; float track1dist = 0; float track2dist = 0; int pos = 0; int years = 0; int gameover = 0; Ball godBall; Ball godBall2; ////////////////////////////////////////////////////////////////////// void setup(){ frameRate(30); size(800,570); // sets size font = loadFont("LucidaBlackletter-48.vlw");// loads font has to be in bi i = loadImage("intergalacticpong.jpg"); // loads image godBall = new Ball(400,50,6,6,pos); // says new varible header to computer like when you say int you get all properties of int godBall2 = new Ball(400,520,10,4,pos); // changeable prop xpos, ypos, xspeed, yspeed,paddle2poition// } /////////////////////////////////////////////////////////////////////// // inclosed draw loop void draw(){ image(i,0,0); godBall.allBall(); godBall2.allBall(); godPaddle(); playerPaddle(); score(); reset(); printWords(); if( (godBall.x1 < 0) && (godBall2.x1 < 0)) { gameover = 1; } } // stops here ///////////////////////////////////////////////////////////////////// //paddle2 function god sets position and tracks balls void godPaddle(){ // centers on ball1 paddle 2 // centers on ball2 paddle 2 noStroke(); fill(250,250,250); // god paddle tracking balls track1dist = dist (godBall.x1,0,720,0); //first ball distance track2dist = dist (godBall2.x1,0,720,0); //second ball distance //looks at balls if ( track1dist <= track2dist) { rect(750,(godBall.y1 - 40),18,80); pos = godBall.y1 -40; // centers on ball paddle 2 } else { // if ball1 is closer tracks it rect(750,godBall2.y1 - 40,18,80); pos = godBall2.y1 - 40 ; // centers on ball paddle 2 } } ////////////////////////////////////////////////////////////////// //paddle1 player function void playerPaddle(){ noStroke(); fill(250,250,250); // paddle design rect(20,mouseY,18,80); } //ends //////////////////////////////////////////////////////////////////// void printWords(){ if (gameover == 1){ textFont(font,60); fill(200,0,0); // font color text("The Damned Shall Laugh",90,250); } } //text /////////////////////////////////////////////////////////////////// void score(){ textFont(font,60); fill(250,250,230); // font color text("years",500,50); text(years,700,50); if ((godBall.x1 >= 737) || godBall2.x1 >= 732) { years ++ ; } //chexk in readout println("begin"); float f = 0.3; println(years); println( gameover); String s = "end"; println(s); } ////////////////////////////////////////////// void reset() { if (mousePressed == true) { gameover = 0; years = 0; } } //on same plane as draw setup and all other functions can call functions from it by using "." class Ball{ // specific varibles/ data // int pos = 0; int fillrate = 0; int x1 = 0; int y1 = 0; int speedx = 0; int speedy = 0; float bpdist1x = 0; // ball/paddle/distance/paddle1/x axis float bpdist1y = 0; float bpdist2x = 0; float bpdist2y = 0; Ball ( int _x, int _y, int _speedx, int _speedy,int _pos ){ // input x,y,speedx,speedy,paddle position pos = _pos; x1 = _x; y1 = _y; speedx = _speedx; speedy = _speedy; } // runs all following functions void allBall(){ drawBall(); moveball(); ballbouncewall(); ballbouncepd1 (); //bounces off paddle player1 ballbouncepd2(); //bounces off paddle god2 if (mousePressed == true) { x1 = 400; y1 = 250; } /// BAAAAAAAAAAAAAAAAAD restets the balls } //draws ball void drawBall() { fillrate = x1 / 3 ; // rate of disaperance ball noStroke(); fill(250,250,250,fillrate); // makes ball come and go ellipseMode (CENTER); // sets center points as ref ellipse(x1, y1, 55, 55); // draws ellipse } // ball motion void moveball() { x1 = x1 + speedx; // sets motion y1 = y1 + speedy; } // reverses motion when a WAlls hit void ballbouncewall (){ if (x1 >= 800) { speedx = speedx * -1; } if ((y1 >= 540) || (y1 <= 5)) { speedy = speedy * -1; } } //player paddle 1 deflection ball void ballbouncepd1 () { bpdist1x = dist (x1,0,20,0); // paddle1 deflection ball bpdist1y = dist (0,y1,0,mouseY); // paddle1 deflection ball if ( ( bpdist1x <= 20) && (bpdist1y <= 80) ) { speedx = speedx * -1; } } // god paddle 2 deflection ball void ballbouncepd2(){ bpdist2x = dist (x1,0,800,0); // ball distance x bpdist2y = dist (0,y1,0,pos); // ball distance y if ( (bpdist2x <= 60) && ( bpdist2y <= 80) ) { speedx = speedx * -1; } } } //END CLASS