Exemple #1
0
        public static PowerUpTypesEnum DetectPowerUp(int matchCount, AxisTypesEnum axis)
        {
            PowerUpTypesEnum powerUp = PowerUpTypesEnum.Vertical;

            if (matchCount == 4)
            {
                switch (axis)
                {
                case AxisTypesEnum.Vertical:
                    powerUp = PowerUpTypesEnum.Vertical;
                    break;

                case AxisTypesEnum.Horizontal:
                    powerUp = PowerUpTypesEnum.Horizontal;
                    break;
                }
            }
            else if (matchCount == 5)
            {
                powerUp = PowerUpTypesEnum.Bomb;
            }
            else
            {
                powerUp = PowerUpTypesEnum.ColorBomb;
            }

            return(powerUp);
        }
Exemple #2
0
        public IList <ICell> CheckCell(ICell cell, out AxisTypesEnum majorAxis)
        {
            IList <ICell> allCellList = new List <ICell>();

            IList <ICell> horizontalCellsList = CheckLine(AxisTypesEnum.Horizontal, cell);
            IList <ICell> verticalCellsList   = CheckLine(AxisTypesEnum.Vertical, cell);

            if (horizontalCellsList.Count > 1)
            {
                foreach (var horCell in horizontalCellsList)
                {
                    allCellList.Add(horCell);
                }
            }

            if (verticalCellsList.Count > 1)
            {
                foreach (var vertCell in verticalCellsList)
                {
                    allCellList.Add(vertCell);
                }
            }

            if (allCellList.Count > 0)
            {
                allCellList.Add(cell);
            }

            if (horizontalCellsList.Count > verticalCellsList.Count)
            {
                majorAxis = AxisTypesEnum.Horizontal;
            }
            else if (horizontalCellsList.Count < verticalCellsList.Count)
            {
                majorAxis = AxisTypesEnum.Vertical;
            }
            else
            {
                majorAxis = AxisTypesEnum.Undefined;
            }

            foreach (var oneCell in allCellList)
            {
                if (oneCell.CellStateEnum != CellStatesEnum.Lock)
                {
                    oneCell.CellStateEnum = CellStatesEnum.Check;
                }
            }

            return(allCellList);
        }
        private IEnumerator MarkAndDestroy(IDictionary <ICell, IDictionary <IList <ICell>, AxisTypesEnum> > cellsWithAxisDictionary)
        {
            foreach (var cellDictionary in cellsWithAxisDictionary)
            {
                foreach (var cellList in cellDictionary.Value)
                {
                    MarkMatchedCells(cellList.Key);
                }
            }

            yield return(new WaitForSeconds(Strings.TIME_AFTER_MARK));

            foreach (var cellDictionary in cellsWithAxisDictionary)
            {
                foreach (var cellList in cellDictionary.Value)
                {
                    if (cellDictionary.Key.CurrentGameObject != null)
                    {
                        if (cellList.Key.Count > 3 &&
                            cellDictionary.Key.CurrentGameObject.CompareTag(Strings.TAG_POWER) == false)
                        {
                            AxisTypesEnum majorAxis  = cellList.Value;
                            int           matchCount = cellList.Key.Count;

                            PowerUpTypesEnum powerUp = Helper.DetectPowerUp(matchCount, majorAxis);
                            _spawnedPowerUpDictionary.Add(
                                new Vector3(cellDictionary.Key.TargetX, cellDictionary.Key.TargetY, 0f), powerUp);
                        }
                    }

                    WorkAfterMatch(cellList.Key);
                }
            }

            _matchedCellsWithAxisDictionary.Clear();
            _matchedCellsDictionary.Clear();

            yield return(new WaitForSeconds(Strings.TIME_AFTER_DESTROY));

            OnEvent(EventTypesEnum.BOARD_EndDestroyMatchedCells, null);
        }
        private void FindMatches()
        {
            foreach (var cell in _board.Cells)
            {
                AxisTypesEnum majorAxis = AxisTypesEnum.Undefined;

                IList <ICell> matchedCellsList = new List <ICell>();

                IDictionary <IList <ICell>, AxisTypesEnum> matchedCellsDictionary =
                    new Dictionary <IList <ICell>, AxisTypesEnum>();

                if (Helper.CellIsEmpty(cell) == false)
                {
                    if (cell.CellStateEnum != CellStatesEnum.Check)
                    {
                        matchedCellsList = _checkManager.CheckCell(cell, out majorAxis);
                        matchedCellsDictionary.Add(matchedCellsList, majorAxis);
                        _matchedCellsWithAxisDictionary.Add(cell, matchedCellsDictionary);
                    }
                }
            }

            StartCoroutine(MarkAndDestroy(_matchedCellsWithAxisDictionary));
        }
