// distance is the scene distance public override bool canSpawnObject(float distance, ObjectSpawnData spawnData) { if (!base.canSpawnObject(distance, spawnData)) { return(false); } // If section transition is true a transition object must be found if (spawnData.sectionTransition) { if (platformObject.sectionTransition) { // any transition is a section transition if there are no specific section transitions defined if (platformObject.fromSection.Count == 0) { return(true); } // return true if the from section equals the previous section and matches up with the to section which equals the current section // fromSection and toSection must be equal in size for (int i = 0; i < platformObject.fromSection.Count; ++i) { if (platformObject.fromSection[i] == spawnData.prevSection && platformObject.toSection[i] == spawnData.section) { return(true); } } } return(false); } return(!platformObject.sectionTransition); }
// distance is the scene distance public override bool canSpawnObject(float distance, ObjectSpawnData spawnData) { if (!base.canSpawnObject(distance, spawnData)) return false; // If section transition is true a transition object must be found if (spawnData.sectionTransition) { if (platformObject.sectionTransition) { // any transition is a section transition if there are no specific section transitions defined if (platformObject.fromSection.Count == 0) { return true; } // return true if the from section equals the previous section and matches up with the to section which equals the current section // fromSection and toSection must be equal in size for (int i = 0; i < platformObject.fromSection.Count; ++i) { if (platformObject.fromSection[i] == spawnData.prevSection && platformObject.toSection[i] == spawnData.section) { return true; } } } return false; } return !platformObject.sectionTransition; }
public void Start() { cameraTransform = Camera.main.transform; infiniteObjectManager = InfiniteObjectManager.instance; infiniteObjectManager.init(); infiniteObjectHistory = InfiniteObjectHistory.instance; infiniteObjectHistory.init(infiniteObjectManager.getTotalObjectCount()); sectionSelection = SectionSelection.instance; moveDirection = Vector3.forward; turnOffset = Vector3.zero; turnPlatform = new PlatformObject[(int)ObjectLocation.Last]; localDistance = new float[(int)ObjectLocation.Last]; localSceneDistance = new float[(int)ObjectLocation.Last]; localPlatformHeight = new float[(int)ObjectLocation.Last]; localSceneHeight = new float[(int)ObjectLocation.Last]; infiniteObjectManager.getObjectSizes(out platformSizes, out sceneSizes, out straightPlatformWidth, out largestSceneLength); stopObjectSpawns = false; spawnData = new ObjectSpawnData(); spawnData.largestScene = largestSceneLength; spawnData.useWidthBuffer = true; spawnData.section = 0; spawnData.sectionTransition = false; noCollidableProbability.init(); showStartupObjects(false); spawnObjectRun(true); }
public void Start() { dataManager = DataManager.instance; infiniteObjectManager = InfiniteObjectManager.instance; infiniteObjectManager.init(); infiniteObjectHistory = InfiniteObjectHistory.instance; infiniteObjectHistory.init(infiniteObjectManager.getTotalObjectCount()); sectionSelection = SectionSelection.instance; chaseController = ChaseController.instance; moveDirection = Vector3.forward; spawnDirection = Vector3.forward; turnPlatform = new PlatformObject[(int)ObjectLocation.Last]; infiniteObjectManager.getObjectSizes(out platformSizes, out sceneSizes, out largestSceneLength); infiniteObjectManager.getObjectStartPositions(out platformStartPosition, out sceneStartPosition); stopObjectSpawns = false; spawnData = new ObjectSpawnData(); spawnData.largestScene = largestSceneLength; spawnData.useWidthBuffer = true; spawnData.section = 0; spawnData.sectionTransition = false; noCollidableProbability.init(); showStartupObjects(GameManager.instance.showTutorial); spawnObjectRun(true); }
// Initialize for instances public void Start() { ObjectPool.instance.Init(); ObjectHistory.instance.Init(ObjectPool.instance.GetTotalObjectCount()); moveDirection = Vector3.forward; spawnDirection = Vector3.forward; turnPlatform = new PlatformObject[(int)Direction.Count]; platformTurnIndex = new int[(int)Direction.Count]; turnScene = new SceneObject[(int)Direction.Count]; sceneTurnIndex = new int[(int)Direction.Count]; ObjectPool.instance.GetObjectSizes(out platformSizes, out sceneSizes, out largestSceneLength); ObjectPool.instance.GetObjectStartPositions(out platformStartPositions, out sceneStartPositions); stopSpawning = false; spawnData = new ObjectSpawnData(); spawnData.largestScene = largestSceneLength; spawnData.useWidthBuffer = true; spawnData.section = 0; spawnData.sectionTransition = false; this.SpawnObjects(true); GameController.instance.OnStartGame += StartGame; }
public override bool canSpawnObject(float distance, ObjectSpawnData spawnData) { if (dataManager.getPowerUpLevel(powerUpType) == 0) return false; if (!base.canSpawnObject(distance, spawnData)) return false; return true; }
// Override to add additional restriction public override bool CanSpawnObject(float distance, ObjectSpawnData spawnData) { if (!base.CanSpawnObject(distance, spawnData)) { return(false); } int platformLocalIndex = ObjectHistory.instance.GetFirstPlatformIndex(); if (platformLocalIndex == -1) { return(false); } // Get the platform that this scene is going to spawn next to. // See if the platform requires linked scenes and if it does, if this scene fulfills that requirement. PlatformObject platform = ObjectPool.instance.GetObjectFromLocalIndex(platformLocalIndex, ObjectType.Platform) as PlatformObject; if (platform.HasLinkedScenes()) { for (int i = 0; i < linkedPlatforms.Count; ++i) { if (linkedPlatforms[i].CanSpawnObject(platformLocalIndex)) { return(true); } } return(false); } else if (linkedPlatforms.Count > 0) // return false if this scene is linked to a platform but the platform doesn't have any linked scenes { return(false); } // if the platform can't fit, then don't spawn it float totalDistance = ObjectHistory.instance.GetTotalDistance(false); float largestScene = spawnData.largestScene; float sceneBuffer = (spawnData.useWidthBuffer ? platformSceneWidthBuffer : 0); // useWidthBuffer contains the information if we should spawn up to totalDistance if (totalDistance - distance - sceneBuffer - largestScene >= 0) { // largest scene of 0 means we are approaching a turn and it doesn't matter what size object is spawned as long as it fits if (largestScene == 0) { return(totalDistance - distance - sceneBuffer >= zSize); } else { return(largestScene >= zSize); } } return(false); }
public override bool canSpawnObject(float distance, ObjectSpawnData spawnData) { if (!base.canSpawnObject(distance, spawnData)) return false; for (int i = 0; i < avoidPlatforms.Count; ++i) { if (!avoidPlatforms[i].canSpawnObject(infiniteObjectHistory.getLastLocalIndex(ObjectType.Platform))) return false; } // may not be able to spawn if the slots don't line up return (spawnData.slotPositions & ((thisInfiniteObject as CollidableObject).getSlotPositionsMask())) != 0; }
public override bool canSpawnObject(float distance, ObjectSpawnData spawnData) { if (dataManager.getPowerUpLevel(powerUpType) == 0) { return(false); } if (!base.canSpawnObject(distance, spawnData)) { return(false); } return(true); }
public override bool canSpawnObject(float distance, ObjectSpawnData spawnData) { if (!base.canSpawnObject(distance, spawnData)) { return(false); } for (int i = 0; i < avoidPlatforms.Count; ++i) { if (!avoidPlatforms[i].canSpawnObject(infiniteObjectHistory.getLastLocalIndex(ObjectType.Platform))) { return(false); } } return(true); }
// Objects may not be able to be spawned if they are too close to another object, for example public virtual bool canSpawnObject(float distance, ObjectSpawnData spawnData) { // can't spawn if the sections don't match up if (!infiniteObject.canSpawnInSection(spawnData.section)) { return(false); } for (int i = 0; i < avoidObjectRuleMaps.Count; ++i) { if (!avoidObjectRuleMaps[i].canSpawnObject(distance)) { return(false); // all it takes is one } } return(true); }
// Check if the object is able to be spawned public virtual bool CanSpawnObject(float distance, ObjectSpawnData spawnData) { // Cannot spawn if the object is unable to spawn in the given ection if (!thisObject.CanSpawnInSection(spawnData.section)) { return(false); } // Rules check for (int i = 0; i < avoidObjectRuleMaps.Count; ++i) { if (!avoidObjectRuleMaps[i].CanSpawnObject(distance)) { return(false); } } return(true); }
public override bool CanSpawnObject(float distance, ObjectSpawnData spawnData) { if (!base.CanSpawnObject(distance, spawnData)) { return(false); } for (int i = 0; i < avoidPlatforms.Count; ++i) { if (!avoidPlatforms[i].CanSpawnObject(ObjectHistory.instance.GetLastLocalIndex(ObjectType.Platform))) { return(false); } } // may not be able to spawn if the slots don't line up return((spawnData.slotPositions & ((thisObject as CollidableObject).GetSlotPositionsMask())) != 0); }
public override bool CanSpawnObject(float distance, ObjectSpawnData spawnData) { if (!base.CanSpawnObject(distance, spawnData)) { return(false); } // If section transition is true a transition object must be found if (spawnData.sectionTransition) { if (platformObject.isForSectionTransition) { // any transition is a section transition if there are no specific section transitions defined if (platformObject.fromSection.Count == 0) { return(true); } // return true if the from section equals the previous section and matches up with the to section which equals the current section // fromSection and toSection must be equal in size for (int i = 0; i < platformObject.fromSection.Count; ++i) { if (platformObject.fromSection[i] == spawnData.prevSection && platformObject.toSection[i] == spawnData.section) { return(true); } } } return(false); } // Prevent multiple turns from spawning within the same object location. if (spawnData.turnSpawned && (platformObject.isLeftTurn || platformObject.isRightTurn)) { return(false); } return(!platformObject.isForSectionTransition); }
/** * The next platform is determined by probabilities as well as object rules. * spawnData contains any extra data that is needed to make a decision if the object can be spawned */ public int getNextObjectIndex(ObjectType objectType, ObjectSpawnData spawnData) { InfiniteObject[] objects = null; switch(objectType) { case ObjectType.Platform: objects = platforms; break; case ObjectType.Scene: objects = scenes; break; case ObjectType.Obstacle: objects = obstacles; break; case ObjectType.Coin: objects = coins; break; case ObjectType.PowerUp: objects = powerUps; break; } float totalProbability = 0; float distance = infiniteObjectHistory.getTotalDistance(objectType == ObjectType.Scene); int objectIndex; for (int localIndex = 0; localIndex < objects.Length; ++localIndex) { objectIndex = localIndexToObjectIndex(localIndex, objectType); // cache the result objectCanSpawnCache[objectIndex] = appearanceRules[objectIndex].canSpawnObject(distance, spawnData); if (!objectCanSpawnCache[objectIndex]) { continue; } probabilityCache[objectIndex] = appearanceProbability[objectIndex].getProbability(distance) * appearanceRules[objectIndex].probabilityAdjustment(distance); totalProbability += probabilityCache[objectIndex]; } // chance of spawning nothing (especially in the case of collidable objects) if (totalProbability == 0) { return -1; } float randomValue = Random.value; float prevObjProbability = 0; float objProbability = 0; // with the total probability we can determine a platform // minor optimization: don't check the last platform. If we get that far into the loop then regardless we are selecting that platform for (int localIndex = 0; localIndex < objects.Length - 1; ++localIndex) { objectIndex = localIndexToObjectIndex(localIndex, objectType); if (!objectCanSpawnCache[objectIndex]) { continue; } objProbability = probabilityCache[objectIndex]; if (randomValue <= (prevObjProbability + objProbability) / totalProbability) { return localIndex; } prevObjProbability += objProbability; } return objects.Length - 1; }
/** * The next platform is determined by probabilities as well as object rules. * spawnData contains any extra data that is needed to make a decision if the object can be spawned */ public int getNextObjectIndex(ObjectType objectType, ObjectSpawnData spawnData) { InfiniteObject[] objects = null; switch (objectType) { case ObjectType.Platform: objects = platforms; break; case ObjectType.Scene: objects = scenes; break; case ObjectType.Obstacle: objects = obstacles; break; case ObjectType.Coin: objects = coins; break; case ObjectType.PowerUp: objects = powerUps; break; } float totalProbability = 0; float distance = infiniteObjectHistory.getTotalDistance(objectType == ObjectType.Scene); int objectIndex; for (int localIndex = 0; localIndex < objects.Length; ++localIndex) { objectIndex = localIndexToObjectIndex(localIndex, objectType); // cache the result objectCanSpawnCache[objectIndex] = appearanceRules[objectIndex].canSpawnObject(distance, spawnData); if (!objectCanSpawnCache[objectIndex]) { continue; } probabilityCache[objectIndex] = appearanceProbability[objectIndex].getProbability(distance) * appearanceRules[objectIndex].probabilityAdjustment(distance); totalProbability += probabilityCache[objectIndex]; } // chance of spawning nothing (especially in the case of collidable objects) if (totalProbability == 0) { return(-1); } float randomValue = Random.value; float prevObjProbability = 0; float objProbability = 0; // with the total probability we can determine a platform // minor optimization: don't check the last platform. If we get that far into the loop then regardless we are selecting that platform for (int localIndex = 0; localIndex < objects.Length - 1; ++localIndex) { objectIndex = localIndexToObjectIndex(localIndex, objectType); if (!objectCanSpawnCache[objectIndex]) { continue; } objProbability = probabilityCache[objectIndex]; if (randomValue <= (prevObjProbability + objProbability) / totalProbability) { return(localIndex); } prevObjProbability += objProbability; } return(objects.Length - 1); }
// Get the index of the next object from given object type public int GetNextObjectIndex(ObjectType objectType, ObjectSpawnData spawnData) { BasicObject[] objects = null; switch (objectType) { case ObjectType.Platform: objects = platforms; break; case ObjectType.Scene: objects = scenes; break; case ObjectType.Obstacle: objects = obstacles; break; case ObjectType.Donut: objects = donuts; break; case ObjectType.Fuel: objects = fuels; break; case ObjectType.PowerUp: objects = powerUps; break; } float totalProbability = 0; float distance = ObjectHistory.instance.GetTotalDistance(objectType == ObjectType.Scene); int objectIndex; for (int localIndex = 0; localIndex < objects.Length; ++localIndex) { objectIndex = GetObjectIndexFromLocalIndex(localIndex, objectType); // cache the result objectCanSpawnCache[objectIndex] = appearRules[objectIndex].CanSpawnObject(distance, spawnData); if (!objectCanSpawnCache[objectIndex]) { continue; } probabilityCache[objectIndex] = appearProbs[objectIndex].GetProbability(distance); totalProbability += probabilityCache[objectIndex]; } // chance of spawning nothing (especially in the case of collidable objects) if (totalProbability == 0) { return(-1); } // Use probability to decide which index should be returned float randomValue = Random.value; float prevObjProbability = 0; float objProbability = 0; for (int localIndex = 0; localIndex < objects.Length - 1; ++localIndex) { objectIndex = GetObjectIndexFromLocalIndex(localIndex, objectType); if (!objectCanSpawnCache[objectIndex]) { continue; } objProbability = probabilityCache[objectIndex]; if (objProbability == float.MaxValue || randomValue <= (prevObjProbability + objProbability) / totalProbability) { return(localIndex); } prevObjProbability += objProbability; } return(objects.Length - 1); }
// Objects may not be able to be spawned if they are too close to another object, for example public virtual bool canSpawnObject(float distance, ObjectSpawnData spawnData) { // can't spawn if the sections don't match up if (!thisInfiniteObject.canSpawnInSection(spawnData.section)) { return false; } for (int i = 0; i < avoidObjectRuleMaps.Count; ++i) { if (!avoidObjectRuleMaps[i].canSpawnObject(distance)) return false; // all it takes is one } return true; }