コード例 #1
0
        // spawn a scene object at the specified location
        private SceneObject SpawnSceneObject(int localIndex, ObjectLocation location, Vector3 position, Vector3 direction, bool activateImmediately)
        {
            SceneObject scene        = (SceneObject)infiniteObjectManager.ObjectFromPool(localIndex, ObjectType.Scene);
            Quaternion  lookRotation = Quaternion.LookRotation(direction);

            scene.Orient(position + direction * sceneSizes[localIndex].z / 2, lookRotation);
            if (activateImmediately)
            {
                scene.Activate();
            }

            int            objectIndex  = infiniteObjectManager.LocalIndexToObjectIndex(localIndex, ObjectType.Scene);
            InfiniteObject prevTopScene = infiniteObjectHistory.ObjectSpawned(objectIndex, 0, location, lookRotation.eulerAngles.y, ObjectType.Scene, scene);

            // the current scene now becames the parent of the previous top scene
            if (prevTopScene != null)
            {
                prevTopScene.SetInfiniteObjectParent(scene);
            }
            else
            {
                infiniteObjectHistory.SetBottomInfiniteObject(location, true, scene);
            }

            infiniteObjectHistory.AddTotalDistance(sceneSizes[localIndex].z, location, true, spawnData.section);
            if (scene.sectionTransition)
            {
                infiniteObjectHistory.DidSpawnSectionTranition(location, true);
            }

            return(scene);
        }
コード例 #2
0
        // returns the length of the created platform
        private PlatformObject SpawnPlatform(int localIndex, ObjectLocation location, Vector3 position, Vector3 direction, bool activateImmediately)
        {
            PlatformObject platform     = (PlatformObject)infiniteObjectManager.ObjectFromPool(localIndex, ObjectType.Platform);
            Quaternion     lookRotation = Quaternion.LookRotation(direction);

            platform.Orient(position + (direction * platformSizes[localIndex].z / 2), lookRotation);
            if (activateImmediately)
            {
                platform.Activate();
            }

            int            objectIndex     = infiniteObjectManager.LocalIndexToObjectIndex(localIndex, ObjectType.Platform);
            InfiniteObject prevTopPlatform = infiniteObjectHistory.ObjectSpawned(objectIndex, 0, location, lookRotation.eulerAngles.y, ObjectType.Platform, platform);

            // the current platform now becames the parent of the previous top platform
            if (prevTopPlatform != null)
            {
                prevTopPlatform.SetInfiniteObjectParent(platform);
            }
            else
            {
                infiniteObjectHistory.SetBottomInfiniteObject(location, false, platform);
            }
            infiniteObjectHistory.AddTotalDistance(platformSizes[localIndex].z, location, false, spawnData.section);

            return(platform);
        }
コード例 #3
0
        // the player hit a turn, start generating new objects
        public bool UpdateSpawnDirection(Vector3 newDirection, bool setMoveDirection, bool rightTurn, bool playerAboveTurn, out Vector3 turnOffset)
        {
            turnOffset = Vector3.zero;
            // Don't set the move direction above a curve because the cuve will set the direction
            if (setMoveDirection)
            {
                moveDirection = newDirection;
            }

            // don't change spawn directions if the player isn't above a turn. The game is about to be over anyway so there isn't a reason to keep generating objects
            if (!playerAboveTurn)
            {
                stopObjectSpawns = true;
                return(false);
            }

            float yAngle = Quaternion.LookRotation(newDirection).eulerAngles.y;

            if ((rightTurn && Mathf.Abs(yAngle - infiniteObjectHistory.GetObjectLocationAngle(ObjectLocation.Right)) < 0.01f) ||
                (!rightTurn && Mathf.Abs(yAngle - infiniteObjectHistory.GetObjectLocationAngle(ObjectLocation.Left)) < 0.01f))
            {
                spawnDirection    = newDirection;
                wrongMoveDistance = 0;
                ObjectLocation turnLocation = (rightTurn ? ObjectLocation.Right : ObjectLocation.Left);
                turnPlatform[(int)ObjectLocation.Center]   = turnPlatform[(int)turnLocation];
                turnPlatform[(int)ObjectLocation.Right]    = turnPlatform[(int)ObjectLocation.Left] = null;
                turnIndex[(int)ObjectLocation.Center]      = turnIndex[(int)turnLocation];
                turnScene[(int)ObjectLocation.Center]      = turnScene[(int)turnLocation];
                turnScene[(int)ObjectLocation.Right]       = turnScene[(int)ObjectLocation.Left] = null;
                sceneTurnIndex[(int)ObjectLocation.Center] = sceneTurnIndex[(int)turnLocation];

                // The center objects and the objects in the location opposite of turn are grouped together with the center object being the top most object
                for (int i = 0; i < 2; ++i)
                {
                    InfiniteObject infiniteObject = infiniteObjectHistory.GetTopInfiniteObject((turnLocation == ObjectLocation.Right ? ObjectLocation.Left : ObjectLocation.Right), i == 0);
                    // may be null if the turn only turns one direction
                    if (infiniteObject != null)
                    {
                        InfiniteObject centerObject = infiniteObjectHistory.GetBottomInfiniteObject(ObjectLocation.Center, i == 0);
                        infiniteObject.SetInfiniteObjectParent(centerObject);
                    }
                }

                infiniteObjectHistory.Turn(turnLocation);
                if (turnPlatform[(int)ObjectLocation.Center] != null)
                {
                    infiniteObjectHistory.ResetTurnCount();
                }

                turnOffset = GetTurnOffset();
                return(true);
            }

            // Set the move direction even if the turn is a curve so the infinite objects will move in the opposite direciton of the player
            moveDirection = newDirection;
            return(false);
        }
