Ejemplo n.º 1
0
 public MapLayer(int width, int height)
 {
     map = new Tile[height, width];
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             map[y, x] = new Tile(0, 0);
         }
     }
 }
Ejemplo n.º 2
0
 public void Add(Tile tile)
 {
     if (!dict.ContainsValue(tile))
     {
         dict.Add(tile.TileID, tile);
     }
     else
     {
         throw new Exception("Cannot add tile, it's already in there");
     }
 }
Ejemplo n.º 3
0
        // loads the tiles from xml-file generated by TileMapEditor TODO: Content pipeline
        public TileLoader(string filename, IEContentManager content)
        {
            this.content = content;
            list = new TileList();
            input = new TInput();
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(filename);
            //TODO:
                foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) // tilesetFile nodes
                {
                    //TODO Make tilesets
                    if (node.Name == "tiles") // if node is <tiles>
                    {
                        foreach (XmlNode imageTileNode in node.ChildNodes) // <imageTiles>
                        {

                            int id = Int32.Parse(imageTileNode.Attributes["id"].Value);
                            int width = Int32.Parse(imageTileNode.Attributes["width"].Value);
                           int height = Int32.Parse(imageTileNode.Attributes["height"].Value);

                            foreach (XmlNode imageTileNodes in imageTileNode.ChildNodes)
                            {
                                if (imageTileNodes.Name == "image")
                                {
                                    string file = imageTileNodes.Attributes["file"].Value;
                                    string[] contentName =  file.Split('.');

                                    try
                                    {
                                        file = contentName[0];
                                    }
                                    catch
                                    {
                                        throw new Exception("Invalid picture name at " + file);
                                    }
                                    texture = content.Load<Texture2D>("Content/images/" + contentName[0]);

                                    tile = new Tile(texture,id);
                                    list.Add(tile);
                                }

                                //TODO Optimize tilesets
                                if (imageTileNodes.Name == "tilesetImage")
                                {
                                    string file = imageTileNodes.Attributes["file"].Value;
                                    string[] contentName = file.Split('.');

                                    try
                                    {
                                        file = contentName[0];
                                    }
                                    catch
                                    {
                                        throw new Exception("Invalid picture name at " + file);
                                    }

                                    //Loads the whole texture. for optimizing just load the tileset
                                    //Once then use the same texture in all tiles
                                    texture = content.Load<Texture2D>("Content/images/" + contentName[0]);
                                    int x = Int32.Parse(imageTileNodes.Attributes["posX"].Value);
                                    int y = Int32.Parse(imageTileNodes.Attributes["posY"].Value);

                                    Rectangle tilesetPart = new Rectangle(x, y, width, height);
                                    tile = new Tile(texture, id, tilesetPart);
                                    tile.IsPartOfTileset = true;
                                    list.Add(tile);
                                }
                            }

                            //TODO: Check for bugs
                            //Load nulltiles with collision
                            if (imageTileNode.Name == "nullTile")
                            {
                                foreach (XmlNode imageTileNodes in imageTileNode.ChildNodes)
                                {
                                    if (imageTileNodes.Name == "collision")
                                    {
                                        string collision = imageTileNodes.Attributes["area"].Value;
                                        if (collision != "none")
                                        {
                                            tile = new Tile(CollisionType.Unpassable);
                                        }
                                        else
                                        {
                                            tile = new Tile(CollisionType.Passable);
                                        }
                                        tile.TileID = id;
                                        list.Add(tile);
                                    }
                                }

                            }
                        }
                    }
                }
        }
Ejemplo n.º 4
0
 public void SetTile(int x, int y, int tileIndex, int tileset)
 {
     map[y, x] = new Tile(tileIndex, tileset);
 }
Ejemplo n.º 5
0
 public void SetTile(int x, int y, Tile tile)
 {
     map[y, x] = tile;
 }
Ejemplo n.º 6
0
 public MapLayer(Tile[,] map)
 {
     this.map = (Tile[,])map.Clone();
 }