previousnext

We're going to control the paddle by using the left and right arrow keys from the keyboard.

To do this, we need to do two things: 1) find out when the left and right arrow keys have been pressed and 2) move the paddle when they have.

In order to receive key events, we'll create one function called on_key_up and another called on_key_down, then use a bit of jQuery magic to bind them to the appropriate events.

Then, on our way through the draw function, we'll check to see if either arrow is pressed down, and move the paddle accordingly.

And we have a game!

:-)

Well ... we do have a few more things to do, but we are getting there.

previousnext