Game Development Reference
In-Depth Information
Golf Game Version 3
With the
WindProjectile
class available to us, we can modify the Golf Game to incorporate
wind effects. The class that will implement the new version of the game is called
GolfGame3
.
A typical screen shot for the game is shown in Figure 5-11. Two new text fields have been added
to the GUI that allow the x- and y-components of wind velocity to be specified. Everything else
about the GUI is the same as in version 2 of the Golf Game. A negative x-component of wind
velocity indicates a headwind. If the x-component of wind velocity is positive, then there is a
tailwind. A positive y-component of wind velocity indicates a right-to-left crosswind.
Figure 5-11.
A typical Golf Game version 3 screen shot
Very few changes had to be made to the
GolfGame2
class to produce the
GolfGame3
class.
A
WindProjectile
field is declared that will represent the golf ball.
import javax.swing.*;
import java.awt.*;
import javax.swing.border.BevelBorder;
import java.awt.event.*;
import javax.swing.Timer;
public class GolfGame3 extends JFrame implements ActionListener
{
// GUI component declarations not shown ...
// The golf ball is a WindProjectile.
private WindProjectile golfball;