Exemple #5
0
        private IList <ICell> CheckLine(AxisTypesEnum axisTypeEnum, ICell cell)
        {
            if (Helper.CellIsEmpty(cell))
            {
                return(null);
            }

            IList <ICell> sideCells = new List <ICell>();

            int x = cell.TargetX;
            int y = cell.TargetY;

            int boardLimit;
            int axis;

            ICell sideCell = null;

            if (axisTypeEnum == AxisTypesEnum.Horizontal)
            {
                boardLimit = _board.Width;
                axis       = x;
            }
            else
            {
                boardLimit = _board.Height;
                axis       = y;
            }

            if (axis > 0 && axis < boardLimit)
            {
                for (int i = axis - 1; i >= 0; i--)
                {
                    sideCell = (axisTypeEnum == AxisTypesEnum.Horizontal)
                        ? _board.Cells[i, y]
                        : _board.Cells[x, i];

                    if (Helper.CellIsEmpty(sideCell) || sideCell.CurrentGameObject.CompareTag(Strings.TAG_POWER))
                    {
                        break;
                    }
                    if (sideCell.CurrentGameObject.CompareTag(cell.CurrentGameObject.tag))
                    {
                        sideCells.Add(sideCell);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (axis >= 0 && axis < boardLimit)
            {
                for (int i = axis + 1; i < boardLimit; i++)
                {
                    sideCell = (axisTypeEnum == AxisTypesEnum.Horizontal)
                        ? _board.Cells[i, y]
                        : _board.Cells[x, i];

                    if (Helper.CellIsEmpty(sideCell) || sideCell.CurrentGameObject.CompareTag(Strings.TAG_POWER))
                    {
                        break;
                    }
                    if (sideCell.CurrentGameObject.CompareTag(cell.CurrentGameObject.tag))
                    {
                        sideCells.Add(sideCell);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(sideCells);
        }
        void AddSelectionBoxLineBillboard(bool entered, AxisTypesEnum axis, Vector4 color, float scale)
        {
            int lineLength    = 222;
            int lineThickness = (int)MathHelper.Clamp(scale / 20, 3, 20);

            // Get position to start generating from
            Vector3 startingPosition = Vector3.Zero;

            if (axis == AxisTypesEnum.X)
            {
                startingPosition = this.GetPosition() - new Vector3(-MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER, 0, 0);
            }
            else if (axis == AxisTypesEnum.Y)
            {
                startingPosition = this.GetPosition() - new Vector3(0, MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER, 0);
            }
            else if (axis == AxisTypesEnum.Z)
            {
                startingPosition = this.GetPosition() - new Vector3(0, 0, -MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER);
            }

            for (int i = 0; i < MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER * 2; i += 200)
            {
                float delta = i;
                if (i >= MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER * 2)
                {
                    break;
                }

                Matrix matrix = Matrix.Identity;

                // Choose axis in which to generate selection box lines
                Vector3 position  = startingPosition;
                Vector3 direction = Vector3.Zero;
                if (axis == AxisTypesEnum.X)
                {
                    position.X -= delta;
                    direction   = this.WorldMatrix.Left;
                }
                else if (axis == AxisTypesEnum.Y)
                {
                    position.Y += delta;
                    direction   = this.WorldMatrix.Up;
                }
                else if (axis == AxisTypesEnum.Z)
                {
                    position.Z -= delta;
                    direction   = this.WorldMatrix.Forward;
                }

                Matrix localRot = Matrix.Identity;
                matrix.Translation = Vector3.Transform(position - this.GetPosition(), this.WorldMatrix);
                if (entered)
                {
                    MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.DebrisTrailLine, color, matrix.Translation,
                                                           direction, lineLength, lineThickness * 2.5f);
                }
                else
                {
                    MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.ProjectileTrailLine, color, matrix.Translation,
                                                           direction, lineLength, lineThickness);
                }
            }
        }
        void AddSelectionBoxLineBillboard(bool entered, AxisTypesEnum axis, Vector4 color, float scale)
        {
            int lineLength = 222;
            int lineThickness = (int) MathHelper.Clamp(scale / 20, 3, 20);
            
            // Get position to start generating from
            Vector3 startingPosition = Vector3.Zero;
            if (axis == AxisTypesEnum.X)
            {
                startingPosition = this.GetPosition() - new Vector3(-MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER, 0, 0);
            }
            else if (axis == AxisTypesEnum.Y)
            {
                startingPosition = this.GetPosition() - new Vector3(0, MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER, 0);
            }
            else if (axis == AxisTypesEnum.Z)
            {
                startingPosition = this.GetPosition() - new Vector3(0, 0, -MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER);
            }

            for (int i = 0; i < MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER * 2; i += 200)
            {
                float delta = i;
                if (i >= MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER * 2)
                {
                    break;
                }

                Matrix matrix = Matrix.Identity;

                // Choose axis in which to generate selection box lines
                Vector3 position = startingPosition;
                Vector3 direction = Vector3.Zero;
                if (axis == AxisTypesEnum.X)
                {
                    position.X -= delta;
                    direction = this.WorldMatrix.Left;
                }
                else if (axis == AxisTypesEnum.Y)
                {
                    position.Y += delta;
                    direction = this.WorldMatrix.Up;
                }
                else if (axis == AxisTypesEnum.Z)
                {
                    position.Z -= delta;
                    direction = this.WorldMatrix.Forward;
                }

                Matrix localRot = Matrix.Identity;
                matrix.Translation = Vector3.Transform(position - this.GetPosition(), this.WorldMatrix);
                if(entered)
                    MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.DebrisTrailLine, color, matrix.Translation,
                        direction, lineLength, lineThickness*2.5f);
                else
                    MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.ProjectileTrailLine, color, matrix.Translation,
                        direction, lineLength, lineThickness);
            }
        }