コード例 #1
0
ファイル: FileLoader.cs プロジェクト: nian0601/MobileGame
        //This method loads the "newest" map, that is the map the player last played on/unlocked
        //Gets called when the game boots up (in MainMenuScreen)
        public static void Initialize()
        {
            gameData = new GameData();

            string savePath = SaveFilesDirectoryPath + @"\GameData.xml";

            FileStream stream = File.Open(savePath, FileMode.Open);

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(GameData));
                gameData = (GameData)serializer.Deserialize(stream);
            }
            finally
            {
                stream.Close();
            }

            LoadLevel(gameData.CurrentMap);
        }
コード例 #2
0
ファイル: FileLoader.cs プロジェクト: nian0601/MobileGame
        public static void UpdateGameData()
        {
            //Instansiate a new GameData object that we later will serialize
            GameData GameData = new GameData();

            //If the MapListCount is greater then the current mapvalue that means have more maps to play
            if (gameData.MapList.Count > gameData.CurrentMap)
            {
                //So we set AllMapsDone to FALSE
                GameData.AllMapsDone = false;
                //And set LastMapPlayed to the next level (increment it with one)
                GameData.CurrentMap = gameData.CurrentMap + 1;
            }
            //and if it isnt then we just played the last map in the game
            else
            {
                //So we set AllMapsDone to true
                GameData.AllMapsDone = true;
                //And keep the last level as the lastMapPlayed
                GameData.CurrentMap = gameData.CurrentMap;
            }

            //Make sure that we transfer the MapList between GameData's
            GameData.MapList = gameData.MapList;

            //Make sure that the gameData variable that the game actually uses gets updated aswell!
            gameData = GameData;

            //
            //After we have set the two values we simply do the serializing process
            //

            string savePath = SaveFilesDirectoryPath + @"\GameData.xml";

            FileStream stream = File.Open(savePath, FileMode.Create);

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(GameData));
                serializer.Serialize(stream, GameData);
            }
            finally
            {
                stream.Close();
            }
        }
コード例 #3
0
ファイル: FileLoader.cs プロジェクト: nian0601/MobileGame
        public static void ResetSaveFile()
        {
            //Instansiate a new GameData object that we later will serialize
            GameData GameData = new GameData();

            GameData.AllMapsDone = false;
            GameData.CurrentMap = 1;

            //Make sure that we transfer the MapList between GameData's
            GameData.MapList = gameData.MapList;

            //Make sure that the gameData variable that the game actually uses gets updated aswell!
            gameData = GameData;

            //
            //After we have set the two values we simply do the serializing process
            //

            string savePath = SaveFilesDirectoryPath + @"\GameData.xml";

            FileStream stream = File.Open(savePath, FileMode.Create);

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(GameData));
                serializer.Serialize(stream, GameData);
            }
            finally
            {
                stream.Close();
            }

            Console.WriteLine("Reset Save File! (CurrentMap = 1, AllMapsDone = false)");
        }
コード例 #4
0
ファイル: FileLoader.cs プロジェクト: nian0601/MobileGame
        public static void SaveLevel(string LevelName)
        {
            int MapHeight = EditorMapManager.NumYTiles;
            int MapWidth = EditorMapManager.NumXTiles;

            byte[,] CollisionLayer = EditorMapManager.CollisionLayer;
            byte[,] BackgroundLayer = EditorMapManager.BackgroundLayer;
            byte[,] PlatformLayer = EditorMapManager.PlatformLayer;
            byte[,] SpecialsLayer = EditorMapManager.SpecialsLayer;

            //First we read the GameData file so that we get access to the MapList
            //We will use that to propperly name the new map
            string GameDataPath = SaveFilesDirectoryPath + @"\GameData.xml";
            GameData TempGameData;
            FileStream GameDataStream = File.Open(GameDataPath, FileMode.Open);

            try
            {
                XmlSerializer GameDataSerializer = new XmlSerializer(typeof(GameData));
                TempGameData = (GameData)GameDataSerializer.Deserialize(GameDataStream);
            }
            finally
            {
                GameDataStream.Close();
            }

            //Now we make sure that we have a Levels directory
            System.IO.Directory.CreateDirectory(LevelDirectoryPath);

            //Get all the necessary LevelData
            LevelData LevelData = new LevelData();
            LevelData.TileSize = 20;
            LevelData.MapHeight = MapHeight;
            LevelData.MapWidth = MapWidth;
            LevelData.CollisionLayer = ConvertToJaggedArray(CollisionLayer);
            LevelData.BackgroundLayer = ConvertToJaggedArray(BackgroundLayer);
            LevelData.PlatformLayer = ConvertToJaggedArray(PlatformLayer);
            LevelData.SpecialsLayer = ConvertToJaggedArray(SpecialsLayer);

            //And now its time to build the SavePath
            //The new level we want to save should get number "MapList.Count + 1"
            //So if the MapList is empty, that is we have no maps,
            //then the new map we save will get number "0 + 1 = 1"
            //If there are 8 maps in the list then the new map will get number "8 + 1 = 9"
            string savePath = LevelDirectoryPath + @"\" + LevelName + ".xml";
            FileStream stream = File.Open(savePath, FileMode.Create);

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(LevelData));
                serializer.Serialize(stream, LevelData);
            }
            finally
            {
                stream.Close();
            }

            //After we have saved the new level we need to update the GameData file (update the MapList)
            TempGameData.MapList = gameData.MapList;
            if (!TempGameData.MapList.Contains(LevelName))
                TempGameData.MapList.Add(LevelName);

            GameDataStream = File.Open(GameDataPath, FileMode.Create);

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(GameData));
                serializer.Serialize(GameDataStream, TempGameData);
            }
            finally
            {
                GameDataStream.Close();
            }

            gameData = TempGameData;
        }
