Example #1
0
        private static void CarvePassages(int cx, int cy, Cell[,] cells)
        {
            var directions = new List<Directions>
            {
                Directions.N,
                Directions.S,
                Directions.E,
                Directions.W,
            }
            .OrderBy(x => Guid.NewGuid());

            foreach (var direction in directions)
            {
                int nx = cx + DX[direction];
                int ny = cy + DY[direction];

                if (IsOutOfBounds(nx, ny, cells))
                    continue;

                if (cells[nx, ny].Value != 0)
                    continue;

                cells[cx, cy].Value |= (int)direction;
                cells[nx, ny].Value |= (int)OPPOSITE[direction];

                CarvePassages(nx, ny, cells);
            }
        }
Example #2
0
        public override void Update(GameTime gameTime)
        {
            if (this.MustUpdate)
            {
                for (int x = 0; x < Cells.GetLength(0); x++)
                {
                    for (int y = 0; y < Cells.GetLength(1); y++)
                    {
                        Cell newCell = new Cell(Cells[x, y].Bounds, 
                                                Cells[x, y].Type, 
                                                Cells[x, y].Fill, 
                                                Cells[x, y].Animation);

                        newCell.Borders = Cells[x, y].Borders;

                        Cells[x, y] = null;

                        Cells[x, y] = newCell;
                        Cells[x, y].Texture =
                            Utils.RuntimeTextures.BasicBordered(
                                GraphicsDevice,
                                Cells[x, y].Fill,
                                Cells[x, y].Borders);
                    }
                }

                this.MustUpdate = false;
            }

            for (int x = 0; x < Cells.GetLength(0); x++)
            {
                for (int y = 0; y < Cells.GetLength(1); y++)
                {
                    Cells[x, y].UpdateAnimation(gameTime);
                }
            }
            
            base.Update(gameTime);
        }
Example #3
0
        public void GenerateRandom()
        {
            this.Cells = new Cell[this.Size.X, this.Size.Y];

            for (int x = 0; x < this.Size.X; x++)
            {
                for (int y = 0; y < this.Size.Y; y++)
                {
                    Rectangle Bounds = new Rectangle(
                        x * CellSize.X, y * CellSize.Y,
                        CellSize.X, CellSize.Y);

                    Cell c = new Cell(Bounds);
                    c.Texture = Utils.RuntimeTextures.Basic(Parent.GraphicsDevice, Color.Transparent);
                    Cells.SetValue(c, x, y);
                }
            }

            MazeGenerator.Do(this);
            this.MustUpdate = true;
        }
Example #4
0
        private static bool IsOutOfBounds(int x, int y, Cell[,] cells)
        {
            if (x < 0 || x > cells.GetLength(0) - 1)
                return true;

            if (y < 0 || y > cells.GetLength(1) - 1)
                return true;

            return false;
        }