Game Development Reference
In-Depth Information
We will highlight one feature of the BoatSimulator class. The planing speed for the
Fountain 35' Lightning speedboat is 8.44 m/s (30.4 km/hr ). When the boat reaches this speed,
the planing action of the hull begins and the hull tilts upward. While the physical details of the
planing process are not modeled in the Boat Simulator, the appearance of planing is modeled.
The resetDisplay method is used to update the GUI display. The BoatSimulator class uses
three pictures to display the boat. If the x-component of boat velocity is less than the planing
speed, the “no planing” picture of the boat is used. If the boat has reached planing speed, the
“half-plane” picture is used, which shows the boat beginning to tilt upward. If the boat velocity
is greater than the planing speed plus 2.0 m/s , the “full-plane” picture is used to show the boat
at the full-plane tilt angle.
// Get the graphics object on the JPanel.
Graphics g = drawingPanel.getGraphics();
int width = drawingPanel.getWidth() - 1;
int height = drawingPanel.getHeight() - 1;
g.clearRect(0, 0, width, height);
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
g.setColor(Color.BLACK);
g.drawLine(0, 70, width, 70);
// Draw the boat depending on whether the boat
// is planing or not.
if ( boat.getVx() < boat.getPlaningSpeed() ) {
g.drawImage(noPlaneIcon.getImage(), 100, 95,
noPlaneWidth, noPlaneHeight, drawingPanel);
}
else if ( boat.getVx() < boat.getPlaningSpeed() + 2.0 ) {
g.drawImage(halfPlaneIcon.getImage(), 100, 95,
halfPlaneWidth, halfPlaneHeight, drawingPanel);
}
else {
g.drawImage(fullPlaneIcon.getImage(), 100, 95,
fullPlaneWidth, fullPlaneHeight, drawingPanel);
}
The effect (although somewhat primitive) of the three pictures is to show the boat tilting
upward when it passes through its planing speed. If the boat slows down below its planing
speed, the boat in the GUI tilts back down. Play around with the Boat Simulator. The boat
doesn't do much more than speed up or slow down, but the simulation does a good job of
reproducing the performance test data for the Fountain Lightning speedboat.
There are a couple of things to keep in mind about the Boat Simulator. The acceleration as
modeled by the Boat Simulator is the maximum, full-throttle acceleration. No attempt was
Search WWH ::




Custom Search