Esempio n. 1
0
    /* Selects a level information at random from the avaiable levels
     * and generates its corresponding objects on the Scene*/
    public void LoadLevelLayout()
    {
        //////////////////////////////////Random level selection goes here
        //currentSpeed = speedValues[(int) gameSpeedSetting]; //Sets Spped
        if (currentGameMode == GameMode.Debug)
        {
            HeaderLevelDetails.instance.FillDetails(levelSelected);
        }
        difficultySetting = levelSelected.difficulty;
        gameSpeedSetting  = levelSelected.gameSpeed;
        currentSpeed      = speedValues[(int)levelSelected.gameSpeed];
        float platformXLimit = platformsOrigin.x + (platformXOffset * 3); //Sets the spaces between rows an columns
        float platformZLimit = platformsOrigin.z + (platformZOffset * 3);
        int   i = 0;                                                      //keeps count of the object's index from the selected level

        /*This loop increments the value from the initial position on an interval equal to the
         * spaces between each platform to instantiate them in the correct position*/

        for (float row = platformsOrigin.x; row <= platformXLimit; row += platformXOffset)
        {
            for (float column = platformsOrigin.z; column <= platformZLimit; column += platformZOffset)
            {
                platformPositions[i] = new Vector3(row, platformsOrigin.y, column);


                /*The Manager creates a platform based on the platform types's enum value,
                 * interpreting it as an index from its array of platforms*/

                GameObject g = Instantiate(platformPool[(int)levelSelected.GetPlatformType(i)],
                                           new Vector3(row, platformsOrigin.y, column), Quaternion.identity);
                g.transform.localScale = platformsScale;

                //NOTE: Add Object Attached (make g a parent of said object if aplicable)

                //Set the corresponding properties of the platform specified in the config file
                if (levelSelected.GetPlatformType(i) == PlatformType.DirectionChanger)
                {
                    g.GetComponent <DirectionChangerPlatform>().SetSettings(levelSelected.GetPlatformSettings(i));
                }

                //Add the Moving Platform's properties to the created platform if aplicable
                if (levelSelected.GetPlatformSettings(i).IsThePlatformMovable())
                {
                    g.AddComponent <MovingPlatform>().SetSettings(levelSelected.GetPlatformSettings(i));
                }
                g.transform.parent = stage.transform;
                platformReferences.Add(g);
                i++;
            }
        }
    }