コード例 #1
0
    // Spawn platform
    private PlatformObject SpawnPlatform(int localIndex, Direction locationDirection, Vector3 position,
                                         Vector3 direction, bool activateImmediately)
    {
        PlatformObject platform     = (PlatformObject)ObjectPool.instance.GetObjectFromPool(localIndex, ObjectType.Platform);
        Quaternion     lookRotation = Quaternion.LookRotation(direction);

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

        int         objectIndex     = ObjectPool.instance.GetObjectIndexFromLocalIndex(localIndex, ObjectType.Platform);
        BasicObject prevTopPlatform = ObjectHistory.instance.ObjectSpawned(objectIndex, 0, locationDirection,
                                                                           lookRotation.eulerAngles.y, ObjectType.Platform, platform);

        // the current platform now becames the parent of the previous top platform
        if (prevTopPlatform != null)
        {
            prevTopPlatform.SetObjectParent(platform);
        }
        else
        {
            ObjectHistory.instance.SetBottomObject(locationDirection, IS_PLATFORM, platform);
        }
        ObjectHistory.instance.AddTotalDistance(platformSizes[localIndex].z, locationDirection, IS_PLATFORM, spawnData.section);

        return(platform);
    }
コード例 #2
0
    // spawn a scene object at the specified location
    private SceneObject SpawnScene(int localIndex, Direction locationDirection, Vector3 position,
                                   Vector3 direction, bool activateImmediately)
    {
        SceneObject scene        = (SceneObject)ObjectPool.instance.GetObjectFromPool(localIndex, ObjectType.Scene);
        Quaternion  lookRotation = Quaternion.LookRotation(direction);

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

        int         objectIndex  = ObjectPool.instance.GetObjectIndexFromLocalIndex(localIndex, ObjectType.Scene);
        BasicObject prevTopScene = ObjectHistory.instance.ObjectSpawned(objectIndex, 0, locationDirection,
                                                                        lookRotation.eulerAngles.y, ObjectType.Scene, scene);

        // the current scene now becames the parent of the previous top scene
        if (prevTopScene != null)
        {
            prevTopScene.SetObjectParent(scene);
        }
        else
        {
            ObjectHistory.instance.SetBottomObject(locationDirection, IS_SCENE, scene);
        }

        ObjectHistory.instance.AddTotalDistance(sceneSizes[localIndex].z, locationDirection, IS_SCENE, spawnData.section);
        if (scene.isForSectionTransition)
        {
            ObjectHistory.instance.DidSpawnSectionTransition(locationDirection, IS_SCENE);
        }

        return(scene);
    }
