Game Development Reference
In-Depth Information
Next, we add code to load in the previously saved game stats.
m_ObjectStats.LoadStats(StatsHandle);
Hands-on Example: Target Shooting!
Now, it's time to use some of the new classes that I discussed previously in this chapter. This example
builds upon previous examples by adding the player's power pyramid, a moveable player's view that
you can turn left and right, and a weapon that can fire projectiles by the user touching the screen.
A cube is placed in front of the player's pyramid, and another cube is placed behind the pyramid.
We have to make modifications to the MyGLRenderer class to add code that creates the player's
pyramid, creates the player's weapon, and processes the collisions between the cube in front of the
pyramid and the pyramid and between the player's weapon's projectiles and the cubes.
Creating the Player
In order to create the player's power pyramid, we have to add some new variables and functions.
The player's power pyramid is m_Pyramid .
private PowerPyramid m_Pyramid;
The textures that are used with the player's pyramid are held in m_TexPyramid1 and m_TexPyramid2 .
private Texture m_TexPyramid1;
private Texture m_TexPyramid2;
The PyramidCreateTexture() function creates the textures for our player's power pyramid and stores
these textures in m_TexPyramid1 and m_TexPyramid2 . (See Listing 7-56.)
Listing 7-56. Creating the Textures for the Pyramids
public void PyramidCreateTexture(Context context)
{
m_TexPyramid1 = new Texture(context,R.drawable.pyramid1);
m_TexPyramid2 = new Texture(context,R.drawable.pyramid2);
}
The CreatePyramid() function creates the player's pyramid graphic. (See Listing 7-57.)
The function does the following:
1.
Creates a shader for use in rendering the pyramid.
Creates a new Mesh object using the data from the PyramidVertices array in
the Pyramid class.
2.
Creates a new Material object that sets the glow animation to true, so that
when the material is updated, the emissive color property cycles between the
values set with GetEmissiveMin() and GetEmissiveMax() .
3.
 
Search WWH ::




Custom Search