|Top Previous Next|
This month's "Plug and play" section contains the full code for a 3D pool game that uses the physics engine. The game uses a top view camera, but you can place the camera anywhere, make it follow player's (white) ball, and so on.
There are many sets of pool playing rules out there, so I have decided to make my own rules: you've got 9 balls, each one of them having a value of 50 points. If your (white) ball goes into one of the pockets, you lose 100 points, so the maximum score that can be obtained is 450 points.
The game can be restarted at any time by pressing the "R" key; this could come in handy if you hit a ball too hard and it jumps over the table border, for example. Move the mouse around to rotate the cue, press and hold the left mouse button, and then release it to hit the white ball. I have added a "max power" sound as well; it will tell us when the max power shot has been reached, so there's no need to keep pressing the left mouse button.
Feel free to play with the mass, friction, damping and elasticity for player's ball, as well as for the other 9 balls - it's an area that could use some improvements, depending on your preferences. Don't forget to try several max_power as well; this variable gives player's maximum shot power.
The entire code is fully commented, as always.