예제 #1
0
        public static List<Block>[] load(string path, string name, int tileWidth, int tileHeight, TextureManager textureManager)
        {
            path += name;
            String[] fileData = System.IO.File.ReadAllLines(path);
            String[] lineData = null;
            Vector2 position = Vector2.Zero;
            int textureNumber, rowCount = fileData.Length, colCount = 0;

            List<Block> collidables = new List<Block>();
            List<Block> nonCollidables = new List<Block>();
            List<Block> exits = new List<Block>();
            List<Block> springs = new List<Block>();
            List<Block> spikes = new List<Block>();
            List<Block> coins = new List<Block>();
            List<Block> key = new List<Block>();
            List<Block> destructables = new List<Block>();
            List<Block> solidCollidables = new List<Block>();

            for (int row = 0; row < rowCount; row++)
            {
                lineData = fileData[row].Split(dataFileSeparator);
                colCount = lineData.Length;
                for (int col = 0; col < colCount; col++)
                {
                    position = new Vector2(col * tileWidth, row * tileHeight);
                    textureNumber = Convert.ToInt32(lineData[col]);
                    if (textureNumber != 0) //not black
                    {

                        if (textureNumber == 1)
                        {
                            TextureData textureData = null;
                            textureData = textureManager.Get("grassTiles");
                            if (textureData != null)
                            {

                              SpritePositionInfo PositionInfo = new SpritePositionInfo(new Vector2(tileWidth * col, tileHeight * row), tileWidth, tileHeight);
                              solidCollidables.Add(getSprite(PositionInfo, textureData, textureNumber, tileWidth, tileHeight));
                            }
                        }
                        else if (textureNumber == 2)
                        {
                            TextureData textureData = null;
                            textureData = textureManager.Get("tileSheet");
                            if (textureData != null)
                            {

                                SpritePositionInfo PositionInfo = new SpritePositionInfo(new Vector2(tileWidth * col, tileHeight * row), tileWidth, tileHeight);
                                solidCollidables.Add(getSprite(PositionInfo, textureData, textureNumber, tileWidth, tileHeight));
                            }
                        }
                        else if (textureNumber > 2 && textureNumber <= 5)
                        {
                            TextureData textureData = null;
                            textureData = textureManager.Get("tileSheet");
                            if (textureData != null)
                            {

                                SpritePositionInfo PositionInfo = new SpritePositionInfo(new Vector2(tileWidth * col, tileHeight * row), tileWidth, tileHeight);
                                nonCollidables.Add(getSprite(PositionInfo, textureData, textureNumber, tileWidth, tileHeight));
                            }
                        }

                        else if (textureNumber > 5 && textureNumber <= 7)
                        {
                            TextureData textureData = null;
                            textureData = textureManager.Get("destructableTile");
                            if (textureData != null)
                            {

                                SpritePositionInfo PositionInfo = new SpritePositionInfo(new Vector2(tileWidth * col, tileHeight * row), tileWidth, tileHeight);
                                destructables.Add(getSprite(PositionInfo, textureData, textureNumber, tileWidth, tileHeight));
                            }

                        }
                        else if (textureNumber == 8)
                        {
                            TextureData textureData = null;
                            textureData = textureManager.Get("spikes");
                            if (textureData != null)
                            {
                                SpritePositionInfo PositionInfo = new SpritePositionInfo(new Vector2(tileWidth * col, tileHeight * row), tileWidth, tileHeight);
                                spikes.Add(getSprite(PositionInfo, textureData, textureNumber, tileWidth, tileHeight));
                            }

                        }
                        else if (textureNumber == 9)
                        {
                            TextureData textureData = null;
                            textureData = textureManager.Get("door");
                            if (textureData != null)
                            {
                                SpritePositionInfo PositionInfo = new SpritePositionInfo(new Vector2(tileWidth * col, tileHeight * row), tileWidth, tileHeight);
                                exits.Add(getSprite(PositionInfo, textureData, textureNumber, tileWidth, tileHeight));
                            }
                        }
                        else if (textureNumber == 10)
                        {
                            TextureData textureData = null;
                            textureData = textureManager.Get("key");
                            if (textureData != null)
                            {
                                SpritePositionInfo PositionInfo = new SpritePositionInfo(new Vector2(tileWidth * col, tileHeight * row), tileWidth, tileHeight);
                                key.Add(getSprite(PositionInfo, textureData, textureNumber, tileWidth, tileHeight));
                            }
                        }
                        //else if (textureNumber > 11 && textureNumber <= 22)
                        //{
                        //    AnimatedTextureData textureData = null;
                        //    textureData = (AnimatedTextureData)game.TextureManager.Get("grassTiles");
                        //    if (textureData != null)
                        //    {
                        //        Transform transform = new Transform(position, 0, textureData.OriginTopLeft, Vector2.One, textureData.Dimensions, true);
                        //        game.SpriteManager.Add(getForgroundSprite(game, transform, textureData, textureNumber));
                        //    }
                        //}
                        //else
                        //{
                        //    TextureData textureData = null;
                        //    textureData = TextureManager.Get(textureNumber);
                        //    if (textureData != null)
                        //    {
                        //        SpritePresentationInfo PresentationInfo = new SpritePresentationInfo(new Rectangle(576, 864, tileWidth, tileHeight), backDepth);
                        //        SpritePositionInfo PositionInfo = new SpritePositionInfo(new Vector2(tileWidth * col, tileHeight * row), tileWidth, tileHeight);
                        //        collidables.Add(getBackgroundSprite(PresentationInfo, PositionInfo, textureData, textureNumber));
                        //    }
                        //}
                      //  textureData = game.TextureManager.Get(textureNumber);

                    }
                }
            }

            List<Block>[] blocks = new List<Block>[9];
            blocks[0] = collidables;
            blocks[1] = nonCollidables;
            blocks[2] = exits;
            blocks[3] = springs;
            blocks[4] = spikes;
            blocks[5] = key;
            blocks[6] = coins;
            blocks[7] = destructables;
            blocks[8] = solidCollidables;

            return blocks;
        }
