Game Development Reference
In-Depth Information
public class GolfGame extends JFrame implements ActionListener
{
private JTextField vxTextField;
private JTextField vyTextField;
private JTextField vzTextField;
private JTextField distanceTextField;
private JLabel vxLabel;
private JLabel vyLabel;
private JLabel vzLabel;
private JLabel distanceLabel;
private JComboBox axesComboBox;
private JButton fireButton;
private JButton resetButton;
private JPanel drawingPanel;
private GridBagConstraints gbc;
// The golf ball is a SimpleProjectile.
private SimpleProjectile golfball;
// The player can control the distance to the hole.
private double distanceToHole;
// These fields are for the images used in the game.
private ImageIcon golferIcon;
private ImageIcon flagIcon;
private int golferWidth;
private int golferHeight;
private int flagWidth;
private int flagHeight;
// These elements are used to control the execution
// speed of the game. Without them, the game would
// run too quickly.
private GameUpdater gameUpdater;
private Timer gameTimer;
Like all constructors, the GolfGame constructor is used to initialize the fields declared in the
class. A SimpleProjectile object is created to represent the golf ball that is fired from the tee.
The velocities of the golf ball are initially set to zero, but their values will be updated based on
the text in the text fields when the Fire button is pressed. The initial x-, y-, and z-coordinates of
the golf ball are all set to zero. The distanceToHole field is initially set to be 200 m .
Search WWH ::




Custom Search