I am looking for a little help on adding on to some code for a Breakout game using Javascript within Tumult Hype. I am looking to make it so that once you hit a certain score the ball speed will increase.
Here is the code so far without the speed booster.
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);
This is the code I am adding onto. Now what I was planning was to do what create a global variable to apply to the window.intervalMoveBall. I would then write a new function that would detect the score value at 1000 points and double the balls speed making it move every 5 miliseconds instead of 10.
Now what I am not sure how to do is actually write the if statement so that it detects the score value. I was wondering if anybody might be able to show me how to right that or even be able to tell me if using a global and a new function with an if statement will even work for this or not.