Game Development Reference
In-Depth Information
Creating the Player's Weapon
Next, the player's weapon and the ammunition it uses need to be created in the MyGLRenderer
class.
The player's weapon is
m_Weapon
.
private Weapon m_Weapon = null;
The sound effects for the player's weapon are held in
m_PlayerWeaponSFX
.
private Sound m_PlayerWeaponSFX = null;
The player's weapon is created in the
CreateWeapon()
function.
The
CreateWeapon()
function (see Listing 7-58) does the following:
1.
Creates a new shader that uses vertex shaders and fragment shaders that
require no texture. This is for the ammunition that does not use a texture.
2.
Creates a cube mesh for use as the 3D model for the weapon's ammunition.
Creates a new
Material
object and sets its emissive property to green.
3.
4.
Creates a new weapon and sets its ammunition range and speed.
5.
Creates and loads in new ammunition into the weapon by calling the
weapon's
LoadAmmunition()
function. These pieces of ammunition are green
cubes that are created from the cube mesh and
Material
object created in
previous steps.
Listing 7-58. Creating the Weapon
void CreateWeapon(Context iContext)
{
//Create Cube Shader
Shader Shader = new Shader(iContext, R.raw.vsonelightnotexture, R.raw.fsonelightnotexture);
// ok
// Create
MeshEx CubeMesh = new MeshEx(6,0,-1,3,Cube.CubeDataNoTexture, Cube.CubeDrawOrder);
// Create Material for this object
Material Material1 = new Material();
Material1.SetEmissive(0.0f, 1.0f, 0.0f);
// Create Weapon
m_Weapon = new Weapon(iContext, null, null, null, Material1, Shader);
float AmmunitionRange = 100;
float AmmunitionSpeed = 0.5f;