Game Development Reference
In-Depth Information
The GUI class for the Free-Kick Game is named FreeKick and is very similar to the GUI
for the Golf Game presented earlier in the chapter. When the Fire button is pressed, the
actionPerformed method declared in the FreeKick class is called. The first thing the method
does is to extract input values from the text fields and compute the angular velocity of the ball.
public void actionPerformed(ActionEvent event) {
// Extract input values from text fields.
double vx0 = Double.parseDouble(vxTextField.getText());
double vy0 = Double.parseDouble(vyTextField.getText());
double vz0 = Double.parseDouble(vzTextField.getText());
double spinRate = Double.parseDouble(spinRateTextField.getText());
double rx = Double.parseDouble(rxTextField.getText());
double ry = Double.parseDouble(ryTextField.getText());
double rz = Double.parseDouble(rzTextField.getText());
// Calculate the angular velocity from the spin rate.
double omega = spinRate*2.0*Math.PI;
The method sets the initial location of the ball and the values of the density and temperature.
Wind was not included as a user input in the GUI (although the SoccerBall class itself does
model wind effects), so the wind velocity is set to zero.
// The ball starts at a spot 18 meters from and directly
// in front of the goal.
double x0 = 23.2;
double y0 = 15.0;
double z0 = 0.0;
// Set the density to be sea level, the wind
// velocity to zero, and temperature to be 294 K.
double density = 1.2;
double temperature = 294.0;
double windVx = 0.0;
double windVy = 0.0;
Values are given to the fields that represent the mass, radius, and area of the soccer ball.
The drag coefficient is given a dummy value that is overwritten in the getRightHandSide method of
the SoccerBall class.
// Define some soccer ball variables. The cd value will be
// overridden in the getFunction method of the SoccerBall class.
double ballMass = 0.43;
double radius = 0.11;
double area = Math.PI*radius*radius;
double cd = 0.25;
When all of the initial values are specified, a SoccerBall object is created. The start method
is called on a Timer object to start the simulation.
Search WWH ::




Custom Search