我正在寻找一些帮助,以便在 Tumult Hype 中使用 Javascript 为 Breakout 游戏添加一些代码。我希望做到这一点,这样一旦你达到一定的分数,球速就会增加。
这是到目前为止没有加速器的代码。
var input1 = event.which || event.keyCode;
if ((input1 == "37") && (window.setLoopLeft == false)) { // LEFT ARROW PRESSED
window.setLoopLeft = true;
window.intervalLeft = setInterval(moveLeft, 5);
} else if ((input1 == "39") && (window.setLoopRight == false)) { // RIGHT ARROW PRESSED
window.setLoopRight = true;
window.intervalRight = setInterval(moveRight, 5);
} else if ((input1 == "32") && (window.ballLaunched == false)) { // SPACE BAR PRESSED
window.ballLaunched = true;
// RUN THE MOVEBALL FUNCTION EVERY 10 MILLISECONDS
window.intervalMoveBall = setInterval(moveBall, window.ballSpeed);
}
function moveBall() {
var ballLeft = parseInt(hypeDocument.getElementById("ball").style.left);
var ballTop = parseInt(hypeDocument.getElementById("ball").style.top);
这是我要添加的代码。现在我的计划是创建一个全局变量以应用于 window.intervalMoveBall。然后,我将编写一个新函数,该函数将检测 1000 分的得分值并将球速度加倍,使其每 5 毫秒而不是 10 毫秒移动一次。
现在我不知道该怎么做实际上是编写 if 语句,以便它检测分数值。我想知道是否有人可以向我展示如何纠正它,甚至可以告诉我使用带有 if 语句的全局函数和新函数是否适用于此。