Ejemplo n.º 1
0
    /// <summary>
    /// Use platform generator to populate this section.
    /// </summary>
    /// <param name="id">section group</param>
    /// <param name="attachPoint">Where the platforms attach to the rest of the level</param>
    public void InitializePlatforms(int id, Vector3 attachPoint)
    {
        ID          = id;
        leftAnchor  = attachPoint;
        lowestPoint = leftAnchor;
        int midPointIndex = platformsPerSection / 2;                                        // Cache it to save from recalculating in the for loop.


        generator.SetAnchorPoint(leftAnchor);
        generator.SetID(id);
        // randomly generate a safe static platform, assign the player spawn here.          Note: It really aught to be a static platform so the player doesn't fall off the level.
        GameObject newPlatform    = generator.GenerateRandomStaticPlatform();
        Platform   platformScript = newPlatform.GetComponent <Platform>();

        playerSpawn = platformScript.GetSpawnPoint();                                       // Set the spawn position of the player to the first platform in this section
        platformScript.hasSpawnedSomething = true;
        platforms.Add(newPlatform);                                                         // keep track of the platform in this section

        generator.followsSpawn = true;
        // randomly generate the other 'platformsPerSection', picking randomly from the different types of platforms.
        for (int i = 1; i < platformsPerSection; i++)
        {
            // Generate Random platform.
            newPlatform    = generator.GenerateRandomPlatform();
            platformScript = newPlatform.GetComponent <Platform>();
            platforms.Add(newPlatform);


            // set midpoint
            if (i == midPointIndex)
            {
                midpoint = newPlatform.transform.TransformPoint(platformScript.GetCenterPoint());
            }


            // set rightmost anchor
            rightAnchor = platformScript.transform.TransformPoint(platformScript.GetRightAnchor());

            // Generate Addition - Initialize Powerups / Collectibles / Enemies here
            if (platformScript.canSpawnAdd)
            {
                GameObject addition = generator.GenerateRandomAddition();
                if (addition != null)
                {
                    addition.transform.position = platformScript.GetSpawnPoint();
                    addition.transform.SetParent(newPlatform.transform);
                }
            }

            if (i == 1)
            {
                generator.followsSpawn = false;
            }
            if (rightAnchor.y < lowestPoint.y)
            {
                lowestPoint = rightAnchor;
            }
        }

        SpawnFloor();
    }