User interact with the program using both the mouse and keyboard. While the cue stick appears on the screen, the program continually inputs the coordinates of the mouse. These coordinates are used to determine where the end of the cue stick should be. The program takes the x-coordinate of the mouse and calculates an appropriate y-coordinate so that the end of the cue will move around the cue ball in a circle of radius 6 (this is the length of the cue). Therefore, by simply moving the mouse left and right, the user can rotate the cue stick around the ball. If the absolute value of the x-coordinate exceeds 6, the y-coordinates switch sign so that the cue faces in the opposite y direction. This allows for 360 degrees of rotation. The user left-clicks the mouse to shoot the ball in the direction that the cue is pointed. Once the balls have stopped due to the simulated friction, striking spacebar will bring the cue stick back and allow the user to shoot again.
I hope that others will continue to improve my program, making it more realistic and allowing for more user-interaction. There are several things that I would have wanted to add had time permitted:
- Add More Balls
- Allow user to add spin by hitting different parts of the cue ball
- Allow balls to move in 3-dimensions
- Allow user to control how hard he hits the cue ball
- Improve the accuracy of the collision detection