Exemplo n.º 1
0
        static void Initialize(Engine engine)
        {
            int startRow = 3;
            int startCol = 2;
            int endRow = WorldRows;
            int endCol = WorldCols - 2;

            for (int i = startCol; i < endCol; i++)
            {
                Block currBlock = new Block(new MatrixCoords(startRow, i));

                //if (i == startCol + 7)
                //    currBlock = new ExplodingBlock(new MatrixCoords(startRow, i));
                currBlock = new GiftBlock(new MatrixCoords(startRow, i));
                //if (i > startCol + 3 && i < endCol - 25)
                //    currBlock = new UnpassableBlock(new MatrixCoords(startRow, i));

                engine.AddObject(currBlock);
            }

            for (int i = startRow; i < endRow; i++)
            {
                IndestructibleBlock wallBlockLeft = new IndestructibleBlock(new MatrixCoords(i, startCol - 1));
                engine.AddObject(wallBlockLeft);

                IndestructibleBlock wallBlockRight = new IndestructibleBlock(new MatrixCoords(i, endCol));
                engine.AddObject(wallBlockRight);
            }

            //for (int i = 6; i < 9; i++)
            //{
            //    TrailObject trailObject = new TrailObject(new MatrixCoords(startRow + 1, i));
            //    engine.AddObject(trailObject);
            //}

            Ball theBall = new Ball(new MatrixCoords(WorldRows / 2, 0),
                new MatrixCoords(1, 1));
            engine.AddObject(theBall);

            //MeteoriteBall theMeteoriteBall = new MeteoriteBall(new MatrixCoords(WorldRows / 2, 1), new MatrixCoords(1, 1));
            //engine.AddObject(theMeteoriteBall);

            //UnstoppableBall theUnstoppableBall = new UnstoppableBall(new MatrixCoords(WorldRows / 2, 1),   new MatrixCoords(-1, 1));
            //engine.AddObject(theUnstoppableBall);

            Racket theRacket = new Racket(new MatrixCoords(WorldRows - 1, WorldCols / 2 - 3), RacketLength);

            engine.AddObject(theRacket);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize the blocks.
        /// </summary>
        /// <returns>List of block objects.</returns>
        public List <Entity> InitializeBlocks()
        {
            // Deserialize the blocks data.
            JToken[]      blocksData = JsonConvert.DeserializeObject <JToken[]>(_entityData.GetValue("blocks").ToString());
            List <Entity> blocks     = new List <Entity>();

            Texture2D texture = _game.Content.Load <Texture2D>("Images/Tile/Blocks");

            int tileSize = GetTileSize();

            int blockId;
            int positionX;
            int positionY;

            int    i;
            JToken blockData;

            // Convert the data to real objects.
            for (i = 0; i < blocksData.Length; i++)
            {
                blockData = blocksData[i];

                blockId   = (int)blockData["id"];
                positionX = (int)blockData["x"] * tileSize;
                positionY = (int)blockData["y"] * tileSize;

                Entity block = null;

                switch ((BlockType)blockId)
                {
                case BlockType.COINBLOCK:
                    block = new ValueBlock(new Vector2(positionX, positionY), 16, 16, (int)blockData["coins"], _game.Content, _level);
                    break;

                case BlockType.GIFTBLOCK:
                    PowerUp item = new Mushroom(Vector2.Zero, 16, 16, _game.Content, _level);
                    block = new GiftBlock(new Vector2(positionX, positionY), 16, 16, item, _game.Content, _level);
                    break;

                case BlockType.STONE:
                    block = new Tile(texture, new Rectangle(64, 16, 16, 16), new Vector2(positionX, positionY), 16, 16, true, _level);
                    break;

                case BlockType.CLOUD:
                    block = new Platform(texture, new Rectangle(32, 32, 16, 16), new Vector2(positionX, positionY), 16, 16, true, _level);
                    break;

                case BlockType.WOOD:
                    block = new Tile(texture, new Rectangle(64, 0, 16, 16), new Vector2(positionX, positionY), 16, 16, true, _level);
                    break;

                case BlockType.PIPE:

                    int column = 0;

                    if ((bool)blockData["top"])
                    {
                        column = 16;
                    }

                    block = new Pipe(texture, new Rectangle(column, 32, 16, 16), new Vector2(positionX, positionY), _level);

                    break;

                case BlockType.PLUNGER_PIPE:
                    block = new Pipe(texture, new Rectangle(16, 32, 16, 16), new Vector2(positionX, positionY), _level, _game.Content);
                    break;
                }

                if (block != null)
                {
                    blocks.Add(block);
                }
            }

            return(blocks);
        }