xxxxxxxxxx
//Global declarations
float x;
float y;
float xSpeed = 7;
float ySpeed = 5;
float score = 0;
void setup(){
size(800,500);
x = width/2;
y = height/2;
}
void draw(){
background(0);
//Display ball
ellipse(x,y,20,20);
//Move ball
x+= xSpeed;
y+= ySpeed;
//Bounce ball
if (x > width || x < 0){
xSpeed*= -1;
}
if (y > height || y < 0){
ySpeed*= -1;
}
if (x < 65 && y < (mouseY + 25) && y > (mouseY - 25)){
xSpeed*= -1;
score++;
xSpeed = random(5,9);
ySpeed = random(-9,9);
}
if (x < 50){
score = 0;
x = 700;
y = random(5,295);
}
//Display paddle
rectMode(CENTER);
rect(50,mouseY,10,50);
println("x: " + x);
println("mouseY: " + mouseY);
println("score: " + score);
}