예제 #1
0
        public static void LoadWorld(string name)
        {
            string progfiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
            string json      = System.IO.File.ReadAllText(progfiles + @"\Sap\Worlds\" + name + @"\" + "world.json");

            // Pause game loop before messing with data
            GEngine.pause();

            // Clear all world data
            Tile.RemoveAll();
            World w = new World(name);

            SpriteHandler.sprites.Clear();
            SpriteHandler.sentiants.Clear();
            //SpriteHandler.VisableSprites.Clear();

            World.BinWorld             binw = new World.BinWorld();
            MemoryStream               ms   = new MemoryStream(Encoding.UTF8.GetBytes(json));
            DataContractJsonSerializer ser  = new DataContractJsonSerializer(binw.GetType());

            binw = ser.ReadObject(ms) as World.BinWorld;

            // Load in all saved world data
            Tile[] tiles = new Tile[binw.tiles.Length];
            List <StructureTile> struct_tiles = new List <StructureTile>();

            for (var i = 0; i < binw.tiles.Length; i++)
            {
                // if its a function tile, load it as one
                if (binw.tiles[i] is FunctionTile.BinFuncTile)
                {
                    tiles[i] = new FunctionTile(binw.tiles[i] as FunctionTile.BinFuncTile);
                }
                else if (binw.tiles[i] is StructureTile.BinStructureTile)
                {
                    tiles[i] = new StructureTile(binw.tiles[i] as StructureTile.BinStructureTile);
                    struct_tiles.Add(tiles[i] as StructureTile);
                }
                else
                {
                    tiles[i] = new Tile(binw.tiles[i]);
                }
            }

            // Populate arrays with saved data (must be up here since function tiles are appended on init)
            w.Tiles = tiles.ToList();


            w.StructureTiles = struct_tiles;


            Game.World = w;

            Game.P = new Player();

            string playerjson = System.IO.File.ReadAllText(progfiles + @"\Sap\Worlds\" + name + @"\" + "player.json");

            Player.BinPlayer           binp = new Player.BinPlayer();
            MemoryStream               msp  = new MemoryStream(Encoding.UTF8.GetBytes(playerjson));
            DataContractJsonSerializer serp = new DataContractJsonSerializer(binp.GetType());

            binp = serp.ReadObject(msp) as Player.BinPlayer;

            Game.P.LoadInventory(binp);

            Game.P.X    = binp.X;
            Game.P.Y    = binp.Y;
            Game.Camera = new Camera(Game.P);

            // Resume the game loop
            GEngine.resume();
            // Set the gamestate
            Game.GameState = GameState.GAME;
        }
예제 #2
0
 public BinFuncTile(FunctionTile t)
     : base(t)
 {
     RegenerateTimer = t.GetRegenerateTimer();
     Harvested       = t.isHarvested();
 }