I'm seeking advice on how to create a function using JavaScript. Currently, I am developing a snake game and have successfully implemented movement controls. By clicking buttons, I can navigate the snake in different directions. However, I've encountered an issue where if the same button is clicked multiple times in a row, the speed of the snake increases due to the SpeedX += 5; function being executed.
I'm trying to find a solution to prevent this from happening. One idea I had was to implement an event or function that restricts the ability to click the same direction repeatedly until a new direction is chosen. Do you have any suggestions for me?