Objects can be hit by balls. This is where the application starts to get interesting. When a ball hits a wall, the direction the ball is moving is reflected. In contrast, when a ball hits a hole, the energy in the ball is drained (so it will stop moving) and the ball is moved off the playing surface. That is, unless it is the cue ball, in which case it is placed back into the center of the table.
When two balls hit it is more complex. The energy of the hitting ball is shared with the ball it hits, and both move off in new directions. The physics of this reaction are not precisely described by the code shown here, but it is close enough to look realistic.