xxxxxxxxxx
//variables
float xPos, xSpeed; // horizontal motion
float yPos, ySpeed; // vertical motion
int score; //score
int red, green, blue; //colours
//setup
void setup () {
red = 255;
green = 255;
blue = 0;
xPos = 250;
yPos = 250;
xSpeed = 3;
ySpeed = 5;
score = 0;
size (500, 500);
background(0, 255, 255);
}
// forever loop
void draw () {
noStroke();
fill(0, 25);
rect (0, 0, width, height);
// ball
fill (red, green, blue);
ellipse (xPos, yPos, 30, 30);
xPos = xPos + xSpeed;
yPos = yPos + ySpeed;
if (xPos < 15) {
xSpeed = xSpeed * - 1;
}
if (xPos > 500) {
xSpeed = 0;
ySpeed = 0;
textSize(45);
textAlign (CENTER);
text("Game Over\nTry Again", 250, height - 150);
}
if (yPos > 485 || yPos < 15) {
ySpeed = ySpeed * - 1;
}
if (xSpeed > 0 && xPos > 455 && yPos > mouseY && yPos < mouseY+120){
xSpeed = xSpeed * -1.1;
score = score + 1;
red = random(100, 255);
green = random (100, 255);
blue = random (100, 255);
}
// paddle
rect (width-30, mouseY, 50, 120, score*2);
textAlign(CENTER);
textSize (50);
text ("SCORE: " + score, width/2, height/2);
}