Beispiel #1
0
    // JRH v0.1.8
    /// <summary>
    /// Modifies a newly instantiated row using a specified code to add pits, obstacles and rewards
    /// </summary>
    /// <param name="row"></param>
    /// <param name="codeA"></param>
    /// <param name="codeB"></param>
    /// <param name="codeC"></param>
    void SetRow(ref PlatformRow row, char codeA, char codeB, char codeC)
    {
        char[] code = new char[3] {
            codeA, codeB, codeC
        };                                                    // JRH v0.1.8: Put the three codes into an array

        // JRH v0.1.8: Set functionality to PlatformRow / gameObject

        row.gameObject.name += row.transform.GetSiblingIndex();
        // JRH v0.1.8: Add the row's in-scene position relative to the other rows to the gameObject's name

        if (GameManager.Instance.PlatformManager.LastRow != null)
        {
            row.transform.position = new Vector3(0f, 0f, GameManager.Instance.PlatformManager.LastRow.transform.position.z - GameManager.Instance.LaneDistance);
        }
        // JRH v0.1.8: Move the new Row to one laneDistance unit behind the last row

        for (int i = 0; i < 3; i++)
        {
            row.Platforms[i].SetPlatform(code[i]);

            row.Platforms[i].SetCritical(true);

            if (ObstacleLibrary.DecipherCode(row.Platforms[i].Code, PlatformType.PIT))
            {
                row.Platforms[i].SetPit();
            }
            //if (DecipherCode(row.Platforms[i].Code, ItemType.OBS)) row.Platforms[i].SetObstacle(GenerateObstacle(row.Platforms[i]));
        }
    }
    protected override void AddRewards()
    {
        // JRH v0.2.5: Add a reward to a lane over each gap that is part of the critical path
        foreach (RowData data in rowCodes)
        {
            // JRH v0.2.5: Add a reward only if the index of the data indicates a row filled with pits
            if ((rowCodes.IndexOf(data) + 1) % xRowVal == 0)
            {
                List <int> lanes = new List <int>();

                // JRH v0.2.5: hoo boy this line's a doozy
                for (int i = 0; i < 3; i++)
                {
                    if (data.CritArray[i] && (!ObstacleLibrary.DecipherCode(rowCodes[rowCodes.IndexOf(data) - 1].CodeArray[i]) &&
                                              !ObstacleLibrary.DecipherCode(rowCodes[rowCodes.IndexOf(data) + 1].CodeArray[i])))
                    {
                        lanes.Add(i);
                    }
                }
                // JRH v0.2.5: If each platform is both on the critical path and the platforms both in front and behind it aren't pits or obstacles,
                // add it to the list of potential lanes we're putting a reward into

                int ran = Random.Range(0, lanes.Count);
                // JRH v0.2.5: Out of the rows specified above, choose a random one

                data.CodeArray[lanes[ran]] = char.ToUpper(data.CodeArray[lanes[ran]]);
                // JRH v0.2.5: Put a reward into that one
            }
        }
    }
Beispiel #3
0
    void Start()
    {
        useGUILayout = false;
        FindAllGridUnits();
        enemyL    = gameObject.GetComponent <EnemyLibrary>();
        obstacleL = gameObject.GetComponent <ObstacleLibrary>();

        //S.GameControlInst.= GameObject.FindGameObjectWithTag ("GameController").GetComponent<GameControl> ();
    }
Beispiel #4
0
 public static void Initialize(GameControl gc, Player pl)
 {
     gameControl     = gc;
     shopControl     = gc.gameObject.GetComponent <ShopControl>();
     clickControl    = gc.gameObject.GetComponent <ClickControl>();
     gridControl     = gc.gameObject.GetComponent <GridControl>();
     shopControlGUI  = gc.gameObject.GetComponent <ShopControlGUI>();
     obstacleLibrary = gc.gameObject.GetComponent <ObstacleLibrary>();
     enemyLibrary    = gc.gameObject.GetComponent <EnemyLibrary>();
     player          = pl;
 }
