Exemplo n.º 1
0
 private void SetLevel1(Vector3[,] cellData)
 {
     for (int x = 0; x < cellData.GetLength(xDimension); x++)
     {
         for (int y = 0; y < cellData.GetLength(yDimension); y++)
         {
             #region Side walls spawn
             if (x == 0 || y == 0 ||
                 x == gridSize.x || y == gridSize.y)
             {
                 gridSpawner.SpawnWall(cellData[x, y]); //side walls spawn
                 continue;
             }
             #endregion
             #region Road spawn
             gridSpawner.SpawnRoad(cellData[x, y]);
             #endregion
             #region Enemies spawn
             int enemyXPos = cellData.GetLength(xDimension) % 2 == 0 ? enemyPosIndent : enemyPosIndentEven;
             int enemyYPos = cellData.GetLength(yDimension) % 2 == 0 ? enemyPosIndent : enemyPosIndentEven;
             if (x == cellData.GetLength(xDimension) - enemyXPos && y == cellData.GetLength(yDimension) - enemyYPos)
             {
                 gridSpawner.SpawnEnemies(cellData[x, y], enemiesNumber); //enemies spawn
             }
             #endregion
             #region Coins spawn
             if (!(x == 1 && y == 1))
             {
                 gridSpawner.SpawnCoin(cellData[x, y]); //coins spawn
             }
             #endregion
             #region Player spawn
             if (x == playerSpawnPosition.x && y == playerSpawnPosition.y)
             {
                 gridSpawner.SpawnPlayer(cellData[x, y]); //player spawn
             }
             #endregion
         }
     }
 }
Exemplo n.º 2
0
    private void SetLevel()
    {
        int currentPlayer    = 0;
        var playersPositions = GetPlayersPositions();

        for (int x = 0; x < gameGrid.Nodes.GetLength(0); x++)
        {
            for (int y = 0; y < gameGrid.Nodes.GetLength(1); y++)
            {
                if (playersPositions.Contains(new Vector2Int(x, y)))
                {
                    Base newPlayer = new Base();
                    newPlayer.SetUpBase(gameGrid.Nodes[x, y], currentPlayer, playerColors[currentPlayer], gameGrid);
                    currentPlayer++;
                    continue;
                }
                if (UnityEngine.Random.value < obstacleSpawnChance)
                {
                    gridSpawner.SpawnWall(gameGrid.Nodes[x, y].transform.position);
                    gameGrid.Nodes[x, y].IsObstacle = true;
                }
            }
        }

        Vector2Int[] GetPlayersPositions()
        {
            Vector2Int[] playersPosition = new Vector2Int[totalPlayers];
            var          anglePerObject  = 360 / totalPlayers;
            Vector2Int   center          = new Vector2Int(Mathf.RoundToInt(gridSize.x * 0.5f), Mathf.RoundToInt(gridSize.y * 0.5f));

            for (int i = 0; i < totalPlayers; i++)
            {
                int        a   = i * anglePerObject;
                Vector2Int pos = RandomCircle(center, spawnCircleRadius, a);
                playersPosition[i] = pos;
            }
            return(playersPosition);
        }

        Vector2Int RandomCircle(Vector2Int center, float radius, int a)
        {
            float      ang = a;
            Vector2Int pos = Vector2Int.zero;

            pos.x = Mathf.RoundToInt(center.x + radius * Mathf.Sin(ang * Mathf.Deg2Rad)) - 1;
            pos.y = Mathf.RoundToInt(center.y + radius * Mathf.Cos(ang * Mathf.Deg2Rad)) - 1;
            return(pos);
        }
    }