Game Development Reference
In-Depth Information
Creating Player Weapons and Ammunition
We need to create new classes for the player's weapon and the ammunition that the weapon uses.
The Ammunition class derives from the Object3d class.
public class Ammunition extends Object3d
The m_FireStatus variable is true if this piece of ammunition has been fired.
private boolean m_FireStatus = false;
The m_AmmunitionSpent variable allows you to keep track if this piece of ammunition has been used up.
private boolean m_AmmunitionSpent = false;
The m_AmmunitionRange variable holds the maximum range of the ammunition, which is defaulted to
50 units in the OpenGL world.
private float m_AmmunitionRange = 50;
The m_AmmunitionStartPosition variable holds the position the ammo is fired from and is initialized
to 0,0,0.
private Vector3 m_AmmunitionStartPosition = new Vector3(0,0,0);
The speed of the ammo in terms of OpenGL world units per update is held in m_AmmoSpeed and
defaults to 0.5.
private float m_AmmoSpeed = 0.5f;
The SFX index for the sound effect associated with this piece of ammo, if it exists, is m_FireSFXIndex .
The default, which is -1, means that there is no sound effect associated with this piece of
ammunition.
private int m_FireSFXIndex = -1;
The Ammunition constructor initializes the object by calling its base constructor and setting the
ammunition range, ammunition speed, and the mass of the ammunition, which is defaulted to 1.
(See Listing 7-14.)
Listing 7-14. Ammunition Constructor
Ammunition(Context iContext, Mesh iMesh, MeshEx iMeshEx, Texture[] iTextures, Material iMaterial,
Shader iShader, float AmmunitionRange,float AmmunitionSpeed)
{
super(iContext, iMesh, iMeshEx, iTextures, iMaterial, iShader );
m_AmmunitionRange = AmmunitionRange;
m_AmmoSpeed = AmmunitionSpeed;
GetObjectPhysics().SetMass(1.0f);
}
 
Search WWH ::




Custom Search