Example #1
0
 public static void SaveMap(Map map, IEnumerable<Actor> actors, string fileName)
 {
     using (Stream stream = File.Create(fileName))
     {
         SaveMap(map, actors, stream);
     }
 }
Example #2
0
        public static void SaveMap(Map map, IEnumerable<Actor> actors, Stream stream)
        {
            XDocument document = new XDocument();

            XElement mapRoot = new XElement("map");

            mapRoot.Add(SaveMedia());
            mapRoot.Add(SaveLevelObjects(map, actors));

            document.Add(mapRoot);
            document.Save(stream);
        }
        public override bool LoadContent()
        {
            bool success = base.LoadContent();
            if (success)
            {
                ContentController.Instance.LoadContent<Texture2D>("ContentLoadError", "ContentLoadError");
                this.world = new World(new Vector2(0f, 9.81f));

                this.map = MapLoader.Initialize(this.maps[0], this);
                if (this.map == null || !MapLoader.LoadCurrentMap())
                {
                    System.Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Loading of Map: {0} has failed!", this.maps[0]));
                    success = false;
                }
            }

            return success;
        }
Example #4
0
        private static XElement SaveLevelObjects(Map map, IEnumerable<Actor> actors)
        {
            XElement levelObjects = new XElement("levelobjects");

            // Save background objects
            XElement backgrounds = new XElement("backgrounds");

            foreach (IXmlSerializable item in map.BackgroundObjects)
            {
                backgrounds.Add(item.XmlSerialize());
            }

            levelObjects.Add(backgrounds);

            // Save foreground objects
            XElement foregrounds = new XElement("foregrounds");

            foreach (IXmlSerializable mapObject in map.MapObjects)
            {
                foregrounds.Add(mapObject.XmlSerialize());
            }

            levelObjects.Add(foregrounds);

            // Save actors
            XElement actorElements = new XElement("actors");

            foreach (IXmlSerializable actor in actors)
            {
                actorElements.Add(actor.XmlSerialize());
            }

            levelObjects.Add(actorElements);

            return levelObjects;
        }
Example #5
0
        public override bool LoadContent()
        {
            bool success = base.LoadContent();
            if (success)
            {
                ContentController.Instance.LoadContent<Texture2D>("ContentLoadError", "ContentLoadError");
                this.world = new World(new Vector2(0f, 9.81f * this.gravityScalar));

                this.map = MapLoader.Initialize(this.maps[0], this);
                if (this.map == null || !MapLoader.LoadCurrentMap())
                {
                    System.Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Loading of Map: {0} has failed!", this.maps[0]));
                    success = false;
                }
                else
                {
                    this.debugView = new DebugViewXNA(this.world);
                    this.debugView.DefaultShapeColor = Color.White;
                    this.debugView.SleepingShapeColor = Color.LightGray;
                    this.debugView.LoadContent(this.GraphicsDevice, MainGame.ContentManager);
                    this.debugViewMatrix = Matrix.CreateOrthographicOffCenter(0f, ConvertUnits.ToSimUnits(this.map.Width), ConvertUnits.ToSimUnits(this.map.Height), 0f, 0f, .01f);
                }

                this.Camera.Following = this.map.Players.ElementAt(0);
            }

            return success;
        }