public void FindUpdatedPath(float currentX, float currentY)
        {
            if (_matrixMap.MatrixMapCells == null)
            {
                Debug.LogError("_matrixMap.MatrixMapCells == null");
                return;
            }

            var aStar = new MySolver <MatrixMapCell, object>(_matrixMap.MatrixMapCells);
            var path  = aStar.Search(new Vector2(currentX, currentY), new Vector2(_endGridPosition.X, _endGridPosition.Y), null, _formula, _enemy.Flying);

            var x = 0;

            if (path != null)
            {
                foreach (var node in path)
                {
                    if (x == 1)
                    {
                        _nextNode = node;
                        break;
                    }

                    x++;
                }
            }
            else
            {
                Debug.LogError("I'm stuck!");

                _matrixMap.RemoveLastTower();
            }
        }
Example #2
0
        private void Copy(int x1, int y1, int x2, int y2)
        {
            int startX  = x1 < x2 ? x1 : x2;
            int startY  = y1 < y2 ? y1 : y2;
            int columns = Math.Abs(x1 - x2) + 1;
            int rows    = Math.Abs(y1 - y2) + 1;

            this.mmcCopyCells = new MatrixMapCell(columns, rows);

            columns += startX;
            rows    += startY;

            int nx = 0;

            for (int x = startX; x < columns; x++)
            {
                int ny = 0;
                for (int y = startY; y < rows; y++)
                {
                    MapCell cell = this.Map.Cells[x, y];
                    if (cell != null)
                    {
                        this.mmcCopyCells[nx, ny] = new MapCell(cell.Brick);
                    }
                    ny++;
                }
                nx++;
            }
        }
Example #3
0
        private MatrixMapCell ResizeMatrix(MatrixMapCell pmtx_CellsToResize, int pint_QtdColumns, int pint_QtdRows)
        {
            MatrixMapCell oldMatrix = pmtx_CellsToResize;

            pmtx_CellsToResize = new MatrixMapCell(pint_QtdColumns, pint_QtdRows);
            if (oldMatrix != null)
            {
                oldMatrix.CopyTo(pmtx_CellsToResize);
            }
            return(pmtx_CellsToResize);
        }
Example #4
0
        private void DrawMatrix(MatrixMapCell pmtx_MatrixCell, Graphics gr)
        {
            if (pmtx_MatrixCell != null)
            {
                int plotX = 0;
                for (int x = 0; x < pmtx_MatrixCell.Columns; x++)
                {
                    int plotY = 0;
                    for (int y = 0; y < pmtx_MatrixCell.Rows; y++)
                    {
                        MapCell cell = pmtx_MatrixCell[x, y];
                        if (cell != null)
                        {
                            gr.DrawImage(cell.Brick.Image, plotX, plotY);
                        }

                        plotY += this.fint_TileHeigth;
                    }
                    plotX += this.fint_TileWidth;
                }
            }
        }
Example #5
0
        private void Paste(int x1, int y1)
        {
            int startX = x1;
            int startY = y1;

            int maxColumn = startX + this.mmcCopyCells.Columns;
            int maxRow    = startY + this.mmcCopyCells.Rows;

            MatrixMapCell mmc = this.Map.Cells;

            if (mmc.Columns < maxColumn)
            {
                maxColumn = mmc.Columns;
            }
            if (mmc.Rows < maxRow)
            {
                maxRow = mmc.Rows;
            }

            int nx = 0;

            for (int x = startX; x < maxColumn; x++)
            {
                int ny = 0;
                for (int y = startY; y < maxRow; y++)
                {
                    MapCell cell = this.mmcCopyCells[nx, ny];
                    if (cell != null)
                    {
                        mmc[x, y] = cell;
                    }
                    ny++;
                }
                nx++;
            }
        }
Example #6
0
        private void Create(int x1, int y1, int x2, int y2)
        {
            if (copy)
            {
                int startX = x2;
                int startY = y2;

                int maxColumn = startX + this.mmcCopyCells.Columns;
                int maxRow    = startY + this.mmcCopyCells.Rows;

                MatrixMapCell mmc = this.Map.SubCells[subMatrixIndex];
                if (mmc.Columns < maxColumn)
                {
                    maxColumn = mmc.Columns;
                }
                if (mmc.Rows < maxRow)
                {
                    maxRow = mmc.Rows;
                }

                mmc.Clear();
                int nx = 0;
                for (int x = startX; x < maxColumn; x++)
                {
                    int ny = 0;
                    for (int y = startY; y < maxRow; y++)
                    {
                        mmc[x, y] = this.mmcCopyCells[nx, ny];
                        ny++;
                    }
                    nx++;
                }
            }
            else
            {
                int startX  = x1 < x2 ? x1 : x2;
                int startY  = y1 < y2 ? y1 : y2;
                int columns = Math.Abs(x1 - x2) + startX;
                int rows    = Math.Abs(y1 - y2) + startY;


                MatrixMapCell mmc = this.Map.SubCells[subMatrixIndex];
                if (mmc.Columns < columns)
                {
                    columns = mmc.Columns;
                }
                if (mmc.Rows < rows)
                {
                    rows = mmc.Rows;
                }

                mmc.Clear();
                for (int x = startX; x <= columns; x++)
                {
                    for (int y = startY; y <= rows; y++)
                    {
                        mmc[x, y] = new MapCell(this.brk);
                    }
                }
            }
        }