// Declare gameOperators These will be updated.
var paddleLeft;
/** Declare Update & Draw Functions outside Draw Loop */
var updatePaddle = function(){
paddleLeft = mouseX - PADDLE_WIDTH / 2;
};
var drawPaddle = function(){
rect(paddleLeft, PADDLE_TOP, PADDLE_WIDTH, PADDLE_HEIGHT);
};
//The all important: draw = function(){ };
draw = function(){ // Begin Draw Loop
background(0);
/** Call Update & Draw Functions inside Draw Loop */
updatePaddle();
drawPaddle();
}; // End Draw Loop
/** If the Ball goes Offscreen */
if(ballPositionY > 420){
playerLives -= 1; // Subtract 1 from Number of Plays
ballPositionY = 30; // Reposition Ball for next serve
}
/** Print the playerLives Variable to the screen **/
text("Lives left: " + playerLives, 40, 50);
Adding a Background image.
//Load Backround for end of Game
PImage bg_img;
void setup()
{
size(400, 400);
bg_img = loadImage("vintage(400).jpg");
}
//PAU GAME
if(playerLives === 0) {
//background(0, 0, 255);
image(bg_img);
fill(0, 0, 255);
textSize(36);
textAlign(CENTER);
text("Pau Game", 200, 100);
textSize(24);
textAlign(CENTER);
text("But you did Score: " + score, 200, 125);
noLoop();
}
}; // End Draw Loop