Ejemplo n.º 1
0
        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];
            turnIndex      = new int[(int)ObjectLocation.Last];
            turnScene      = new SceneObject[(int)ObjectLocation.Last];
            sceneTurnIndex = new int[(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);

            GameManager.instance.OnStartGame += StartGame;
        }
Ejemplo n.º 2
0
        // 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;
            }

            // Prevent multiple turns from spawning within the same object location.
            if (spawnData.turnSpawned && (platformObject.leftTurn || platformObject.rightTurn)) {
                return false;
            }

            return !platformObject.sectionTransition;
        }
Ejemplo n.º 3
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;
        }
        // distance is the scene distance
        public override bool CanSpawnObject(float distance, ObjectSpawnData spawnData)
        {
            if (!base.CanSpawnObject(distance, spawnData))
            {
                return(false);
            }

            int platformLocalIndex = infiniteObjectHistory.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 = infiniteObjectManager.LocalIndexToInfiniteObject(platformLocalIndex, ObjectType.Platform) as PlatformObject;

            if (platform.LinkedSceneObjectRequired())
            {
                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 = infiniteObjectHistory.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;
        }
Ejemplo n.º 6
0
        // 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;
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        // 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);
        }
        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);
        }
Ejemplo n.º 10
0
        // distance is the scene distance
        public override bool CanSpawnObject(float distance, ObjectSpawnData spawnData)
        {
            if (!base.CanSpawnObject(distance, spawnData))
                return false;

            int platformLocalIndex = infiniteObjectHistory.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 = infiniteObjectManager.LocalIndexToInfiniteObject(platformLocalIndex, ObjectType.Platform) as PlatformObject;

            if (platform.LinkedSceneObjectRequired()) {
                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 = infiniteObjectHistory.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;
        }
        // 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);
            }

            // Prevent multiple turns from spawning within the same object location.
            if (spawnData.turnSpawned && (platformObject.leftTurn || platformObject.rightTurn))
            {
                return(false);
            }

            return(!platformObject.sectionTransition);
        }
Ejemplo n.º 12
0
        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];
            turnIndex = new int[(int)ObjectLocation.Last];
            turnScene = new SceneObject[(int)ObjectLocation.Last];
            sceneTurnIndex = new int[(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);

            GameManager.instance.OnStartGame += StartGame;
        }
Ejemplo n.º 13
0
        /**
         * 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 probabilityAdjustment = 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;
                }

                probabilityAdjustment = appearanceRules[objectIndex].ProbabilityAdjustment(distance);
                // If the probability adjustment has a value of the float's max value then spawn this object no matter hwat
                if (probabilityAdjustment == float.MaxValue) {
                    probabilityCache[objectIndex] = probabilityAdjustment;
                    totalProbability = float.MaxValue;
                    break;
                }

                probabilityCache[objectIndex] = appearanceProbability[objectIndex].GetProbability(distance) * probabilityAdjustment;
                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 (objProbability == float.MaxValue || 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 probabilityAdjustment = 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;
                }

                probabilityAdjustment = appearanceRules[objectIndex].ProbabilityAdjustment(distance);
                // If the probability adjustment has a value of the float's max value then spawn this object no matter hwat
                if (probabilityAdjustment == float.MaxValue)
                {
                    probabilityCache[objectIndex] = probabilityAdjustment;
                    totalProbability = float.MaxValue;
                    break;
                }

                probabilityCache[objectIndex] = appearanceProbability[objectIndex].GetProbability(distance) * probabilityAdjustment;
                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 (objProbability == float.MaxValue || randomValue <= (prevObjProbability + objProbability) / totalProbability)
                {
                    return(localIndex);
                }
                prevObjProbability += objProbability;
            }
            return(objects.Length - 1);
        }