float x, y, speedX, speedY; float diam = 10; float rectSize = 200; int points = 0; //integer with decimal points while int only does it without deciamls void setup() { //defines intital environment and is only run once fullScreen(); //defines pop up window properties fill(0, 255, 0); textSize(32); reset(); } void points(){ fill(255, 255, 0); //text(points, 200, 60); } void reset() { x = width/2; //100 y = height/2; //100 speedX = random(3, 5); //resets the ball's speed speedY = random(3, 5); } void draw() { //loops forever until completed background(0); //color black of the backround text("Points: " + points, 560, 60); ellipse(x, y, diam, diam); //shape of the ball rect(0, 0, 20, height); //rectangle on the left rect(width-30, mouseY-rectSize/2, 10, rectSize); //rectangle on the right, moves with mouse x += speedX; //3,4, 0r 5 + 200 y += speedY; //3,4 or 5 + 200 // if ball hits movable bar, invert X direction if ( x > width-30 && x < width -20 && y > mouseY-rectSize/2 && y < mouseY+rectSize/2 ) { // compares both and can only be true if both are true. Only Y because rect can only be allowed to move vertically and is depedended on the mouse's movement. speedX = speedX * -1; points = points +1; } // if ball hits wall, change direction of X if (x < 25) { speedX *= -1.1; speedY *= 1.1; x += speedX; } // if ball hits up or down, change direction of Y if ( y > height || y < 0 ) { // can be true if one expression is true, but can only be false if BOTH expressions are false speedY *= -1; } // } void mousePressed() { //as you'd expect its a mouse press that resets the game reset(); }