The assignment calls for a number of balls, using an array to keep track of each ball's values. I used an array to hold the multiple objects of "ball", rather than the actual values. For a bit more fun, I added a collision detect routine. Every move update checks the location of the other balls to determine if an intersection has occured. If so, the vectors of each ball are turned 90 degrees. It's a very rough approximation of balls bouncing into each other, but for the most part it looks reasonable.
Collisions are calculated by comparing a "box" around each circle to another "box" around the other circles. If the any two points of the box overlap, a collision occurs. It too is a rough approximation of an actual collision. |

Download the source code here