Game Development Reference
In-Depth Information
Hands-on Example: Arena Objects and Tanks
Now, let's use the Arena Object class and the Tank class in a working hands-on example. We must
make some modifications to our code from Chapter 7's hands-on example. This hands-on example
Modifying the MyGLRenderer Class
The type for the
m_Cube
variable has been changed to an ArenaObject class.
private ArenaObject3d m_Cube;
In the
CreateCube()
function, we create a new ArenaObject instead of a Cube object.
m_Cube = new ArenaObject3d(iContext, null,CubeMesh, CubeTex, Material1, Shader,XMaxBoundary,XMinBou
ndary,ZMaxBoundary,ZMinBoundary);
The
onDrawFrame()
function now updates
m_Cube
with
UpdateArenaObject()
instead of
UpdateObject3d()
.
m_Cube.UpdateArenaObject();
Next, we have to add in some code for our new tank. I will discuss the key functions in this section.
The
m_Tank
variable is added in to represent our enemy tank.
private Tank m_Tank;
The
CreateTankType1()
function (see Listing 8-63) creates the tank object. The
CreateTankType1()
function does the following:
1.
Creates the tank's weapon and ammunition
2.
Creates the material for the tank's main body
3.
Creates the tank's main body texture
4.
Creates the mesh for the main tank body with data from
Pyramid2.Pyramid2Vertices
5.
Creates the material for the tank's turret
6.
Creates the texture for the tank's turret
Creates the tank's turret mesh with data from
Pyramid2.Pyramid2Vertices
7.
8.
Creates the tank's turret offset
9.
Creates the tank's shader
10.
Initializes the tank properties, such as the tank's position, scale, sound
effects, color that it makes on the grid, etc.