コード例 #3
0
    // The player has turned. Update the spawn direction to continue spawning objects
    public bool UpdateSpawnDirection(Vector3 newDirection, bool rightTurn,
                                     bool playerAboveTurn, out Vector3 turnOffset)
    {
        turnOffset    = Vector3.zero;
        moveDirection = newDirection;

        // Terminate if the player is not above turn. Stop spawning objects as the game is about to be over.
        if (!playerAboveTurn)
        {
            stopSpawning = true;
            return(false);
        }

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

        if ((rightTurn && Mathf.Abs(yAngle - ObjectHistory.instance.GetObjectDirectionAngle(Direction.Right)) < 0.01f) ||
            (!rightTurn && Mathf.Abs(yAngle - ObjectHistory.instance.GetObjectDirectionAngle(Direction.Left)) < 0.01f))
        {
            spawnDirection = newDirection;
            Direction turnDirection = (rightTurn ? Direction.Right : Direction.Left);
            turnPlatform[(int)Direction.Center]      = turnPlatform[(int)turnDirection];
            turnPlatform[(int)Direction.Right]       = turnPlatform[(int)Direction.Left] = null;
            platformTurnIndex[(int)Direction.Center] = platformTurnIndex[(int)turnDirection];
            turnScene[(int)Direction.Center]         = turnScene[(int)turnDirection];
            turnScene[(int)Direction.Right]          = turnScene[(int)Direction.Left] = null;
            sceneTurnIndex[(int)Direction.Center]    = sceneTurnIndex[(int)turnDirection];

            // 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)
            {
                Direction   direction      = turnDirection == Direction.Right ? Direction.Left : Direction.Right;
                BasicObject infiniteObject = ObjectHistory.instance.GetTopObject(direction, i == 0);
                // may be null if the turn only turns one direction
                if (infiniteObject != null)
                {
                    BasicObject centerObject = ObjectHistory.instance.GetBottomObject(Direction.Center, i == 0);
                    infiniteObject.SetObjectParent(centerObject);
                }
            }

            ObjectHistory.instance.Turn(turnDirection);
            if (turnPlatform[(int)Direction.Center] != null)
            {
                ObjectHistory.instance.ResetTurnCount();
            }

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

        return(false);
    }
コード例 #4
0
    // The player has turned. Replace the center values with the corresponding turn values if they are valid
    public void Turn(Direction direction)
    {
        for (int i = 0; i < objectSpawnIndex[(int)Direction.Center].Count; ++i)
        {
            lastObjectSpawnDistance[(int)Direction.Center][i] = lastObjectSpawnDistance[(int)direction][i];

            if (objectSpawnIndex[(int)direction][i] != -1)
            {
                objectSpawnIndex[(int)Direction.Center][i] = objectSpawnIndex[(int)direction][i];
            }
        }

        for (int i = 0; i < (int)ObjectType.Count; ++i)
        {
            if (objectTypeSpawnIndex[(int)direction][i] != -1)
            {
                objectTypeSpawnIndex[(int)Direction.Center][i] = objectTypeSpawnIndex[(int)direction][i];
            }

            lastLocalIndex[(int)Direction.Center][i] = lastLocalIndex[(int)direction][i];
            lastObjectTypeSpawnDistance[(int)Direction.Center][i] = lastObjectTypeSpawnDistance[(int)direction][i];
        }

        totalDistance[(int)Direction.Center]        = totalDistance[(int)direction];
        totalSceneDistance[(int)Direction.Center]   = totalSceneDistance[(int)direction];
        objectDirectionAngle[(int)Direction.Center] = objectDirectionAngle[(int)direction];
        platformDistanceDataMap[(int)Direction.Center].CopyFrom(platformDistanceDataMap[(int)direction]);

        previousPlatformSection[(int)Direction.Center]          = previousPlatformSection[(int)direction];
        previousSceneSection[(int)Direction.Center]             = previousSceneSection[(int)direction];
        spawnedPlatformSectionTransition[(int)Direction.Center] = spawnedPlatformSectionTransition[(int)direction];
        spawnedSceneSectionTransition[(int)Direction.Center]    = spawnedSceneSectionTransition[(int)direction];

        // Use the center direction if there aren't any objects in the direction across from the turn direction
        Direction acrossDirection = (direction == Direction.Right ? Direction.Left : Direction.Right);

        if (bottomPlatformObjectSpawned[(int)acrossDirection] == null)
        {
            acrossDirection = Direction.Center;
        }

        if (topTurnPlatformObjectSpawned != null)
        {
            topTurnPlatformObjectSpawned.SetObjectParent(topPlatformObjectSpawned[(int)Direction.Center]);
        }
        else
        {
            bottomTurnPlatformObjectSpawned = bottomPlatformObjectSpawned[(int)acrossDirection];
        }
        topTurnPlatformObjectSpawned = topPlatformObjectSpawned[(int)Direction.Center];

        if (topTurnSceneObjectSpawned != null)
        {
            topTurnSceneObjectSpawned.SetObjectParent(topSceneObjectSpawned[(int)Direction.Center]);
        }
        else
        {
            bottomTurnSceneObjectSpawned = bottomSceneObjectSpawned[(int)acrossDirection];
        }
        topTurnSceneObjectSpawned = topSceneObjectSpawned[(int)Direction.Center];

        topPlatformObjectSpawned[(int)Direction.Center]    = topPlatformObjectSpawned[(int)direction];
        bottomPlatformObjectSpawned[(int)Direction.Center] = bottomPlatformObjectSpawned[(int)direction];
        topSceneObjectSpawned[(int)Direction.Center]       = topSceneObjectSpawned[(int)direction];
        bottomSceneObjectSpawned[(int)Direction.Center]    = bottomSceneObjectSpawned[(int)direction];
        for (int i = (int)Direction.Left; i < (int)Direction.Count; i += 2)
        {
            topPlatformObjectSpawned[i]    = null;
            bottomPlatformObjectSpawned[i] = null;
            topSceneObjectSpawned[i]       = null;
            bottomSceneObjectSpawned[i]    = null;
        }
    }