A collision occurs when two objects overlap. That is to say they both occupy the same space, either in whole or in part. As this shall be our first collision exercise, we shall limit our efforts to detecting collisions between pairs of circles.
You shall repeat the process of creating circle pairs, detecting their collision status, and displaying them in the GDIDrawer window each time the user presses the spacebar. If the user presses any other key, even before the first pair is evaluated, your program shall exit.
In order to create pairs of circles you will require two sets of information. Each circle will require a radius and a center point described by an X- and Y-coordinate pair. These values shall be generated randomly, adhering to the following rules:
1) Each radius shall have a size between 25 and 200 inclusive.
2) The location of the circles shall be set such that the entirety of each circle may be displayed within the GDIDrawer window. Remember that the GDIDrawer window is 800 x 600 pixels.
Once the values for describing the circles have been generated, you must create an equation which will allow you to determine whether the circles collide. To be clear, if your equation determines that the circles are either touching or overlapping, then they shall be considered to have collided.
Finally, if your equation determines that the circles have collided, you shall display both circles colored red in the GDIDrawer window as shown in Figure 11-1 at the top of the following page. On the other hand, if your equation determines that the circles have not collided, then you shall display them in the GDIDrawer window with randomized values for red, green, and blue as shown in Figure 11-2 at the bottom of the following page.
Figure 11-1: Sample Set of Circles Which Have Collided
Figure 11-2: Sample Set of Circles Which Have Not Collided