コード例 #4
0
        // set everything back to 0 for a new game
        public void SaveObjectsReset()
        {
            // save off the current objects. They will be deactivated after new objects have been sapwned
            if (topPlatformObjectSpawned[(int)ObjectLocation.Center] != null)
            {
                savedInfiniteObjects = topPlatformObjectSpawned[(int)ObjectLocation.Center];

                for (int i = 0; i < (int)ObjectLocation.Last; ++i)
                {
                    if (i != (int)ObjectLocation.Center && topPlatformObjectSpawned[i])
                    {
                        topPlatformObjectSpawned[i].SetInfiniteObjectParent(savedInfiniteObjects);
                    }
                    if (bottomPlatformObjectSpawned[i] != null)
                    {
                        bottomPlatformObjectSpawned[i].SetInfiniteObjectParent(savedInfiniteObjects);
                    }
                    if (topSceneObjectSpawned[i] != null)
                    {
                        topSceneObjectSpawned[i].SetInfiniteObjectParent(savedInfiniteObjects);
                    }
                    if (bottomSceneObjectSpawned[i] != null)
                    {
                        bottomSceneObjectSpawned[i].SetInfiniteObjectParent(savedInfiniteObjects);
                    }

                    if (topTurnPlatformObjectSpawned != null)
                    {
                        topTurnPlatformObjectSpawned.SetInfiniteObjectParent(savedInfiniteObjects);
                    }
                }
            }
            else
            {
                // topPlatformObjectSpawned is null when the player turns the wrong way off of a turn
                savedInfiniteObjects = topTurnPlatformObjectSpawned;
            }

            if (bottomTurnPlatformObjectSpawned != null)
            {
                bottomTurnPlatformObjectSpawned.SetInfiniteObjectParent(savedInfiniteObjects);
            }
            if (topTurnSceneObjectSpawned != null)
            {
                topTurnSceneObjectSpawned.SetInfiniteObjectParent(savedInfiniteObjects);
            }
            if (bottomTurnSceneObjectSpawned != null)
            {
                bottomTurnSceneObjectSpawned.SetInfiniteObjectParent(savedInfiniteObjects);
            }

            activeObjectLocation = ObjectLocation.Center;
            for (int i = 0; i < (int)ObjectLocation.Last; ++i)
            {
                totalDistance[i]      = 0;
                totalSceneDistance[i] = 0;
                platformDistanceDataMap[i].ResetValues();
                objectLocationAngle[i] = 0;

                topPlatformObjectSpawned[i] = bottomPlatformObjectSpawned[i] = null;
                topSceneObjectSpawned[i]    = bottomSceneObjectSpawned[i] = null;

                previousPlatformSection[i]          = 0;
                previousSceneSection[i]             = 0;
                spawnedSceneSectionTransition[i]    = false;
                spawnedPlatformSectionTransition[i] = false;

                for (int j = 0; j < objectSpawnIndex[i].Count; ++j)
                {
                    objectSpawnIndex[i][j]        = -1;
                    lastObjectSpawnDistance[i][j] = 0;
                }
                for (int j = 0; j < (int)ObjectType.Last; ++j)
                {
                    objectTypeSpawnIndex[i][j]          = -1;
                    lastLocalIndex[i][j]                = -1;
                    latestObjectTypeSpawnDistance[i][j] = -1;
                }
            }

            topTurnPlatformObjectSpawned = bottomTurnPlatformObjectSpawned = null;
            topTurnSceneObjectSpawned    = bottomTurnSceneObjectSpawned = null;
        }
