https://pastein.ru/t/Fq
скопируйте уникальную ссылку для отправки
Загрузка данных
const moveSpeed = 9; var moveSpeedNow; var ballSpeedX = 18; var ballSpeedY = 0; var rightPaddle = document.getElementById('right'); var leftPaddle = document.getElementById('left'); var field = document.getElementById('field'); var pressedKeysCodes = new Set(); var allCodes = [38, 40, 83, 87]; var startTime = new Date; var limitedTime = new Date; function go1() { if (pressedKeysCodes.has(40) && pressedKeysCodes.has(83)) { rightPaddle.style.top = (((rightPaddle.getBoundingClientRect().top - field.getBoundingClientRect().top - 7) + moveSpeed)) + "px"; leftPaddle.style.top = (((leftPaddle.getBoundingClientRect().top - field.getBoundingClientRect().top - 7) + moveSpeed)) + "px"; } if (pressedKeysCodes.has(38) && pressedKeysCodes.has(87)) { rightPaddle.style.top = (((rightPaddle.getBoundingClientRect().top - field.getBoundingClientRect().top - 7) - moveSpeed)) + "px"; leftPaddle.style.top = (((leftPaddle.getBoundingClientRect().top - field.getBoundingClientRect().top - 7) - moveSpeed)) + "px"; } if (pressedKeysCodes.has(83) && pressedKeysCodes.has(38)) { leftPaddle.style.top = (((leftPaddle.getBoundingClientRect().top - field.getBoundingClientRect().top - 7) + moveSpeed)) + "px"; rightPaddle.style.top = (((rightPaddle.getBoundingClientRect().top - field.getBoundingClientRect().top - 7) - moveSpeed)) + "px"; } if (pressedKeysCodes.has(87) && pressedKeysCodes.has(40)) { leftPaddle.style.top = (((leftPaddle.getBoundingClientRect().top - field.getBoundingClientRect().top - 7) - moveSpeed)) + "px"; rightPaddle.style.top = (((rightPaddle.getBoundingClientRect().top - field.getBoundingClientRect().top - 7) + moveSpeed)) + "px"; } if (pressedKeysCodes.has(40)) { rightPaddle.style.top = (((rightPaddle.getBoundingClientRect().top - field.getBoundingClientRect().top - 7) + moveSpeed)) + "px"; } if (pressedKeysCodes.has(38)) { rightPaddle.style.top = (((rightPaddle.getBoundingClientRect().top - field.getBoundingClientRect().top - 7) - moveSpeed)) + "px"; } if (pressedKeysCodes.has(83)) { leftPaddle.style.top = (((leftPaddle.getBoundingClientRect().top - field.getBoundingClientRect().top - 7) + moveSpeed)) + "px"; } if (pressedKeysCodes.has(87)) { leftPaddle.style.top = (((leftPaddle.getBoundingClientRect().top - field.getBoundingClientRect().top - 7) - moveSpeed)) + "px"; } console.log(pressedKeysCodes); return; } addEventListener("keydown", function (event) { pressedKeysCodes.add(event.keyCode); go1(); }); addEventListener('keyup', function (event) { pressedKeysCodes.delete(event.keyCode); });