Пример #1
0
        public List<IEntity> Load(Brick.OnBrickDieEvent onBrickDieEvent)
        {
            int gameWidth = _game.GraphicsDeviceManager.PreferredBackBufferWidth;
            List<IEntity> res = new List<IEntity>();
            Random rand = new Random();

            //int[][] aLevel = new int[]
            //{
            //    new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
            //};

            for (int y = _game.TopMenuHeight*2; y < (_game.TopMenuHeight*2 + Brick.BRICK_HEIGHT * 10); y += (int)Brick.BRICK_HEIGHT)
            {
                for (int x = 0; x <= gameWidth - Brick.BRICK_WIDTH; x += (int)Brick.BRICK_WIDTH)
                {
                    Brick b = new Brick(_game, x, y, rand.Next(Brick.COLORS));
                    b.OnBrickDie += onBrickDieEvent;

                    res.Add(b);
                    _game.Components.Add(b);
                }
            }

            return res;
        }
Пример #2
0
        public void SetupLevel(byte[][] bricks)
        {
            int rowCount = bricks.Count();

            if (rowCount <= 0)
                throw new Exception("Invalid number of rows in level!");

            int colCount = bricks[0].Count();

            if (colCount <= 0)
                throw new Exception("Invalid number of columns in level!");

            Log.Write("Setting up level with {0} rows and {1} columns.", rowCount, colCount);

            int startX = _game.Width / 2 - (colCount * Config.Brick.Width) / 2;
            int startY = _game.TopBarHeight;
            int endX = startX + colCount * Config.Brick.Width;
            int endY = startY + rowCount * Config.Brick.Height;

            Log.Write("Level position: ({0}, {1}) - ({2}, {3})", startX, startY, endX, endY);

            if ((startX < 0) ||
                (startY < 0) ||
                (endX > _game.Width) ||
                (endY > (float)_game.Height * 0.75))
                throw new Exception("Level too big for the window size!");

            for (int y = 0; y < rowCount; y++)
            {
                for (int x = 0; x < colCount; x++)
                {
                    if (bricks[y][x] != 0)
                    {
                        Brick b = new Brick(_game, this, (byte)(bricks[y][x] - 1), startX + x * Config.Brick.Width, startY + y * Config.Brick.Height);
                        _game.Components.Add(b);
                        _bricks.Add(b);
                        b = null;
                    }
                }
            }
        }