public TextureManager(Game1 gameref, ContentManager content)
 {
     this.gameref = gameref;
     this.content = content;
     foreach (String textureDirectory in gameref.getOptions().getTextureDirectories())
         addTextureDirectory(textureDirectory);
 }
 static void Main(string[] args)
 {
     using (Game1 game = new Game1())
     {
         game.Run();
     }
 }
 public Options(Game1 gameref)
 {
     this.gameref = gameref;
     try
     {
         XmlDocument xmlDoc = new XmlDocument();
         xmlDoc.Load(OPTIONS_FILE);
         foreach (XmlElement texturePathElement in xmlDoc.GetElementsByTagName("texturePath"))
             textureDirectories.Add(texturePathElement.InnerText);
     }
     catch (Exception e) { Console.WriteLine(e.StackTrace); }
 }
 public Control(Game1 gameref)
 {
     this.gameref = gameref;
     InitializeComponent();
     this.levelEditorPanel.Visible = false;
 }
        public static bool exportMap(string filename, Game1 game)
        {
            XmlTextWriter textWriter = new XmlTextWriter(filename, System.Text.Encoding.UTF8);
            textWriter.Formatting = Formatting.Indented;
            textWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            textWriter.WriteStartElement("Root");
            textWriter.WriteElementString("guid", game.guid.ToString());
            foreach (Level level in game.levels)
            {
                textWriter.WriteStartElement("level");
                textWriter.WriteAttributeString("length", level.levelLength.ToString());
                textWriter.WriteAttributeString("name", level.name);
                textWriter.WriteAttributeString("autoProgress", level.autoProgress.ToString());
                string adj = "";
                foreach (int adjint in level.adjacent)
                {
                    adj += adjint;
                    if (adjint != level.adjacent[level.adjacent.Count - 1])
                        adj += ",";
                }
                textWriter.WriteElementString("adj", adj.ToString());
                if(level.horizon != null && !level.horizon.Equals(""))
                    textWriter.WriteElementString("horizonPath", level.horizon);
                textWriter.WriteStartElement("background");
                foreach (BackgroundItemStruct str in level.backgroundItems)
                {
                    textWriter.WriteStartElement("graphic");
                    textWriter.WriteAttributeString("rotation", str.rotation.ToString());
                    textWriter.WriteAttributeString("scale", str.scale.ToString());
                    textWriter.WriteElementString("path", str.texturePath);
                    textWriter.WriteStartElement("location");
                    textWriter.WriteElementString("x", str.location.X.ToString());
                    textWriter.WriteElementString("y", str.location.Y.ToString());
                    textWriter.WriteEndElement();
                    textWriter.WriteEndElement();
                }
                textWriter.WriteEndElement();
                textWriter.WriteStartElement("items");
                foreach (GameItem item in level.items)
                {
                    textWriter.WriteStartElement("item");
                    textWriter.WriteAttributeString("rotation", item.rotation.ToString());
                    switch (item.polygonType)
                    {
                        case PhysicsPolygonType.Circle:
                            textWriter.WriteElementString("radius", item.radius.ToString());
                            break;
                        case PhysicsPolygonType.Rectangle:
                            textWriter.WriteStartElement("sideLengths");
                            textWriter.WriteElementString("x", item.sideLengths.X.ToString());
                            textWriter.WriteElementString("y", item.sideLengths.Y.ToString());
                            textWriter.WriteEndElement();
                            break;
                    }
                    textWriter.WriteElementString("immovable", item.immovable.ToString());
                    textWriter.WriteElementString("startdepth", item.startdepth.ToString());
                    textWriter.WriteElementString("width", item.width.ToString());
                    textWriter.WriteElementString("name", item.name);
                    textWriter.WriteElementString("loc", item.loc.X + "," + item.loc.Y);
                    textWriter.WriteElementString("weight", item.weight.ToString());
                    textWriter.WriteEndElement();
                }
                textWriter.WriteEndElement();

                textWriter.WriteStartElement("spawns");
                foreach (SpawnPoint spawn in level.spawns)
                {
                    textWriter.WriteStartElement("enemy");
                    textWriter.WriteElementString("count", spawn.count.ToString());
                    textWriter.WriteElementString("bosses", spawn.bosses.ToString());
                    textWriter.WriteElementString("type", spawn.type.ToString());
                    textWriter.WriteElementString("level", spawn.level.ToString());
                    textWriter.WriteElementString("loc", spawn.loc.X.ToString() + "," + spawn.loc.Y.ToString());
                    textWriter.WriteElementString("triggerLocation", spawn.triggerLocation.X.ToString() + "," + spawn.triggerLocation.Y.ToString());
                    textWriter.WriteElementString("triggerWidth", spawn.triggerWidth.ToString());
                    textWriter.WriteEndElement();
                }
                textWriter.WriteEndElement();
                textWriter.WriteElementString("location", level.loc.X + "," + level.loc.Y);
                textWriter.WriteElementString("number", level.number.ToString());

                string prereq = "";
                foreach (int prereqint in level.prereq)
                {
                    prereq += prereqint;
                    if (prereqint != level.prereq[level.prereq.Count - 1])
                        prereq += ",";
                }
                textWriter.WriteElementString("prereq", prereq.ToString());

                textWriter.WriteEndElement();
            }

            textWriter.Close();
            return false;
        }
 public static void importMap(string filename, Game1 gameref)
 {
     XmlDocument xmlDoc = new XmlDocument();
     xmlDoc.Load(filename);
     gameref.levels.Clear();
     foreach(XmlElement levelElement in xmlDoc.GetElementsByTagName("level"))
         gameref.levels.Add(Level.fromXML(levelElement, gameref, filename.Substring(0, filename.LastIndexOf(@"\"))));
     gameref.guid = Guid.Parse(xmlDoc.GetElementsByTagName("guid")[0].FirstChild.Value);
 }
 public BackgroundItemStruct? getBackgroundItemAtLocation(float x, float y, Game1 gameref)
 {
     foreach (BackgroundItemStruct str in backgroundItems)
     {
         Vector2 dimensions = getDimensions(str.texturePath, gameref);
         if (x < str.location.X + dimensions.X && x > str.location.X - dimensions.X &&
             y < str.location.Y + dimensions.Y && y > str.location.Y - dimensions.Y)
             return str;
     }
     return null;
 }
 private Vector2 getDimensions(string texName, Game1 gameref)
 {
     Texture2D tex = gameref.textureManager.getTexture(texName);
     return new Vector2(tex != null ? tex.Width : DEFAULT_DIMENSION, tex != null ? tex.Height : DEFAULT_DIMENSION);
 }
 public SpawnPoint getSpawnAtLocation(float x, float y, Game1 gameref)
 {
     foreach (SpawnPoint spawn in spawns)
     {
         Vector2 dimensions = getDimensions(spawn.type, gameref);
         if (x < spawn.loc.X + dimensions.X && x > spawn.loc.X - dimensions.X &&
             y < spawn.loc.Y + dimensions.Y && y > spawn.loc.Y - dimensions.Y)
             return spawn;
     }
     return null;
 }