コード例 #5
0
        // the player has turned. Replace the center values with the corresponding turn values if they aren't -1
        public void Turn(ObjectLocation location)
        {
            for (int i = 0; i < objectSpawnIndex[(int)ObjectLocation.Center].Count; ++i)
            {
                lastObjectSpawnDistance[(int)ObjectLocation.Center][i] = lastObjectSpawnDistance[(int)location][i];
                if (objectSpawnIndex[(int)location][i] != -1)
                {
                    objectSpawnIndex[(int)ObjectLocation.Center][i] = objectSpawnIndex[(int)location][i];
                }
            }

            for (int i = 0; i < (int)ObjectLocation.Last; ++i)
            {
                if (objectTypeSpawnIndex[(int)location][i] != -1)
                {
                    objectTypeSpawnIndex[(int)ObjectLocation.Center][i] = objectTypeSpawnIndex[(int)location][i];
                }

                lastLocalIndex[(int)ObjectLocation.Center][i] = lastLocalIndex[(int)location][i];
                latestObjectTypeSpawnDistance[(int)ObjectLocation.Center][i] = latestObjectTypeSpawnDistance[(int)location][i];
            }

            totalDistance[(int)ObjectLocation.Center]       = totalDistance[(int)location];
            totalSceneDistance[(int)ObjectLocation.Center]  = totalSceneDistance[(int)location];
            objectLocationAngle[(int)ObjectLocation.Center] = objectLocationAngle[(int)location];

            platformDistanceDataMap[(int)ObjectLocation.Center].CopyFrom(platformDistanceDataMap[(int)location]);

            previousPlatformSection[(int)ObjectLocation.Center]          = previousPlatformSection[(int)location];
            previousSceneSection[(int)ObjectLocation.Center]             = previousSceneSection[(int)location];
            spawnedPlatformSectionTransition[(int)ObjectLocation.Center] = spawnedPlatformSectionTransition[(int)location];
            spawnedSceneSectionTransition[(int)ObjectLocation.Center]    = spawnedSceneSectionTransition[(int)location];

            // use the center location if there aren't any objects in the location across from the turn location
            ObjectLocation acrossLocation = (location == ObjectLocation.Right ? ObjectLocation.Left : ObjectLocation.Right);

            if (bottomPlatformObjectSpawned[(int)acrossLocation] == null)
            {
                acrossLocation = ObjectLocation.Center;
            }

            if (topTurnPlatformObjectSpawned != null)
            {
                topTurnPlatformObjectSpawned.SetInfiniteObjectParent(topPlatformObjectSpawned[(int)ObjectLocation.Center]);
            }
            else
            {
                bottomTurnPlatformObjectSpawned = bottomPlatformObjectSpawned[(int)acrossLocation];
            }
            topTurnPlatformObjectSpawned = topPlatformObjectSpawned[(int)ObjectLocation.Center];
            if (topTurnSceneObjectSpawned != null)
            {
                topTurnSceneObjectSpawned.SetInfiniteObjectParent(topSceneObjectSpawned[(int)ObjectLocation.Center]);
            }
            else
            {
                bottomTurnSceneObjectSpawned = bottomSceneObjectSpawned[(int)acrossLocation];
            }
            topTurnSceneObjectSpawned = topSceneObjectSpawned[(int)ObjectLocation.Center];

            topPlatformObjectSpawned[(int)ObjectLocation.Center]    = topPlatformObjectSpawned[(int)location];
            bottomPlatformObjectSpawned[(int)ObjectLocation.Center] = bottomPlatformObjectSpawned[(int)location];
            topSceneObjectSpawned[(int)ObjectLocation.Center]       = topSceneObjectSpawned[(int)location];
            bottomSceneObjectSpawned[(int)ObjectLocation.Center]    = bottomSceneObjectSpawned[(int)location];

            for (int i = (int)ObjectLocation.Left; i < (int)ObjectLocation.Last; ++i)
            {
                topPlatformObjectSpawned[i]    = null;
                bottomPlatformObjectSpawned[i] = null;
                topSceneObjectSpawned[i]       = null;
                bottomSceneObjectSpawned[i]    = null;
            }
        }