public bool canSpawnObject(float distance, ObjectType thisObjectType, int targetObjectIndex, ObjectType targetObjectType)
    {
        // return true if the parameters do not apply to the current distance
        if (!probability.withinDistance(distance))
        {
            return(true);
        }

        // The target object doesn't matter if we are using objects of the same object type
        float totalDistance = infiniteObjectHistory.getTotalDistance(thisObjectType == ObjectType.Scene);

        if (minDistanceSameObjectType)
        {
            // lastSpawnDistance: the distance of the last object spawned of the inputted object type
            float lastSpawnDistance = infiniteObjectHistory.getLastObjectTypeSpawnDistance(thisObjectType);
            if (totalDistance - lastSpawnDistance <= minDistance)
            {
                return(false);
            }
        }

        // The rest of the tests need the target object, so if there is no target object then we are done early
        if (targetObjectIndex == -1)
        {
            return(true);
        }

        // objectSpawnIndex: spawn index of the last object of the same type (for example, the last duck obstacle spawn index)
        int objectSpawnIndex = infiniteObjectHistory.getObjectSpawnIndex(targetObjectIndex);

        // can always spawn if the object hasn't been spawned before and it is within the probabilities
        if (objectSpawnIndex == -1)
        {
            return(true);
        }

        // latestSpawnIndex: spawn index of the latest object type
        int latestSpawnIndex = infiniteObjectHistory.getObjectTypeSpawnIndex(targetObjectType);

        // can't spawn if there isn't enough object separation
        if (latestSpawnIndex - objectSpawnIndex <= minObjectSeparation)
        {
            return(false);
        }

        // objectLastDistance: distance of the last spawned object of the same type
        float objectLastDistance = infiniteObjectHistory.getSpawnDistance(targetObjectIndex);

        // can't spawn if we are too close to another object
        if (totalDistance - objectLastDistance <= minDistance)
        {
            return(false);
        }

        // looks like we can spawn
        return(true);
    }
Example #2
0
    // The probability of this object occuring can be based on the previous objects spawned.
	public bool probabilityAdjustment(InfiniteObjectHistory infiniteObjectHistory, float distance, ref float localDistance, ref float probability)
	{
        if (targetObjectIndex == -1) {
            Debug.LogError("ObjectRuleMap:probabilityAdjustment error: target object doesn't exist. Ensure the target object has been added to the Infinite Object Manager.");
            return false;
        }
		for (int i = 0; i < rules.Count; ++i) {
            if ((probability = rules[i].probabilityAdjustment(distance, targetObjectIndex, targetObject.getObjectType())) != -1) {
                localDistance = infiniteObjectHistory.getTotalDistance(targetObjectIsScene) - infiniteObjectHistory.getSpawnDistance(targetObjectIndex);
				return true;
			}
		}
		return false;
	}
 // The probability of this object occuring can be based on the previous objects spawned.
 public bool probabilityAdjustment(InfiniteObjectHistory infiniteObjectHistory, float distance, ref float localDistance, ref float probability)
 {
     for (int i = 0; i < rules.Count; ++i)
     {
         if ((probability = rules[i].probabilityAdjustment(distance, targetObjectIndex, targetObject.getObjectType())) != -1)
         {
             localDistance = infiniteObjectHistory.getTotalDistance(targetObjectIsScene) - infiniteObjectHistory.getSpawnDistance(targetObjectIndex);
             return(true);
         }
     }
     return(false);
 }