コード例 #1
0
ファイル: GridManager.cs プロジェクト: OnurYIL/HexfallDemo
        /// <summary>
        /// Checks the entire grid matrix for maches.
        /// This runs after an explosion happened on the grid and new tiles are created.
        /// </summary>
        bool CheckAllTilesForMatch()
        {
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    TileMatches match = gridTiles.CheckTileForMaches(gridTiles[i, j]);
                    if (match != null && match.MatchedTiles.Count() > 2)
                    {
                        StartCoroutine(DisableMatchedTiles(match));
                        return(true);
                    }
                }
            }
            //All matchings complete, ready for input


            _gameState = GameState.idle;

            OnMatchHappened();

            if (_gameState != GameState.ending)
            {
                HideSelection(false);
                SelectTileGroup(lastTouchPosition);

                if (!gridTiles.CheckPotentialMatches())
                {
                    GameOver();
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: GridManager.cs プロジェクト: OnurYIL/HexfallDemo
        /// <summary>
        /// Here starts the disabling of the matched tiles
        /// </summary>
        IEnumerator DisableMatchedTiles(TileMatches matches)
        {
            print("Hiding the matched ones...");
            if (matches.MatchedTiles.Count() < 3)
            {
                yield break;
            }

            HideSelection(true);

            print("Stopping rotation");
            StopCoroutine(RotateCoroutine);

            _gameState = GameState.matching;

            AddScore(matches.MatchedTiles.Count());

            foreach (var t in matches.MatchedTiles)
            {
                t.SetActive(false);

                /* t.GetComponent<SpriteRenderer>().color = new Color(
                 *   t.GetComponent<SpriteRenderer>().color.r,
                 *   t.GetComponent<SpriteRenderer>().color.g,
                 *   t.GetComponent<SpriteRenderer>().color.b, 0f
                 *   );*/
            }
            yield return(new WaitForSeconds(Values.MatchDelay));

            StartCoroutine(MoveDownTiles(matches));
        }
コード例 #3
0
ファイル: GridManager.cs プロジェクト: OnurYIL/HexfallDemo
        /// <summary>
        /// Collapses the columns with empty tiles
        /// </summary>
        IEnumerator MoveDownTiles(TileMatches match)
        {
            _gameState = GameState.matching;

            foreach (var tile in match.MatchedTiles)
            {
                List <GameObject> tilesToMove = new List <GameObject>();

                for (int i = tile.GetComponent <Tile>().row; i < rows; i++)
                {
                    tilesToMove.Add(gridTiles[i, tile.GetComponent <Tile>().column]);
                }
                for (int i = 0; i < tilesToMove.Count; i++)
                {
                    if (match.MatchedTiles.Contains(tilesToMove[i]))
                    {
                        continue;
                    }

                    StartCoroutine(tile.GetComponent <Tile>().SwapDownRow(gridTiles, tilesToMove[i].GetComponent <Tile>()));

                    yield return(new WaitForSeconds(Values.TileSwapDelay));
                }

                //For each removed tile, create a new one.
                InstantiateNewTile(tile.GetComponent <Tile>().row, tile.GetComponent <Tile>().column, tile.transform.position);

                Destroy(tile);
            }

            _gameState = GameState.matchingComplete;
        }
コード例 #4
0
ファイル: TileMatrix.cs プロジェクト: OnurYIL/HexfallDemo
        /// <summary>
        /// 2 overload functions for checking a single tile
        /// and checking a selection group.
        /// </summary>
        public TileMatches CheckTileForMaches(TileGroup group)
        {
            TileMatches matches = new TileMatches();

            //_gameState = GameState.matching;
            foreach (var go in group.tiles)
            {
                matches.AddObjectRange(CheckTileForMaches(go.gameObject).MatchedTiles);
            }

            return(matches);
        }
コード例 #5
0
ファイル: GridManager.cs プロジェクト: OnurYIL/HexfallDemo
        /// <summary>
        /// Rotates a tile group
        /// </summary>
        IEnumerator RotateTileGroup(SwipeDirection _swipeDirection)
        {
            _gameState = GameState.rotating;

            SwapDirection _swapDirection = CalculateRotateDirection(_swipeDirection);

            print("Rotating...");

            //Rotating 120 degrees, 3 times if no matches found
            for (int i = 0; i < 3; i++)
            {
                tileGroup.SetParent(tileGroupCenterObj);

                float elapsedTime = 0;

                Quaternion currentRotation = tileGroupCenterObj.transform.rotation;
                Quaternion targetRotation  = currentRotation;

                //Clockwise or anti-clockwise rotation
                targetRotation *= Quaternion.Euler(Vector3.forward * 120 * (int)_swapDirection);

                //Slerp rotation to have a smooth movement effect
                while (elapsedTime < Values.GroupRotationTime)
                {
                    elapsedTime += Time.deltaTime;
                    tileGroupCenterObj.transform.rotation = Quaternion.Slerp(currentRotation, targetRotation, elapsedTime / Values.GroupRotationTime);
                    yield return(null);
                }

                tileGroupCenterObj.transform.rotation = targetRotation;

                //Actual swapping of the tiles on the grid matrix
                tileGroup.SwapTiles(gridTiles, _swapDirection);

                tileGroup.RemoveParent();


                TileMatches groupMatches = gridTiles.CheckTileForMaches(tileGroup);

                print("Checking group match...");

                StartCoroutine(DisableMatchedTiles(groupMatches));

                yield return(new WaitForSeconds(Values.RotationDelay));
            }

            _gameState = GameState.idle;
        }
コード例 #6
0
ファイル: TileMatrix.cs プロジェクト: OnurYIL/HexfallDemo
        public TileMatches CheckTileForMaches(GameObject go)
        {
            TileMatches matches = new TileMatches();

            //_gameState = GameState.matching;
            GetMatchesTest(go);

            if (totalMatches.Count > 2)
            {
                matches.AddObjectRange(totalMatches);

                Explode(Helpers.FindGroupCenter(totalMatches), totalMatches[0].GetComponent <Tile>().color);
            }

            ClearMatches();

            return(matches);
        }