Beispiel #1
0
    private static int[] GenerateRowObstacles_Improved1(ObstacleBank obstacleBank, int challengeLevel, bool[] paths)
    {
        //Debug.Log("GenerateRowObstacles_Improved1 challengLevel=" + challengeLevel);
        if (challengeLevel > CHALLENGE_LEVEL_MAX)
        {
            challengeLevel = CHALLENGE_LEVEL_MAX;
        }
        bool[] guaranteedPaths = new bool[Constants.ROW_WIDTH];
        for (int i = 0; i < Constants.ROW_WIDTH; i++)
        {
            if (IsPath(paths, i))
            {
                int startI = i;
                while (IsPath(paths, i + 1))
                {
                    i++;
                }
                guaranteedPaths[Random.Range(startI, i + 1)] = true;
            }
        }

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

        for (int i = 0; i < Constants.ROW_WIDTH; i++)
        {
            if (IsPath(guaranteedPaths, i))
            {
                obstacles.Add(Constants.EMPTY_TILE_INDEX);
            }
            else
            {
                float obstacleChance = CHALLENGE_LEVEL_MULTIPLIER * challengeLevel + BASE_OBSTACLE_CHANCE;
                //Debug.Log("obstacleChance=" + obstacleChance);
                if (IsPath(paths, i))
                {
                    if (RollPercentageChance(obstacleChance))
                    {
                        obstacles.Add(Random.Range(0, obstacleBank.GetMaxObstacleId() + 1));
                    }
                    else
                    {
                        obstacles.Add(Constants.EMPTY_TILE_INDEX);
                    }
                }
                else
                {
                    if (RollPercentageChance(NO_PATH_OBSTACLE_CHANCE_MULTIPLIER * obstacleChance))
                    {
                        obstacles.Add(Random.Range(0, obstacleBank.GetMaxObstacleId() + 1));
                    }
                    else
                    {
                        obstacles.Add(Constants.EMPTY_TILE_INDEX);
                    }
                }
            }
        }
        return(obstacles.ToArray());
    }
Beispiel #2
0
 public static int[] GenerateRowObstacles_Improved1(ObstacleBank obstacleBank, int challengeLevel, int[] prevRow)
 {
     bool[] paths = new bool[Constants.ROW_WIDTH];
     for (int i = 0; i < Constants.ROW_WIDTH; i++)
     {
         if (prevRow[i] < 0)
         {
             paths[i] = true;                 // if path has no obstacle it is a path => true
         }
     }
     return(GenerateRowObstacles_Improved1(obstacleBank, challengeLevel, paths));
 }
Beispiel #3
0
    // Pure Random Obstacle Placement with a challenge level input
    public static int[] GenerateRowObstacles_RandomWithChallenge(ObstacleBank obstacleBank, int challengeLevel)
    {
        List <int> obstacles = new List <int>();

        for (int i = 0; i < Constants.ROW_WIDTH; i++)
        {
            if (RollPercentageChance(10f + challengeLevel))
            {
                obstacles.Add(Random.Range(0, obstacleBank.GetMaxObstacleId() + 1));
            }
            else
            {
                obstacles.Add(Constants.EMPTY_TILE_INDEX);
            }
        }
        return(obstacles.ToArray());
    }
Beispiel #4
0
        public WorldRow(GameObject officeSectionPrefab, ObstacleBank obstacleBank, int z, int[] obstacles, bool isDynamicObjectRow, bool isPaydayRow)
        {
            IsDynamicObjectRow   = isDynamicObjectRow;
            IsPaydayRow          = isPaydayRow;
            _obstacles           = obstacles;
            _obstacleObjects     = new GameObject[_obstacles.Length];
            _officeSectionObject = Instantiate(officeSectionPrefab, new Vector3(0, 0, z), Quaternion.identity);
            float xOffset = Constants.TILE_SIZE * 0.5f * (_obstacles.Length - 1);

            for (int i = 0; i < _obstacles.Length; i++)
            {
                if (_obstacles[i] != Constants.EMPTY_TILE_INDEX)
                {
                    _obstacleObjects[i] = Instantiate(obstacleBank.GetObstaclePrefab(_obstacles[i]), new Vector3(i - xOffset, 0, z), Quaternion.identity);
                    _obstacleObjects[i].transform.Rotate(0f, 90f * Random.Range(0, 4), 0f);
                }
            }
        }