Beispiel #5
0
    // JRH v0.2.0
    /// <summary>
    /// Sets the row passed in as a reference using the values contained in a Data parameter
    /// </summary>
    /// <param name="row"></param>
    /// <param name="data"></param>
    public void SetRow(ref PlatformRow row, RowData data)
    {
        // JRH v0.2.0: Set functionality to PlatformRow / gameObject
        row.gameObject.name += row.transform.GetSiblingIndex();
        // JRH v0.2.0: Add the row's in-scene position relative to the other rows to the gameObject's name

        row.SetCode(data.CodeArray);
        // JRH v0.2.0: Set the row's code to the code array held in Data

        if (GameManager.Instance.PlatformManager.LastRow != null)
        {
            row.transform.position = new Vector3(0f, 0f, GameManager.Instance.PlatformManager.LastRow.transform.position.z - GameManager.Instance.LaneDistance);
        }
        // JRH v0.2.0: Move the new Row to one laneDistance unit behind the last row

        // JRH v0.2.0: Set functionality to each Platform component
        for (int i = 0; i < 3; i++)
        {
            row.Platforms[i].SetPlatform(data.CodeArray[i]);
            // JRH v0.2.0: Set the platform's code to the corresponding code in data
            row.Platforms[i].SetCritical(data.CritArray[i]);
            // JRH v0.2.0: Set the platform's critical value to the corresponding critical value in data
            if (ObstacleLibrary.DecipherCode(row.Platforms[i].Code, PlatformType.PIT))
            {
                row.Platforms[i].SetPit();
            }
            // JRH v0.2.0: If the code returns a pit, call the SetPit method in that platform to turn it into a pit

            if (GameManager.Instance.GhostMode)
            {
                if (row.Platforms[i].IsCritical && (row.Platforms[i].Code == 'p' || row.Platforms[i].Code == 'P'))
                {
                    row.Platforms[i].transform.GetChild(0).GetComponent <Renderer>().material = ghostMaterial;
                }
            }
        }

        GenerateObstacles(row, data);

        for (int i = 0; i < 3; i++)
        {
            if (ObstacleLibrary.DecipherCode(row.Platforms[i].Code, PlatformType.REW))
            {
                row.Platforms[i].SetReward(GenerateReward(row.Platforms[i]));
            }
        }
    }
    protected override void AddRewards()
    {
        for (int i = 0; i < rowCodes.Count; i++)
        {
            int blocLength = wide ? 4 : 3;

            if ((i + blocLength) % blocLength == 2)
            {
                for (int j = 0; j < rowCodes[i].CodeArray.Length; j++)
                {
                    if (j != 1 && !ObstacleLibrary.DecipherCode(rowCodes[i].CodeArray[j]))
                    {
                        rowCodes[i].CodeArray[j] = char.ToUpper(rowCodes[i].CodeArray[j]);
                    }
                }
            }
        }
    }
    // JRH v0.2.4
    /// <summary>
    /// Compares and sets the values of this struct to the most recent piece of data in-game
    /// </summary>
    /// <returns></returns>
    public bool CritCheck(RowData?lastRow = null)
    {
        RowData    lastData;
        List <int> unresolved = new List <int>()
        {
            0, 1, 2
        };
        bool criticalResolution;
        int  critCount = 0;

        if (lastRow == null)
        {
            PlatformRow lastInstance = GameManager.Instance.PlatformManager.LastRow;
            char[]      codes        = new char[3] {
                lastInstance.Platforms[0].Code, lastInstance.Platforms[1].Code, lastInstance.Platforms[2].Code
            };
            bool[] crits = new bool[3] {
                lastInstance.Platforms[0].IsCritical, lastInstance.Platforms[1].IsCritical, lastInstance.Platforms[2].IsCritical
            };

            lastData           = new RowData(codes[0], codes[1], codes[2]);
            lastData.critArray = crits;
        }
        else
        {
            lastData = (RowData)lastRow;
        }

        for (int i = 0; i < 3; i++)
        {
            if (lastData.critArray[i])
            {
                critArray[i] = !ObstacleLibrary.DecipherCode(codeArray[i]) || !ObstacleLibrary.DecipherCode(lastData.codeArray[i]) ? true : false;
                // JRH v0.2.0: If the last platform was on the critical path and this one is not an obstacle or pit, set it on the critical path
            }
            else
            {
                critArray[i] = lastData.critArray[i];
            }
            // JRH v0.2.0: Otherwise, let it's critical path follow the platform previous to it's critical path
            //Debug.Log(i + ":" + lastCode[i] + "," + lastCrit[i] + "," + codeArray[i] + "," + critArray[i]);

            if (ObstacleLibrary.DecipherCode(lastData.codeArray[i], PlatformType.TALL))
            {
                critArray[i] = false;
            }
            // JRH v0.2.9: If the current code is tall, remove the platform from the critical path. There is no way above a tall obstacle.
        }

        for (int i = 0; i < critArray.Length; i++)
        {
            if (critArray[i])
            {
                unresolved.Remove(i);
            }
        }
        // JRH v0.2.0: If each platform is critical, whoohoo! We don't need to do anything with it in the next step


        criticalResolution = unresolved.Count < 1 ? true : false;
        // If there are any unresolved platforms, set the conditions for the next loop starting

        /* JRH v0.3.2: Due to the increase in time to switch lanes,
         * while (criticalResolution == false)
         * {
         *  // While there are platforms unresolved, run this loop
         *  criticalResolution = true;
         *  // JRH v0.2.0: Resets the critical resolution pre-emptively, to be changed again if any platforms have their critical value changed
         *  List<int> toResolve = new List<int>();
         *
         *  foreach (int i in unresolved)
         *  {
         *      bool leftCrit, rightCrit;
         *
         *      leftCrit = i > 0 && !GameManager.Instance.PlatformGenerator.DecipherCode(codeArray[i - 1]) && critArray[i - 1] ? true : false;
         *      rightCrit = i < critArray.Length - 1 && !GameManager.Instance.PlatformGenerator.DecipherCode(codeArray[i + 1]) && critArray[i + 1] ? true : false;
         *      // JRH v0.2.0: Checks the platforms to the left and right of this platform (if they exist) and returns a bool for each if they can transfer critical value
         *
         *      if ((leftCrit || rightCrit) && !GameManager.Instance.PlatformGenerator.DecipherCode(codeArray[i]))
         *      {
         *          // JRH v0.2.0: If critical value can be transfered (i.e. if the platform isn't a danger and the left or right platforms can transfer critical value
         *          critArray[i] = true;
         *          // JRH v0.2.0: Transfer the critical value
         *          criticalResolution = false;
         *          // JRH v0.2.0: Change the critical resolution so the loop repeats at least once more
         *          toResolve.Add(i);
         *          // JRH v0.2.0: Add the platform index to the list of platforms to resolve
         *      }
         *  }
         *
         *  foreach (int i in toResolve) unresolved.Remove(i);
         *  // JRH v0.2.0: Remove any platforms that have been resolved from the list of platforms needing to be resolved
         * }*/

        List <int> toResolve = new List <int>();

        foreach (int i in unresolved)
        {
            bool leftCrit, rightCrit;

            leftCrit  = i > 0 && !ObstacleLibrary.DecipherCode(codeArray[i - 1]) && critArray[i - 1] ? true : false;
            rightCrit = i < critArray.Length - 1 && !ObstacleLibrary.DecipherCode(codeArray[i + 1]) && critArray[i + 1] ? true : false;
            // JRH v0.2.0: Checks the platforms to the left and right of this platform (if they exist) and returns a bool for each if they can transfer critical value

            if ((leftCrit || rightCrit) && !ObstacleLibrary.DecipherCode(codeArray[i]))
            {
                // JRH v0.2.0: If critical value can be transfered (i.e. if the platform isn't a danger and the left or right platforms can transfer critical value
                toResolve.Add(i);
                // JRH v0.2.0: Add the platform index to the list of platforms to resolve
            }
        }
        foreach (int i in toResolve)
        {
            critArray[i] = true;
        }

        foreach (bool b in critArray)
        {
            if (b)
            {
                critCount++;
            }
        }
        // JRH v0.2.0: Count the number of platforms that have had their critical value checked and are indeed part of the critical path

        return(critCount > 0 ? true : false);
        // JRH v0.2.0: Return true as long as there is one critical path available on this row, otherwise return false
    }
