Game Development Reference
In-Depth Information
Listing 10-8. Getting a Random Arena Object
ArenaObject3d GetRandomAvailableArenaObject()
{
ArenaObject3d Obj = null;
Random RandomNumber = new Random();
int RandomIndex = 0;
int AvailableObjectsIndex = 0;
int[] AvailableObjects = new int[MAX_ARENA_OBJECTS];
// Build list of available objects
for (int i = 0; i < MAX_ARENA_OBJECTS; i++)
{
if (m_ArenaObjectSet[i] != null)
{
if (m_Active[i] == false)
{
AvailableObjects[AvailableObjectsIndex] = i;
AvailableObjectsIndex++;
}
}
}
// If there are Available Objects then choose one at random from the list of available objects
if (AvailableObjectsIndex > 0)
{
// Find Random Object from array of available objects
RandomIndex = RandomNumber.nextInt(AvailableObjectsIndex);
int ObjIndex = AvailableObjects[RandomIndex];
Obj = GetArenaObject(ObjIndex);
if (Obj != null)
{
Obj.SetVisibility(true);
m_Active[ObjIndex] = true;
}
else
{
Log.e("ARENAOBJECTSSET", "Random Arena OBJECT = NULL ERROR!!!! ");
}
}
return Obj;
}
 
Search WWH ::




Custom Search