https://ci-wdi-900.github.io/pong/

1 answer below »
Answered Same DayNov 03, 2021

Answer To: https://ci-wdi-900.github.io/pong/

Swapnil answered on Nov 04 2021
136 Votes
95368/index.html







95368/main.js
const GAME_AREA_WIDTH =
900;
const GAME_AREA_HEIGHT = 800;
const PADDLE_HEIGHT = 100;
const PADDLE_WIDTH = 10;
const gameArea = document.querySelector('.game-area')
const BALL_SIZE = 10;
const ball = document.querySelector('.ball');
const computerPaddle = document.querySelector('.computer-paddle');
const leftPaddle = document.querySelector('.player-paddle');
computerPaddle.style.borderRadius = '10px'
leftPaddle.style.borderRadius = '10px'
leftPaddle.style.backgroundColor = 'red'
function handleKeyboardInput (event)
{
if (event.key=== 'ArrowDown')
{
leftPaddleYPosition +=50
}
else if (event.key === 'ArrowUp')
{
leftPaddleYPosition -=50
}
}
document.addEventListener('keydown', handleKeyboardInput)
let computerPaddleYPosition = 0;
let computerPaddleYVelocity = 1;
let leftPaddleYPosition = 0;
let leftPaddleYVelocity = 1;
let ballXPosition = 20;
let ballXVelocity = 5;
let ballYPosition = 0;
let ballYVelocity = 5;
function update()
{
computerPaddleYPosition = ballYPosition-PADDLE_HEIGHT/2;
if (computerPaddleYPosition > GAME_AREA_HEIGHT-PADDLE_HEIGHT)
{
computerPaddleYPosition = GAME_AREA_HEIGHT-PADDLE_HEIGHT;
}
else...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here