So far, the physics engine depends on the user clicking and dragging the mouse to control the speed and direction, this means that it can still be used for testing while the program is being developed.
The pockets are set up using the getWidth() and getHeight() functions and the size of the radius. The corner pockets are 2 radii wide by 2 radii high and the centre pockets are 4 radii wide.
Below is the code for the top left pocket
if((balls[i].position.getX() <= 2*balls[i].getRadius())
&& (balls[i].position.getY() <= 2*balls[i].getRadius()))
However we don't want the cue ball entering the pocket and being counted as a 'hit' so I added:
if((i>0) && (balls[i].position.getX() <= 2*balls[i].getRadius())
&& (balls[i].position.getY() <= 2*balls[i].getRadius()))
where the ball i=0 is the cue ball.
When this 'if' statement is fulfilled, the ball velocities are set to zero, a 1 is entered in the appropriate pocket of the hit array (in this case the hit array would be [1, 0, 0, 0, 0, 0] to indicate a hit in the first pocket), and the value of 'true' is returned to a later part of the code.
No comments:
Post a Comment