//Zachary Semcken Presents: //Ghetto Pong! void setup() { //Window parameters. size(400,400); //Makes a 400x400 window. } float r = random(100,200); //Red Amount. float g = random(100,200); //Green Amount. float b = random(100,200); //Blue Amount. float x,y; //X and Y Coordinates of the paddle. float ballX = random(10,width-10); //Ball's X coordinate. float ballY = 10; //Ball's Y coordinate. float ballDX = random(1,10); //Ball's Horizontal velocity. float ballDY = random(1,5); //Ball's Vertical velocity int score; //Sets initial score. boolean bounce; //To be used to show a bounce off the top of the window. boolean xCollision; //Establishes a truth value to the X collision parameters. boolean yCollision; //Establishes a truth value to the Y collision parameters. void drawScene() { //Time to create a background background(0); //Black background rectMode(CORNERS); //Sets the rectangle to corners. fill(r,g,b); //Fills the background with a random color. noStroke(); //No outline. rect(0,0,width,4*height/5); //Creates a rectangle that covers 4/5ths of the screen. } void drawGame() { //Time to draw this bitch! rectMode(CENTER); //Sets a rectangle in center to make the paddle. fill(b,g,r); //Makes the paddle a random color. noStroke(); //Doesn't outline the paddle. x = constrain(mouseX,width/8,7*width/8); //Constrains the X of the paddle to within the screen. y = 9*height/10; //Sets the Y variable of the paddle. rect(x,y,width/4,15); //Draws the paddle! ellipseMode(CENTER); //Makes the ball centered around the ballX and ballY variables. bounce = true; //Starts the bounce variable at TRUE. ballX += ballDX; //Makes the ball move in the X direction. ballY += ballDY; //Makes the ball move in the Y direction. if (ballX < 10 || ballX > width-10) { //If the ball hits the sides of the window ... ballDX = -ballDX; //Negates the horizontal velocity. } if (ballY < 10) { //If the ball hits the top of the screen ... ballDY = -ballDY; //Negates the vertical velocity. bounce = !bounce; //Says the ball bounced! } if (ballY > height-10) { //If the ball hits the bottom of the screen ... ballX = random(10,width-10); //Reset the initial X position of the ball. ballY = 10; //Reset the initial Y position of the ball. ballDX = random(1,width/50); //Reset the initial X velocity of the ball. ballDY = random(1,height/50); //Reset the initial Y velocity of the ball. r = random(100,200); //Reset the initial red value. g = random(100,200); //Reset the initial green value. b = random(100,200); //Reset the initial blue value. score = 0; //Reset the initial score value. } fill(255); //Makes the ball pure white. noStroke(); //No outline of the ball. ellipse(ballX,ballY,20,20); //Creates the ball. if (bounce = !bounce) { //If the ball bounced off the top of the screen ... score += 25; //Add 25 to the player's score. } textSize(30); //Makes a large text to display score. text("" + score,width-100,height-5); //Makes the text appear in the bottom right corner. if (score > 1000 && score <= 1100) { //If you score 1000 points ... fill(255); //In white text ... textSize(30); //And big font ... text("GREAT JOB!",0,height-10); //Put some Words of Encouragment! } if (score > 2000 && score <= 2100) { //If you score 2000 points ... fill(255); //In white text ... textSize(30); //And big font ... text("AWESOME!",0,height-10); //Put SOME MORE WORDS OF ENCOURAGMENT! } if (score > 3000 && score <= 3100) { //If you score 3000 points ... fill(255); //In white text ... textSize(30); //And big font ... text("OUTSTANDING!",0,height-10); //You tell the player how well they are doing! } if (score > 4000) { //If you score 3000 points ... fill(255); //In white text ... textSize(30); //And big font ... text("WHY ARE YOU STILL PLAYING?!?!",0,height-10); //Tell the player there is a problem ... } if (abs(ballX - x) < width/8) { //If the ball is within the confinds of the paddle ... xCollision = true; //The ball has satisfied the X collision condition. } else { //Otherwise ... xCollision = false; //It hasn't. } if (abs(ballY - y) < 12.5) { //If the ball is lines up with the paddle ... yCollision = true; //The ball has satisfied the Y collision condition. } else { //Otherwise ... yCollision = false; //It hasn't. } if (xCollision == true && yCollision == true) { //If both conditions have been met at the same time ... ballDY = -ballDY*1.05; //Then the ball will bounce up and increase in vertical speed. } } void draw() { //It's Showtime! drawScene(); //Gentlemen ... drawGame(); //Start Your Engines! }