コード例 #5
0
ファイル: FileLoader.cs プロジェクト: nian0601/MobileGame
        public static void SaveLevel(string LevelName, LightRenderer aLightRenderer)
        {
            int MapHeight = EditorMapManager.NumYTiles;
            int MapWidth = EditorMapManager.NumXTiles;

            byte[,] CollisionLayer = EditorMapManager.CollisionLayer;
            byte[,] BackgroundLayer = EditorMapManager.BackgroundLayer;
            byte[,] PlatformLayer = EditorMapManager.PlatformLayer;
            byte[,] SpecialsLayer = EditorMapManager.SpecialsLayer;

            float[,] PointLights = new float[aLightRenderer.pointLights.Count, 7];

            for (int y = 0; y < aLightRenderer.pointLights.Count; y++)
            {
                PointLights[y, 0] = aLightRenderer.pointLights[y].Position.X - EditorMapManager.Offset.X;
                PointLights[y, 1] = aLightRenderer.pointLights[y].Position.Y - EditorMapManager.Offset.Y;
                PointLights[y, 2] = aLightRenderer.pointLights[y].Radius;
                PointLights[y, 3] = aLightRenderer.pointLights[y].Power;
                PointLights[y, 4] = aLightRenderer.pointLights[y].Color.R;
                PointLights[y, 5] = aLightRenderer.pointLights[y].Color.G;
                PointLights[y, 6] = aLightRenderer.pointLights[y].Color.B;
            }

            //float[,] AmbientLights = new float[LightingManager.AmbientLights.Count, 8];

            //for (int y = 0; y < LightingManager.AmbientLights.Count; y++)
            //{
            //    AmbientLights[y, 0] = LightingManager.AmbientLights[y].Position.X;
            //    AmbientLights[y, 1] = LightingManager.AmbientLights[y].Position.Y;
            //    AmbientLights[y, 2] = LightingManager.AmbientLights[y].Width;
            //    AmbientLights[y, 3] = LightingManager.AmbientLights[y].Height;
            //    AmbientLights[y, 4] = LightingManager.AmbientLights[y].Color.R;
            //    AmbientLights[y, 5] = LightingManager.AmbientLights[y].Color.G;
            //    AmbientLights[y, 6] = LightingManager.AmbientLights[y].Color.B;
            //    AmbientLights[y, 7] = LightingManager.AmbientLights[y].Power;
            //}

            //First we read the GameData file so that we get access to the MapList
            //We will use that to propperly name the new map
            string GameDataPath = SaveFilesDirectoryPath + @"\GameData.xml";
            GameData TempGameData;
            FileStream GameDataStream = File.Open(GameDataPath, FileMode.Open);

            try
            {
                XmlSerializer GameDataSerializer = new XmlSerializer(typeof(GameData));
                TempGameData = (GameData)GameDataSerializer.Deserialize(GameDataStream);
            }
            finally
            {
                GameDataStream.Close();
            }

            //Now we make sure that we have a Levels directory
            System.IO.Directory.CreateDirectory(LevelDirectoryPath);

            //Get all the necessary LevelData
            LevelData LevelData = new LevelData();
            LevelData.TileSize = 20;
            LevelData.MapHeight = MapHeight;
            LevelData.MapWidth = MapWidth;
            LevelData.CollisionLayer = ConvertToJaggedArray(CollisionLayer);
            LevelData.BackgroundLayer = ConvertToJaggedArray(BackgroundLayer);
            LevelData.PlatformLayer = ConvertToJaggedArray(PlatformLayer);
            LevelData.SpecialsLayer = ConvertToJaggedArray(SpecialsLayer);
            LevelData.PointLights = ConvertToJaggedArray(PointLights);
            LevelData.NumPointLights = aLightRenderer.pointLights.Count;
            //LevelData.AmbientLights = ConvertToJaggedArray(AmbientLights);
            //LevelData.NumAmbientLights = LightingManager.AmbientLights.Count;

            //And now its time to build the SavePath
            //The new level we want to save should get number "MapList.Count + 1"
            //So if the MapList is empty, that is we have no maps,
            //then the new map we save will get number "0 + 1 = 1"
            //If there are 8 maps in the list then the new map will get number "8 + 1 = 9"
            string savePath = LevelDirectoryPath + @"\" + LevelName + ".xml";
            FileStream stream = File.Open(savePath, FileMode.Create);

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(LevelData));
                serializer.Serialize(stream, LevelData);
            }
            finally
            {
                stream.Close();
            }

            //After we have saved the new level we need to update the GameData file (update the MapList)
            TempGameData.MapList = gameData.MapList;
            if (!TempGameData.MapList.Contains(LevelName))
                TempGameData.MapList.Add(LevelName);

            GameDataStream = File.Open(GameDataPath, FileMode.Create);

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(GameData));
                serializer.Serialize(GameDataStream, TempGameData);
            }
            finally
            {
                GameDataStream.Close();
            }

            gameData = TempGameData;
        }