Game Development Reference
In-Depth Information
// If the ball hits the ground, stop the simulation
// and determine if it landed in the box.
if ( ballAltitude <= 0.0 ) {
gameTimer.stop();
if ( ballLocation >= boxLocation &&
ballLocation <= boxLocation + boxWidth - 10 ) {
resultsTextField.setText("You Win!");
}
else {
resultsTextField.setText("Try again");
}
}
}
}
Play around with the Gravity Game. The Reset button resets the display. If the box and ball
don't appear for any reason, press the Reset button to redraw the GUI. Also remember that the
ball won't start to drop until the Drop button is pressed. Try switching the planet from “Earth”
to “Moon” or “Jupiter” and see what happens. Don't forget that you can also adjust the velocity
at which the box will travel.
You'll notice that the ball travels very slowly just after it is dropped but gains speed steadily
with each passing second. This effect is a characteristic of gravity in that it provides a constant
acceleration. The longer an object falls, the faster it will go.
Note When an object travels through an atmosphere, gravity won't continue to accelerate the object
forever because an effect known as aerodynamic drag will limit how fast the object can travel. We'll learn
about aerodynamic drag when we study projectiles in Chapter 5.
Exercise
1.
Compute the gravitational acceleration on the surface of Earth's moon. The radius of the moon is 1.7374 e +6 m ,
and the mass of the moon is 7.3483 e +22 kg .
Friction
Friction is the force that resists motion between two contacting surfaces. When you pick up a
glass of water, it is friction between your hand and the glass that allows you to lift the glass to
your mouth. When a car drives around a curve in the road, it is friction between the tires and
the road that keeps the car from sliding off the road. Friction occurs between all types of matter—
solids, liquids, and gases—and is an important component in many physical models.
Search WWH ::




Custom Search