コード例 #1
0
        public List <IndexGroup> SelectableTriangles(GridPiece tempMapPiece)
        {
            List <IndexGroup> groupHolder = new List <IndexGroup>();

            for (int i = 0; i < 6; i++)
            {
                float angle       = (45f + 60f * i);
                int   xMultiplier = ((angle / 90f > 1) && (angle / 90f < 4)) ? -1 : +1;
                int   yMultiplier = (angle / 90f > 2) ? -1 : +1;

                float xOfVector = Mathf.Sin(angle) * xMultiplier / 2f;
                float yOfVector = Mathf.Cos(angle) * yMultiplier / 2f;

                IndexGroup group = GiveClosestIndexes(tempMapPiece, tempMapPiece.transform.position + new Vector3(xOfVector, yOfVector, 0f), 2);
                if (!group.Contains(groupHolder))
                {
                    groupHolder.Add(group);
                    if (!group.Contains(EverySelectableTriangle))
                    {
                        EverySelectableTriangle.Add(group);
                    }
                }
            }
            return(groupHolder);
        }
コード例 #2
0
        private void CreateGrid()
        {
            oneSideScale = mGridYLength < mGridXLength + 2 ? GetOneSideScale(mGridXLength) : GetOneSideScale(mGridYLength);
            SetPrefabScales();

            xPlusPos = oneSideScale / 2f + oneSideScale / 4f;
            yPlusPos = 2f * oneSideScale / 4f * Mathf.Sqrt(3f);

            OffsetY = (mGridYLength * yPlusPos + (yPlusPos / 2f)) * oneSideScale / 2f;
            OffsetX = ((mGridXLength * (3f * oneSideScale / 4f) + oneSideScale / 4f) - oneSideScale) / 2f;

            Vector3 position, rotation = HexagonalPiecePrefab.transform.rotation.eulerAngles;

            GridMap = new List <GridPiece>();
            for (int i = 0; i < mGridXLength; i++)
            {
                for (int b = 0; b < mGridYLength; b++)
                {
                    position = GivePosition((mGridYLength * i) + b);
                    GridPiece gridPiece = GridPiece();
                    GridMap.Add(gridPiece);
                    gridPiece.transform.localPosition = position;
                    gridPiece.transform.rotation      = Quaternion.Euler(rotation);
                    SetColor(gridPiece, false);
                }
            }
        }
コード例 #3
0
 private static void ResetExplodedGridPieces(IndexGroup item)
 {
     for (int i = item.Indexes.Count - 1; i >= 0; i--)
     {
         GridPiece temp = mGridManager.GridMap[item.Indexes[i]];
         mGridManager.GridMap.RemoveAt(item.Indexes[i]);
         temp.Reset();
     }
 }
コード例 #4
0
 private static void InsertTopOfColumn(int count, int insertIndex, Vector2 enTepePos)
 {
     for (int i = 0; i < count; i++)
     {
         GridPiece temp = mGridManager.GridPiece();
         temp.transform.position = new Vector2(enTepePos.x, enTepePos.y + (mGridManager.yPlusPos * i) + 5f);
         mGridManager.GridMap.Insert(insertIndex + i, temp);
         mGridManager.SetColor(temp, true);
     }
 }
コード例 #5
0
 private static void VisualProcessInExplodingGroups(List <IndexGroup> explodingGroups)
 {
     for (int i = 0; i < explodingGroups.Count; i++)
     {
         for (int b = 0; b < explodingGroups[i].Indexes.Count; b++)
         {
             GridPiece tempPiece = mGridManager.GridMap[explodingGroups[i].Indexes[b]];
             mParticleManager.ShowParticle(tempPiece);
         }
         mScore.AddScode(explodingGroups[i].Indexes.Count, (Vector3)(explodingGroups[i].MiddlePoint(mGridManager)) + Vector3.back);
     }
 }
コード例 #6
0
ファイル: ParticleManager.cs プロジェクト: YasinYuce/Hexfall
        public void ShowParticle(GridPiece explodedPiece)
        {
            if (explodedPiece.GetComponent <IColored>() != null)
            {
                PieceParticle particle = mParticlePool.Allocate();
                particle.gameObject.SetActive(true);
                Action action = null;

                action            = () => { mParticlePool.Release(particle); particle.Release -= action; };
                particle.Release += action;

                particle.ShowParticle(explodedPiece.transform.position + Vector3.back, Colors[explodedPiece.GetComponent <IColored>().ColorIndex]);
            }
        }
