PFont font; float ball_x; float ball_y; float dir_x = 1; float dir_y = 0; float ball_size = 10; float paddle_y; float paddle_width =15; float paddle_height = 50; int lose = 0; void setup(){ size(300,300); noStroke(); smooth(); ball_y = height/2; ball_x = 1; ellipseMode(CORNER); font = loadFont("DialogInput-24.vlw"); textFont(font); } void draw(){ background(51); ball_x += dir_x; ball_y += dir_y; // constrain the paddle so it never moves off screen paddle_y = constrain(mouseY, 0 , height-paddle_height); // if the ball is touching the paddle // first condition checks if it is at the back wall // second two conditions check if it is touching the paddle if(ball_x > width-paddle_width-5-ball_size && ball_y > paddle_y && ball_y < paddle_y + paddle_height){ // changes direction dir_x = dir_x*-1; } // if it is touching the front wall change direction if(ball_x < 0){ dir_x = dir_x*-1; } // if the ball misses the wall the game has been lost if(ball_x > width - ball_size){ lose = 1; } // if the game has not been lost draw the shapes // otherwise write loser to the screen if(lose == 0){ fill(255); ellipse(ball_x, ball_y, ball_size, ball_size); fill(153); rect(width-paddle_width-5, paddle_y, paddle_width, paddle_height); } else{ text("loser", 100,100); } }