示例#1
0
    void GenerateTower(int nbBlocPerLine, int height, int nbColor)
    {
        _nbBlocPerLine = nbBlocPerLine;
        _height        = height;
        NbColorInTower = nbColor;

        foreach (var bloc in _tower)
        {
            if (bloc != null)
            {
                Destroy(bloc.gameObject);
            }
        }
        _tower.Clear();

        //Pick random colors to create variations
        _towerColors.Clear();
        List <BlocColor> availableColors = new List <BlocColor> {
            BlocColor.Blue, BlocColor.Green, BlocColor.Pink, BlocColor.Purple, BlocColor.Red, BlocColor.Yellow
        };

        for (int i = 0; i < nbColor; i++)
        {
            int colorPicked = Random.Range(0, availableColors.Count);
            _towerColors.Add(availableColors[colorPicked]);
            availableColors.RemoveAt(colorPicked);
        }


        for (int y = 0; y < _height; y++)
        {
            for (int x = 0; x < _nbBlocPerLine; x++)
            {
                float angle       = 360f / (float)nbBlocPerLine;
                float angleOffset = (y % 2 == 0) ? 0 : 360 / (nbBlocPerLine * 2);

                Vector3 position = new Vector3(RADIUS * Mathf.Sin(((angle * x) + angleOffset) * Mathf.Deg2Rad),
                                               Y_START + y * BLOC_HEIGHT,
                                               RADIUS * Mathf.Cos(((angle * x) + angleOffset) * Mathf.Deg2Rad));

                GameObject goBloc = Instantiate(GameManager.Instance.GameData.BlocPrefab, position, Quaternion.identity);

                Bloc currentBloc = goBloc.GetComponent <Bloc>();
                currentBloc.Id    = y * _nbBlocPerLine + x;
                currentBloc.Y     = y;
                currentBloc.X     = x;
                currentBloc.Color = _towerColors[Random.Range(0, _towerColors.Count)];
                currentBloc.ApplyColor();
                currentBloc.TogglePhysics(false);
                currentBloc.RegisterStartY();

                _tower.Add(currentBloc);
            }
        }

        UpdateDestructibleBlocs();
    }
示例#2
0
 public void SetLineDestructible(int y, bool destructible)
 {
     for (int x = 0; x < _nbBlocPerLine; x++)
     {
         Bloc blocToCheck = GetBloc(x, y);
         if (blocToCheck != null && !blocToCheck.Destroyed)
         {
             blocToCheck.SetDestructible(destructible);
             blocToCheck.ApplyColor(true);
         }
     }
 }