In this section, I have implemented a "pause" functionality for the game. After clicking on the "Pause" button once, clicking on it again, or clicking on the "Play" button will resume the game. I've also added information about the state of the game when it is paused or stopped. In a real game, erasing the screen when pausing the game is often done to prevent players from "cheating" by pausing a fast moving game to see what they should do next. Here, as we are developping the game, I avoid doing this so as to better see what is happening with the ball.
Take some time to read the code and understand why I change the
values of the flags STOPPED
and
PAUSED
in various places. In programming, a flag
is the general name of a variable used to indicate the state of a program.
With the ball moving as fast as it does, it might be a bit difficult to
see what is going on. If you are curious, I suggest that you change
BALL_dx
and BALL_dy
in the html editor to smaller
values. You can also change the animation frame rate, or the initial
position of the ball.
Next, I will make the ball bounce on the canvas "walls", keeping it inside the canvas. Perhaps you can do this yourself first, right now, by adding some code within the html editor window.
Keep your personal notes here. These notes are stored by your browser on your own computer, and will be available from any page on this site. You can choose to use html syntax for formatting.