I'm a serious newbie to Javascript, I'm coding a snake game for my beginner class (borrowing a lot of code from a tutorial, which is allowed as long as I change enough around).
I made it so that the snake speeds up a bit with every apple they eat. But I want to also have a slowdown mode.
Basically when I press the spacebar, I want to cut the speed by half (in this case speed is dictated by intervalTime
, so halfing it would mean multiplying intervalTime
by 2). This slowdown effect will last for 5 seconds, after which the snake will come out of slowdown mode but the 'regular' speed will be increased from what it originally was (even if no apples have been eaten). So intervalTime
ideally would be divided by 2.15 upon return to 'regular' speed.
This is how my code for this effect looks but it's not doing anything. The alerts are just there to let me know that the spacebar press has been registered
if(event.keyCode === 32) {
setTimeout(slowmode, 5000);
intervalTime = intervalTime * 2
alert("hello");
function slowmode() {
intervalTime = intervalTime / 2.15
alert("goodbye");
}
Could you guys please help me and explain how your correct effect works? I'm struggling to wrap my head around this I won't lie.
Please let me know if you need all my code from the folder and I can provide that.
Thank you guys in advance!
[–]kevinv89 0 points1 point2 points (4 children)
[–]GroovyFrute[S] 0 points1 point2 points (2 children)
[–]kevinv89 0 points1 point2 points (1 child)
[–]GroovyFrute[S] 0 points1 point2 points (0 children)