Beispiel #5
0
    public static int[] GenerateRowObstacles_Dynamic(ObstacleBank obstacleBank)
    {
        List <int> obstacles = new List <int>();

        for (int i = 0; i < Constants.ROW_WIDTH; i++)
        {
            obstacles.Add(Constants.EMPTY_TILE_INDEX);
        }

        int numObstacles = Random.Range(1, 3);

        while (numObstacles > 0)
        {
            int obstacleIndex = Random.Range(1, obstacles.Count - 1);
            if (obstacles[obstacleIndex] == Constants.EMPTY_TILE_INDEX)
            {
                obstacles[obstacleIndex] = Random.Range(0, obstacleBank.GetMaxObstacleId());
                --numObstacles;
            }
        }

        return(obstacles.ToArray());
    }
Beispiel #6
0
    private void CreateRow(int z)
    {
        int[] rowObstacles = new int[Constants.ROW_WIDTH];

        bool startRow   = false;
        bool paydayRow  = false;
        bool dynamicRow = false;

        if (z == 0 || z == 1)
        {
            startRow = true;
        }
        else if (z == _nextPayDay)
        {
            paydayRow           = true;
            _nextPayDay        += _paydayRowInterval;
            _paydayRowInterval += Constants.PAYDAY_ROW_INTERVAL_DELTA;
        }
        else
        {
            if (!_prevRowSpecial)
            {
                dynamicRow = RandomGeneration.RollPercentageChance(20f);
            }
        }

        ObstacleBank bank = ObstacleBank;

        if (startRow || paydayRow)
        {
            rowObstacles    = RandomGeneration.GenerateRowObstacles_Empty();
            _prevRowSpecial = true;
        }
        else if (dynamicRow)
        {
            bool spawnPrinter = RandomGeneration.RollPercentageChance(30f);
            bool spawnChairs  = RandomGeneration.RollPercentageChance(30f);
            if (spawnPrinter)
            {
                int printers   = 1;
                int difficulty = _playerCurrentRow / 30;
                // max. 30%
                difficulty = Mathf.Min(difficulty, 3);
                bool painAndSuffering = RandomGeneration.RollPercentageChance(difficulty * 5.0f);;
                if (painAndSuffering)
                {
                    printers = Random.Range(4, 11);
                }

                rowObstacles = new int[Constants.ROW_WIDTH];
                for (int i = 0; i < Constants.ROW_WIDTH; ++i)
                {
                    rowObstacles[i] = -1;
                }

                for (int i = 0; i < printers; ++i)
                {
                    bool spawnFakePrinter = RandomGeneration.RollPercentageChance(50f);
                    if (spawnFakePrinter)
                    {
                        _worldRows.Add(new WorldRow(OfficePrinterSectionPrefab, bank, z, rowObstacles, dynamicRow, paydayRow));
                    }
                    else
                    {
                        _worldRows.Add(new WorldRow(OfficePrinterSectionPrefab, DynamicPrinterPrefab, Random.Range(0, 4) * 90.0f, 0, z, dynamicRow, paydayRow));
                    }
                    ++z;
                }
                _prevRowObstacles = rowObstacles;
                _prevRowSpecial   = true;
                return;
            }
            else if (spawnChairs)
            {
                rowObstacles = new int[Constants.ROW_WIDTH];
                // all tiles are fair game
                _prevRowObstacles = rowObstacles;
                int chairPos = Random.Range(1, Constants.ROW_WIDTH - 2);
                _worldRows.Add(new WorldRow(OfficeSectionPrefab, DynamicChairsPrefab, Random.Range(0, 2) * 180, chairPos, z, dynamicRow, paydayRow));
                _prevRowSpecial = true;
                return;
            }
            else
            {
                rowObstacles    = RandomGeneration.GenerateRowObstacles_Dynamic(DynamicObstacleBank);
                bank            = DynamicObstacleBank;
                _prevRowSpecial = true;
            }
        }
        else
        {
            // rowObstacles = RandomGeneration.GenerateRowObstacles_Random(ObstacleBank);
            rowObstacles    = RandomGeneration.GenerateRowObstacles_Improved1(ObstacleBank, _playerCurrentRow / 10, _prevRowObstacles);
            _prevRowSpecial = false;
        }

        _worldRows.Add(new WorldRow(paydayRow ? OfficePaydaySectionPrefab : OfficeSectionPrefab, bank, z, rowObstacles, dynamicRow, paydayRow));
        _prevRowObstacles = rowObstacles;
        Debug.Log("Created Row " + z);
    }