示例#1
0
        // spawn the platforms, obstacles, power ups, and coins
        private PlatformObject SpawnObjects(ObjectLocation location, Vector3 position, Vector3 direction, bool activateImmediately)
        {
            SetupSection(location, false);
            spawnData.turnSpawned = turnPlatform[(int)location] != null;
            int localIndex = infiniteObjectManager.GetNextObjectIndex(ObjectType.Platform, spawnData);

            if (localIndex == -1)
            {
                print("Unable to spawn platform. No platforms can be spawned based on the probability rules at distance " +
                      infiniteObjectHistory.GetTotalDistance(false) + " within section " + spawnData.section + (spawnData.sectionTransition ? (" (Transitioning from section " + spawnData.prevSection + ")") : ""));
                return(null);
            }
            PlatformObject platform = SpawnPlatform(localIndex, location, position, direction, activateImmediately);

            if (platform.CanSpawnCollidable() && Random.value >= noCollidableProbability.GetValue(infiniteObjectHistory.GetTotalDistance(false)))
            {
                // First try to spawn an obstacle. If there is any space remaining on the platform, then try to spawn a coin.
                // If there is still some space remaing, try to spawn a powerup.
                // An extension of this would be to randomize the order of ObjectType, but this way works if the probabilities
                // are setup fairly
                SpawnCollidable(ObjectType.Obstacle, position, direction, location, platform, localIndex, activateImmediately);
                if (platform.CanSpawnCollidable())
                {
                    SpawnCollidable(ObjectType.Coin, position, direction, location, platform, localIndex, activateImmediately);
                    if (platform.CanSpawnCollidable())
                    {
                        SpawnCollidable(ObjectType.PowerUp, position, direction, location, platform, localIndex, activateImmediately);
                    }
                }
            }

            return(platform);
        }
示例#2
0
    // Spawn platforms and their attached collidables
    private PlatformObject SpawnPlatformAndCollidables(Direction locationDirection, Vector3 position,
                                                       Vector3 direction, bool activateImmediately)
    {
        SetupSection(locationDirection, false);
        spawnData.turnSpawned = turnPlatform[(int)locationDirection] != null;
        int localIndex = ObjectPool.instance.GetNextObjectIndex(ObjectType.Platform, spawnData);

        if (localIndex == -1)
        {
            return(null);
        }
        PlatformObject platform = SpawnPlatform(localIndex, locationDirection, position, direction, activateImmediately);

        if (platform.CanSpawnCollidable())
        {
            // First try to spawn an obstacle.
            // If there is any space remaining on the platform, then try to spawn a donut.
            // If there is any space remaining on the platform, then try to spawn a fuel.
            // If there is any space remaining on the platform, then try to spawn a powerup.
            SpawnCollidable(ObjectType.Obstacle, position, direction, locationDirection, platform, localIndex, activateImmediately);
            if (platform.CanSpawnCollidable())
            {
                SpawnCollidable(ObjectType.Donut, position, direction, locationDirection, platform, localIndex, activateImmediately);
                if (platform.CanSpawnCollidable())
                {
                    SpawnCollidable(ObjectType.Fuel, position, direction, locationDirection, platform, localIndex, activateImmediately);
                    if (platform.CanSpawnCollidable())
                    {
                        SpawnCollidable(ObjectType.PowerUp, position, direction, locationDirection, platform, localIndex, activateImmediately);
                    }
                }
            }
        }

        return(platform);
    }
示例#3
0
    // returns true if there is still space on the platform for a collidable object to spawn
    private void SpawnCollidable(ObjectType objectType, Vector3 position, Vector3 direction, Direction locationDirection,
                                 PlatformObject platform, int platformLocalIndex, bool activateImmediately)
    {
        int collidablePositions = platform.numCollidables;

        // can't do anything if the platform doesn't accept any collidable object spawns
        if (collidablePositions == 0)
        {
            return;
        }

        Vector3 offset = platformSizes[platformLocalIndex] * 0.1f;
        float   zDelta = platformSizes[platformLocalIndex].z * .8f / (1 + collidablePositions);

        for (int i = 0; i < collidablePositions; ++i)
        {
            if (platform.CanSpawnCollidable(i))
            {
                spawnData.slotPositions = platform.GetSlotsAvailable();
                int localIndex = ObjectPool.instance.GetNextObjectIndex(objectType, spawnData);
                if (localIndex != -1)
                {
                    CollidableObject collidable   = ObjectPool.instance.GetObjectFromPool(localIndex, objectType) as CollidableObject;
                    Quaternion       lookRotation = Quaternion.LookRotation(direction);
                    Vector3          spawnSlot    = collidable.GetSpawnSlot(platform.GetTransform().right *slotDistance, spawnData.slotPositions);
                    collidable.Orient(platform, position + (offset.z + ((i + 1) * zDelta)) * direction + spawnSlot, lookRotation);
                    if (activateImmediately)
                    {
                        collidable.Activate();
                    }

                    int objectIndex = ObjectPool.instance.GetObjectIndexFromLocalIndex(localIndex, objectType);
                    ObjectHistory.instance.ObjectSpawned(objectIndex, (offset.z + ((i + 1) * zDelta)), locationDirection,
                                                         lookRotation.eulerAngles.y, objectType);
                    platform.SpawnCollidable(i);

                    // don't allow any more of the same collidable type if we are forcing a different collidable
                    if (platform.hasDifferentCollidables)
                    {
                        break;
                    }
                }
            }
        }
        spawnData.slotPositions = 0;
    }