Suppose you are moving 7 units of distance at each step. You are at unit 95. The next step, you would normally move to unit 102. However, there is a wall in your way at unit 100. So, instead of getting to unit 102 (and passing the wall by 2 units) you bounce back (the same 2 units) to 98. This is the kind of calculation that is taken into account by the code below, remembering that the position of the ball is that of its centre.

Note that, the way we had done the calculation previously would correspond to stopping at the wall (unit 100) rather than bouncing back.


Get ahead of me!

Next, we add a paddle; this will be a simple rectangle drawn near the bottom on the screen. Can you do this now?


Your notebook

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.


HTML Add Note


  1. Introduction
  2. Drawing a Ball
  3. Defining Ball Variables
  4. Animate!
  5. Stop!
  6. Pause
  7. Bounce!
  8. Bouncing correctly
  9. Adding a paddle