コード例 #7
0
        public void SetColor(GridPiece gridPiece, bool random)
        {
            IColored cPiece = gridPiece.GetComponent <IColored>();

            if (cPiece == null)
            {
                return;
            }

            int columnIndex = (GridMap.Count - 1).GetColumn(mGridYLength);
            int rowIndex    = (GridMap.Count - 1).GetRow(mGridYLength);

            if (random || (columnIndex == 0) || ((columnIndex % 2 != 0) && (rowIndex == 0)))
            {
                int cI = UnityEngine.Random.Range(0, mColors.Length);
                cPiece.ChangeColor(cI, mColors[cI]);
                return;
            }

            List <IndexGroup> groupHolder = SelectableTriangles(gridPiece);
            int randomColorIndex          = UnityEngine.Random.Range(0, mColors.Length);

            cPiece.ColorIndex = randomColorIndex;
            if (groupHolder.CheckColorCount(this, 1) == true)
            {
                for (int i = 0; i < mColors.Length - 1; i++)
                {
                    randomColorIndex++;
                    if (randomColorIndex >= mColors.Length)
                    {
                        randomColorIndex -= mColors.Length;
                    }
                    cPiece.ColorIndex = randomColorIndex;
                    if (groupHolder.CheckColorCount(this, 1) == false)
                    {
                        break;
                    }
                }
            }
            cPiece.ChangeColor(randomColorIndex, mColors[randomColorIndex]);
            return;
        }
コード例 #8
0
        public IndexGroup GiveClosestIndexes(GridPiece ClickedPiece, Vector3 Pos, int countToGive)
        {
            IndexGroup selectedIndexex = new IndexGroup();

            List <GridPiece> excludedPieces = new List <GridPiece>();

            excludedPieces.Add(ClickedPiece);

            Vector2 mPoint = (new List <Vector2>(new Vector2[] { Pos, ClickedPiece.transform.position })).GiveMiddePointOfVectors();

            for (int i = 0; i < countToGive; i++)
            {
                int   closestIndex = 0;
                float closestPoint = 100f;
                for (int b = 0; b < GridMap.Count; b++)
                {
                    if (!excludedPieces.Contains(GridMap[b]))
                    {
                        if (Vector2.Distance(GridMap[b].transform.position, mPoint) < closestPoint)
                        {
                            closestIndex = b;
                            closestPoint = Vector2.Distance(GridMap[b].transform.position, mPoint);
                        }
                    }
                }
                selectedIndexex.Indexes.Add(closestIndex);
                excludedPieces.Add(GridMap[closestIndex]);

                List <Vector2> tempArray = new List <Vector2>(new Vector2[] { Pos, ClickedPiece.transform.position });
                for (int c = 0; c < excludedPieces.Count; c++)
                {
                    tempArray.Add(excludedPieces[c].transform.position);
                }
                mPoint = tempArray.GiveMiddePointOfVectors();
            }

            selectedIndexex.Indexes.Add(GridIndexOfaPiece(ClickedPiece));
            return(selectedIndexex);
        }
コード例 #9
0
ファイル: TriangleSelector.cs プロジェクト: YasinYuce/Hexfall
        public override void TurnSelectedIndexes(int angleDir)
        {
            IndexGroup tempProcessList = new IndexGroup(mSelectorManager.SelectedPieceGroup);

            tempProcessList.Indexes.Sort();
            GridPiece low  = mGridManager.GridMap[tempProcessList.Indexes[0]],
                      mid  = mGridManager.GridMap[tempProcessList.Indexes[1]],
                      high = mGridManager.GridMap[tempProcessList.Indexes[2]];

            if (angleDir == -1)
            {//clockwise
                mGridManager.GridMap[tempProcessList.Indexes[0]] = mid;
                mGridManager.GridMap[tempProcessList.Indexes[1]] = high;
                mGridManager.GridMap[tempProcessList.Indexes[2]] = low;
            }
            else
            {//counter-clockwise
                mGridManager.GridMap[tempProcessList.Indexes[0]] = high;
                mGridManager.GridMap[tempProcessList.Indexes[1]] = low;
                mGridManager.GridMap[tempProcessList.Indexes[2]] = mid;
            }
        }
コード例 #10
0
        public GridPiece GridPiece()
        {
            GridPiece piece  = null;
            Action    action = null;

            if ((CreatedBombPieceCount + 1) <= ((float)mStats.Score.CurrentScore / mBombLimit))
            {
                CreatedBombPieceCount++;
                piece  = BombPool.Allocate();
                action = () => { BombPool.Release(piece); piece.Release -= action; };
            }

            if (!piece)
            {
                piece  = HexagonPool.Allocate();
                action = () => { HexagonPool.Release(piece); piece.Release -= action; };
            }

            piece.Release += action;
            piece.Initialize(this, mSelectorManager, mStats.MoveCount);
            piece.gameObject.SetActive(true);
            return(piece);
        }
コード例 #11
0
 public int GridIndexOfaPiece(GridPiece piece)
 {
     return(GridMap.FindIndex(x => x == piece));
 }