1. Introduction
  2. Draw a Circle
  3. Add Some Color
  4. Action
  5. Library: an Interlude
  6. Bounce
  7. Add a Paddle
  8. The Keyboard
  9. The Mouse
  10. The Bricks
  11. Finishing Touches
  12. Coda

The Mouse

Adding mouse support to our game is even simpler; all we have to do is send the mousemove event to an onMouseMove function, see if the mouse is within the borders of the game, and move the paddle if it is.

Try changing the draw function so that the middle of the paddle is located directly above the mouse pointer instead of the left side.

Now that the keyboard and mouse work, all that's left to do is put in the bricks and add some design and code polish. As usual, we'll stuff all the code not in the draw() function into the library on all future pages.

next prev