예제 #2
0
        public static List<Block>[] buildLevelStructure(int[,] tiles, TextureManager textureManager, int tileWidth, int tileHeight)
        {
            //really going to return a list of objects in the game, mainly stuff to be used with collision detection.
            List<Block> collidables = new List<Block>();
            List<Block> nonCollidables = new List<Block>();
            List<Block> exits = new List<Block>();
            List<Block> springs = new List<Block>();
            List<Block> spikes = new List<Block>();
            List<Block> coins = new List<Block>();
            List<Block> key = new List<Block>();

            int numRows = tiles.GetLength(0);
            int numCols = tiles.GetLength(1);

            for (int rowIndex = 0; rowIndex < numRows; rowIndex++)
            {
                for (int colIndex = 0; colIndex < numCols; colIndex++)
                {
                    if (tiles[rowIndex, colIndex] == 0)
                    {
                        //nothing
                    }
                    else if (tiles[rowIndex, colIndex] == 1)
                    {
                        //make an earth tile - Middle.
                        collidables.Add(new Block("earthmid " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(576, 864, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 2)
                    {
                        collidables.Add(new Block("grassmid " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(504, 576, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 3)
                    {
                        collidables.Add(new Block("grassleft " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(504, 648, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 4)
                    {
                        collidables.Add(new Block("grassright " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(504, 504, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 5)
                    {
                        collidables.Add(new Block("grasssingle " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(648, 0, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 6)
                    {
                        collidables.Add(new Block("bridgelogs " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(288, 720, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 7)
                    {
                        collidables.Add(new Block("watertop " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(432, 576, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 8)
                    {
                        collidables.Add(new Block("waterfull " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(504, 216, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }

                    else if (tiles[rowIndex, colIndex] == 10)
                    {
                        nonCollidables.Add(new Block("fence " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(648, 144, tileWidth, tileHeight), frontDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 11)
                    {
                        nonCollidables.Add(new Block("fencebroken " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(648, 72, tileWidth, tileHeight), frontDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 12)
                    {
                        springs.Add(new Block("spring " + rowIndex + "." + colIndex,
                                                textureManager.Get("items_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(432, 216, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 13)
                    {
                        spikes.Add(new Block("spikes " + rowIndex + "." + colIndex,
                                                textureManager.Get("items_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(347, 0, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 20)
                    {
                        nonCollidables.Add(new Block("exitsign " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(288, 360, tileWidth, tileHeight), frontDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 21)
                    {
                        nonCollidables.Add(new Block("signleft " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(288, 288, tileWidth, tileHeight), frontDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 30)
                    {
                        nonCollidables.Add(new Block("plant " + rowIndex + "." + colIndex,
                                                textureManager.Get("items_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(0, 363, tileWidth, tileHeight), frontDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 40)
                    {
                        key.Add(new Block("key " + rowIndex + "." + colIndex,
                                                textureManager.Get("items_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(72, 363, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 41)
                    {
                        coins.Add(new Block("coin " + rowIndex + "." + colIndex,
                                                textureManager.Get("items_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(288, 360, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 98)
                    {
                        exits.Add(new Block("doormid " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(648, 432, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                    else if (tiles[rowIndex, colIndex] == 99)
                    {
                        exits.Add(new Block("doortop " + rowIndex + "." + colIndex,
                                                textureManager.Get("tiles_spritesheet"),
                                        new SpritePresentationInfo(new Rectangle(648, 360, tileWidth, tileHeight), backDepth),
                                        new SpritePositionInfo(new Vector2(tileWidth * colIndex, tileHeight * rowIndex), tileWidth, tileHeight)));
                    }
                }
            }
            List<Block>[] blocks = new List<Block>[7];
            blocks[0] = collidables;
            blocks[1] = nonCollidables;
            blocks[2] = exits;
            blocks[3] = springs;
            blocks[4] = spikes;
            blocks[5] = key;
            blocks[6] = coins;

            return blocks;
        }