Game Development Reference
In-Depth Information
The GetAvailableArenaObject() function (see Listing 10-7) returns an available arena object by
Searching through the entire set of arena objects in the m_ArenaObjectSet
array and trying to find an ArenaObject3d object that is not null and not active
1.
2.
Processing a non-null object by setting the object's visibility to true, setting
the object to active by setting the corresponding slot in the m_Active array,
and returning the object
3.
Returning a null value if no available object is found
Listing 10-7. Getting an Available Arena Object
ArenaObject3d GetAvailableArenaObject()
{
ArenaObject3d temp = null;
for (int i = 0; i < MAX_ARENA_OBJECTS; i++)
{
if (m_ArenaObjectSet[i] != null)
{
if (m_Active[i] == false)
{
m_ArenaObjectSet[i].SetVisibility(true);
m_Active[i] = true;
return m_ArenaObjectSet[i];
}
}
}
return temp;
}
The GetRandomAvailableArenaObject() function (see Listing 10-8) gets a random arena object from
the set of arena objects by
Creating a random number generator called RandomNumber
1.
2.
Creating an array that will hold the indices of available arena objects to
choose from for our random selection
3.
Building a list of available arena objects and putting the indices into the
AvailableObjects array
4.
Finding a random arena object based on the output of the random number
generator and the list of available arena objects
5.
Returning an available object after setting the visibility and active status
to true
 
Search WWH ::




Custom Search