Pascal Worked Example: Bouncing Ball

From SwinBrain


Implement a game where a ball is placed within a designated area of the screen. The ball will have a specified velocity and will move around within the area. When the ball collides with the edge of the area it should change direction. Striking the bottom/top of the area will reverse the y movement, while striking the left/right will reverse the x movement.


Data: This program will need to store the X and Y location of the ball, as well as details about the area it is moving within. For the area we will need the X, Y location of the upper left hand corner and the width and height.

Structure: The structure of the program will evolve as we perform the iterations. Initially I expect to have the following routines within this program.

  • Draw Border (around the area)
  • Draw Ball
  • Move Ball
  • Clear Ball


This solution was implemented in a number of iterations.

[edit]Bouncing Ball: Overview | Iteration 1 | Iteration 2 | Iteration 3 | Iteration 4
Sample Code » C | C++ | .NET | Pascal | Perl | T-Sql | XHTML | Python | others to come