Beispiel #8
0
    // JRH v0.2.9:
    /// <summary>
    /// A terribly long and convoluted method that accurately decides on which obstacles to generate given the rowdata parameter
    /// </summary>
    /// <param name="row"></param>
    /// <param name="data"></param>
    void GenerateObstacles(PlatformRow row, RowData data)
    {
        //int rowCount = 0;
        List <Obstacle> obstacles             = new List <Obstacle>();
        List <int>      obstacleLanes         = new List <int>();
        List <int>      lanesNeedingObstacles = new List <int>()
        {
            0, 1, 2
        };

        //int width, height;
        char[] codeArray = data.CodeArray;

        // JRH v0.2.9: For each lane that does require a an obstacle, remove it from the lane that requires obstacles REDUNDANCY HURR DURR
        for (int i = 0; i < data.CodeArray.Length; i++)
        {
            if (!ObstacleLibrary.DecipherCode(data.CodeArray[i], PlatformType.OBS))
            {
                lanesNeedingObstacles.Remove(i);
            }
        }

        // JRH v0.2.9: Determine which obstacles are going to be put into the row and the leftmost lane they cover, and return it to the obstacles and obsLanes lists
        while (lanesNeedingObstacles.Count > 0)
        {
            int      width         = 1;
            int      nextLaneCheck = 0;
            Obstacle nextObs;
            char     code, nextCode;

            code = codeArray[lanesNeedingObstacles[0]];
            // JRH v0.2.9: Using the next row needing an obstacle, get a code consisting of an upper and lower bool

            // JRH v0.2.9: Determine the width of the next obstacle through how many adjascent lane match codes with the current lane
            while (lanesNeedingObstacles.Count - nextLaneCheck > 1)
            {
                nextCode = codeArray[lanesNeedingObstacles[1]];
                if (code == nextCode)
                {
                    width++; nextLaneCheck++;
                }
                else
                {
                    break;
                }
            }

            //height = ObstacleLibrary.DecipherCode(code, PlatformType.TALL) ? 2 : 1;
            // Determine the height of the next obstacle based on the code

            // JRH v0.2.9: Find a random obstacle that fits into the height and width requirements
            do
            {
                Obstacle ran = GetComponent <ObstacleLibrary>().LookUpObstacle();
                nextObs = ObstacleLibrary.CompareCodes(code, ran.Code) && ran.Width <= width ? ran : null;
                //nextObs = ran.Height == height && ran.Width <= width ? ran : null;
            } while (nextObs == null);


            obstacles.Add(nextObs);
            // JRH v0.2.9: Add the current obstacle to the list of obstacles
            obstacleLanes.Add(lanesNeedingObstacles[0]);
            // JRH v0.2.9: Add the current lane to the list of lanes
            lanesNeedingObstacles.RemoveRange(0, nextObs.Width);
            // JRH v0.2.9: Remove the lanes that have just been resolved from the list of lanes that need obstacles
        }

        // JRH v0.2.9: For each obstacle rolled, instantiate it into the scene as appropriate
        for (int i = 0; i < obstacleLanes.Count; i++)
        {
            Obstacle   obs = obstacles[i];
            GameObject obj;
            float      leftPos, rightPos;
            List <int> lanesCovered;

            obj = Instantiate(obs.gameObject);
            // JRH v0.2.9: Instantiate the obstacle object in-scene
            leftPos  = obstacleLanes[i] - 1;
            rightPos = leftPos + obs.Width - 1;
            // JRH v0.2.9: Determine the leftmost and rightmost lane that the obstacle is meant to cover

            obj.transform.position = new Vector3(((leftPos + rightPos) / 2) * GameManager.Instance.LaneDistance, 0, row.transform.position.z);
            // JRH v0.2.9: Set the object's position to the midpoint of the left and right lanes covered and the row it's on's Z position

            for (int j = obstacleLanes[i]; j <= obstacleLanes[i] + obs.Width - 1; j++)
            {
                row.Platforms[j].SetObstacle(obj.GetComponent <Obstacle>());
            }
            // JRH v0.2.9: Determine which platforms the object is meant to cover and assign them said obstacle

            obj.transform.SetParent(row.transform);
            // JRH v0.2.9: Finally, set the parent transform so it treadmills along with the row
        }
    }
Beispiel #9
0
    void Start()
    {
        useGUILayout = false;
        FindAllGridUnits ();
        enemyL = gameObject.GetComponent<EnemyLibrary>();
        obstacleL = gameObject.GetComponent<ObstacleLibrary>();

        //S.GameControlInst.= GameObject.FindGameObjectWithTag ("GameController").GetComponent<GameControl> ();
    }