Game Development Reference
In-Depth Information
Figure 14-8. A typical Laser Simulation screen shot
When the Start button is clicked, the actionPerformed method declared in the LaserSimulator
class is called. The process followed by this version of the method is similar to that of the other
sample games presented in this topic. Values for the laser beam power, radius, and absorption
coefficient of the airplane are extracted from the text inside the text fields. The time required
for the plane to absorb 10,000 J/cm 2 is computed from Equation 14-6. The start method is
called on a Timer object to start the airplane moving across the screen.
// The actionPerformed() method is called when
// the Start button is pressed.
public void actionPerformed(ActionEvent event) {
// Get some initial quantities from the text fields.
double power = Double.parseDouble(powerTextField.getText());
double radius = Double.parseDouble(radiusTextField.getText());
double absorption = Double.parseDouble(absorptionTextField.getText());
// Determine the beam area.
double area = Math.PI*radius*radius;
// Compute beam contact time required to destroy airplane.
explosionTime = 10000.0*area/(absorption*power);
Search WWH ::




Custom Search