Ejemplo n.º 1
0
 ///Debug info drawing
 public static void DEBUG_DrawDebugInfo(SpriteBatch batch, SpriteFont debugFont, GameObject entity, Map map)
 {
     batch.DrawString(debugFont, "Speed: " + entity.xVel, new Vector2(10, 10), Color.Purple, 0, Vector2.Zero, 0.8f, SpriteEffects.None, 0);
     batch.DrawString(debugFont, "MapTiles: \n" + map.name, new Vector2(10, 30), Color.Red, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
     batch.DrawString(debugFont, "MapWidth " + map.Width, new Vector2(10, 10), Color.Purple, 0, Vector2.Zero, 0.8f, SpriteEffects.None, 0);
     //batch.DrawString(debugFont, "Tileset: " + map.tiles[0].Index.X, new Vector2(10, 30), Color.Red, 0, Vector2.Zero, 0.8f, SpriteEffects.None, 0);
     //batch.Draw(map.sprite.Texture, new Vector2(20, 40), Color.White);
 }
Ejemplo n.º 2
0
 public static void Draw(SpriteBatch batch, Map map)
 {
     Rectangle src;
     foreach(Tile tile in map.tiles)
     {
         src = new Rectangle(tile.Index.X, tile.Index.Y, map.sprite.frameSize, map.sprite.frameSize);
         batch.Draw(map.sprite.Texture, tile.position, src, Color.White);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// This function reads level data and loads it into a map
        /// </summary>
        /// <param name="map">Map object to mbe written to</param>
        /// <param name="levelFile">Level file to be read</param>
        public static void LoadLevel(ref Map map, string levelFile)
        {
            using(XmlReader reader = XmlReader.Create(levelFile))
            {
                reader.MoveToContent();
                while(reader.Read())
                {
                    if(reader.NodeType == XmlNodeType.Element)
                    {
                        ///Read map values
                        if (reader.Name == "map")
                        {
                            //Read map height and width values
                            map.Width = Convert.ToInt32(reader.GetAttribute("width"));
                            map.Height = Convert.ToInt32(reader.GetAttribute("height"));

                            //Read tile size data (Generally 32, mayb be modified for different sizes later)
                            //Currently only reads width as it should be same as height, but modify if needed here
                            map.TileSize = Convert.ToInt32(reader.GetAttribute("tilewidth"));
                        }

                        //Read map properties
                         if (reader.Name == "property")
                         {
                             map.name = reader.GetAttribute("value");
                         }

                        //Read tileset properties
                         if (reader.Name == "tileset")
                         {
                             reader.Read();

                              if (reader.Name == "image")
                              {
                                  map.sprite.TextureFile = reader.GetAttribute("source");
                              }
                         }
                    }
                }
            }
        }