function moveEverything (){
if(showingWinScreen) {
return;
}
computerMovement();
ballX += ballSpeedX;
ballY += ballSpeedY;
// Getting the ball to hit the panel
if (ballX < 0) {
if (ballY > paddle1Y &&
ballY < paddle1Y + PADDLE_HEIGHT) {
ballSpeedX = -ballSpeedX;
var deltaY =ballY
-(paddle1Y+PADDLE_HEIGHT/2);
ballSpeedY = deltaY * .35;
} else {
player2Score++; // Must come before reset
ballReset();
}
}
if (ballX > canvas.width) {
if (ballY > paddle2Y &&
ballY < paddle2Y + PADDLE_HEIGHT) {
ballSpeedX = -ballSpeedX;
var deltaY =ballY
-(paddle2Y+PADDLE_HEIGHT/2);
ballSpeedY = deltaY * .35;
} else {
player1Score++; // Must come before reset
ballReset();
}
}
if(ballY < 0) {
ballSpeedY = -ballSpeedY;
}
if(ballY > canvas.height) {
ballSpeedY = -ballSpeedY;
}
}
Net
function drawNet() {
for(var i=0; i<canvas.height; i += 40) {
colorRect (canvas.width/2-1,i,2,20,'white');
}
}
Ball & Panel
function drawEverything(){
// Draws the page black
colorRect(0,0, canvas.width, canvas.height, 'black');
// Win Screen
if(showingWinScreen) {
canvasContext.fillStyle = 'white';
if (player1Score >= WINNING_SCORE) {
canvasContext.fillText("Left Player Won!", 350, 200);
} else if(player2Score >= WINNING_SCORE) {
canvasContext.fillText("Right Player Won!", 350, 200);
}
canvasContext.fillText("Click to continue", 350, 400);
return;
}
## Draw Net
drawNet();
// Draws the left
colorRect(0, paddle1Y, PADDLE_THICKNESS, PADDLE_HEIGHT, 'white');
// Draws the right
colorRect(canvas.width-PADDLE_THICKNESS, paddle2Y, PADDLE_THICKNESS, PADDLE_HEIGHT, 'white');
// Draws the Ball
colorCircle(ballX, ballY, 10, 'white')
// The score
canvasContext.fillText(player1Score, 100, 100);
canvasContext.fillText(player2Score, canvas.width-100, 100);
}